Sign inSign up

wozijisun/slim-python

By wozijisun

•Updated almost 9 years ago

Base on slim-python 3.4 .

Image
1

121

wozijisun/slim-python repository overview

⁠Already add some third tools

RUN pip --default-timeout=10000 install --upgrade pip			&& \
        pip --default-timeout=10000 install APScheduler==3.2.0		 && \
        pip --default-timeout=10000 install coverage==4.2		 && \
        pip --default-timeout=10000 install nose==1.3.7			 && \
        pip --default-timeout=10000 install NoseXML==0.19		 && \
        pip --default-timeout=10000 install pytz==2016.6.1		 && \
        pip --default-timeout=10000 install requests			 && \
        pip --default-timeout=10000 install selenium			 && \
        pip --default-timeout=10000 install setuptools==20.10.1		 && \
        pip --default-timeout=10000 install six==1.10.0			 && \
        pip --default-timeout=10000 install tzlocal==1.2.2		 && \
        pip --default-timeout=10000 install update			 && \
        pip --default-timeout=10000 install urllib3==1.16		 && \
        pip --default-timeout=10000 install wheel==0.29.0

⁠This can run some selenium testcase such as:

ui # ls

1.0.0 config.ini

ui # cat config.ini

[config]
ip=172.xx.xx.xx
hub_port=4444
tomcat_port=18080

ui # cd 1.0.0/ 1.0.0# ls Common KENO 1.0.0# cd Common/ Common# ls Common.py init.py LoginPage.py PageInfo.py

Common# cat Common.py 
	# coding:utf-8
	import configparser


	class NewConfigParser(configparser.ConfigParser):
		def optionxform(self, optionstr):
			return optionstr


	class Common(object):
		def __init__(self):
			pass

		@staticmethod
		def get_config_value(opt='', config_file=r'/home/app/ui/config.ini'):
			config = NewConfigParser()
			try:
				config.read(config_file, encoding='utf-8')
				if not config.has_section("config"):
					print("There is no section config, Please check this config." + config_file)
					raise "PARSER CONFIG SECTION ERROR."
				if not config.has_option("config", opt):
					print("There is no option, " + opt + "Please check this config." + config_file)
					raise "PARSER CONFIG OPTION ERROR."
				else:
					value = config.get("config", opt)

			except configparser.DuplicateOptionError as doe:
				print("{} 有问题,需要查看 {}".format(doe, config_file))
				pass

			return value
Common# cat LoginPage.py 
	# coding:utf-8
	import time

	from selenium.common.exceptions import UnexpectedAlertPresentException, NoAlertPresentException

	from PageInfo import PageInfo


	class LoginPage(object):
		def __init__(self, webdriver, url):
			self.driver = webdriver
			self.url = url
			self.driver.get(self.url)
			self.pi = PageInfo()
			self.driver.implicitly_wait(30)
			self.driver.maximize_window()

		def get_title(self):
			return self.driver.title

		def login(self, username, password):
			self.driver.find_element_by_xpath(self.pi.USERNAME_XPATH).send_keys(username)
			self.driver.find_element_by_xpath(self.pi.PASSWORD_XPATH).send_keys(password)
			self.driver.find_element_by_xpath(self.pi.LOGIN_BUTTON_XPATH).click()

			time.sleep(3)
			try:
				alert = self.driver.switch_to.alert
				alert.accept()
			except UnexpectedAlertPresentException:
				pass
			except NoAlertPresentException:
				pass
			return True

		def _login(self):
			self.driver.find_element_by_xpath(self.pi.USERNAME_XPATH).send_keys(self.pi.USER_NAME)
			self.driver.find_element_by_xpath(self.pi.PASSWORD_XPATH).send_keys(self.pi.PASSWORD)
			page = self.driver.find_element_by_xpath(self.pi.LOGIN_BUTTON_XPATH).click()

			try:
				login_fail = self.driver.find_element_by_xpath(self.pi.FAILED_XPATH).text
				if login_fail == self.pi.FAILED_INFO:
					print('此用户:{} 存在一些问题 {}, 请详细检查。'.format(self.pi.USER_NAME, login_fail))
					exit(1)
			except:
				pass

			return page
Common# cat PageInfo.py 
	# coding:utf-8
	from Common import Common


	class PageInfo(object):
		def __init__(self):
			pass

		IP = Common().get_config_value(opt='ip')
		HUB_PORT = Common().get_config_value(opt='hub_port')
		TOMCAT_PORT = Common().get_config_value(opt='tomcat_port')
		
		LOGIN_mtsms_URL = r'http://'+IP+':'+TOMCAT_PORT+'/nn/'
		LOGIN_ms_URL = r'http://'+IP+':'+TOMCAT_PORT+'/mm/'
		LOGIN_mtsvm_URL = r'http://'+IP+':'+TOMCAT_PORT+'/kk/'
		USER_NAME = 'admin'
		PASSWORD = 'admin'

		LOGIN_TITLE = "xxxxxxxx"
		LOGOUT_TEXT = "logout"
		SELECT_BUTTON = r'//*[@id="IdentifyType"]'
		USERNAME_XPATH = r'//*[@id="Identify"]'
		PASSWORD_XPATH = r'//*[@id="Password"]'
		LOGIN_BUTTON_XPATH = r'/html/body/div/div/div/div/div/div[3]/div/div/div/form/fieldset/div[2]/button'
KENO# cat TestLogin.py 
	# coding:utf-8
	import unittest
	import sys
	from selenium import webdriver
	from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

	sys.path.append(r'../Common')
	from PageInfo import PageInfo
	from LoginPage import LoginPage


	class TestLogin(unittest.TestCase):
		def setUp(self):
			# self.driver = webdriver.Firefox(firefox_binary=r'D:\SystemTool\Firefox\firefox.exe')
			# binary = FirefoxBinary(r'D:\SystemTool\Firefox\firefox.exe')
			self.pi = PageInfo()
			firefox_capabilities = {"browserName": "firefox",
									"version": "56.0.2",
									"platform": "ANY",
									"javascriptEnabled": True,
									"marionette": True,
					"seleniumProtocol": "Selenium"
									}
			hub_ip = self.pi.IP
			hub_port = self.pi.HUB_PORT
			browser = webdriver.Remote(command_executor="http://"+hub_ip+":"+hub_port+"/wd/hub", desired_capabilities=firefox_capabilities)
			# self.driver = webdriver.Firefox(firefox_binary=binary, executable_path=r'D:\SystemTool\Python34\geckodriver.exe')
			self.driver = browser

		def tearDown(self):
			self.driver.close()

		def test_login01(self):
			self.page = LoginPage(self.driver, self.pi.LOGIN_ms_URL)
			result = self.page.login("admin", "admin")
			self.assertEqual(True, result)

		def test_login02(self):
			self.page = LoginPage(self.driver, self.pi.LOGIN_ms_URL)
			result = self.page.login("admin", "admin111")
			self.assertEqual(True, result)

	if __name__ == '__main__':
		unittest.main()
testcase# cat exe.sh 
	#!/bin/bash

	#######################################################
	# Author: wozijisun
	# Copyright: all rights reserved 
	#
	# Desc: this script for execute testcase for interface.
	#######################################################

	GAME_NAMES='KENO'

	version=""     		        #Version number like:1.0.0
	workspace_path=""               #Build path
	all_game="all"			#Execute all game
	exe_type="interface"		#Default type interface
	E_ARG=1
	E_NODIR=2

	while getopts ":w:v:t:a:" arg
	do
		case $arg in
			t)
				exe_type=$OPTARG
			;;
			w)
				workspace_path=$OPTARG
				echo "The WORKSPACE path is : ${workspace_path}"
			;;
			a)
				all_game=$OPTARG
				flag=0
				for game in ${GAME_NAMES}
				do
					if [ "${game}x" = "${all_game}x" ];then
						flag=1
						all_game=${game}
						break
					fi
				done
				if [ flag == 1 ];then
					echo "The game name is : ${all_game}"
				else
					echo "Give a wrong game name : ${all_game}"
					echo "It's just like : ${GAME_NAMES}"
					echo "Please check -a."
					exit $E_ARG
				fi
			;;
			v)
				version=$OPTARG
				v=`echo ${version} | awk '{print match($0,/[1-9]+(.)[0-9]+(.)[0-9]+/)?"1":"0";}'`
				if [ ${v} = 0 ];then
					echo "Give a wrong version number : ${version}"
					echo "The version number like : 1.0.0  .Please check -n ."
					exit $E_ARG
				fi
				echo "The software version number is : ${version}"
			;;
			?)
				echo "ERROR:"
				echo "Unkown options!."
				echo "Need -w for workspace path."
				echo "-v for soft version like:1.0.0 ."
				echo "-t for which kind test to run.default value is interface."
				echo "-a for all games. Or give a game name."
				exit $E_ARG
			;;
		esac
	done

	if [ ! -d ${workspace_path} ]; then
		echo "Directory ${workspace_path} not exist!"
		exit $E_NODIR
	elif [ "${workspace_path}x" = "x" ];then
		echo "Please give workspace path. check -w."
		exit $E_ARG
	fi

	if [ "${all_game}x" = "allx" ];then
		all_game=${GAME_NAMES}
	fi

	if [ "${version}x" = "x"  ];then
		echo "Version is null , Please check -v !"
		exit $E_ARG
	fi

	EXECUTE_PATH="${workspace_path}/ExecuteTestCase"

	if [ ! -d ${EXECUTE_PATH} ]; then
		echo "Directory ${EXECUTE_PATH} not exist!"
		mkdir -p ${EXECUTE_PATH}
	fi

	GAMENAME_PATH="${workspace_path}/${exe_type}/${version}"

	if [ ! -d ${GAMENAME_PATH} ]; then
		echo "Directory ${GAMENAME_PATH} not exist!"
		exit $E_NODIR
	fi

	if [ `alias | grep cp | wc -l` != 0 ];then
		unalias cp
	fi

	cp -rf "${GAMENAME_PATH}/Common" "${workspace_path}/"
	flag=0


	if [ "${exe_type}x" = "uix" ];then
		for game in ${all_game}
		do
		if [ ! -d ${GAMENAME_PATH}/${game} ];then
					continue
			else
			for file_name in `ls ${GAMENAME_PATH}/${game}/*.py`
					do
							fn=`echo "${file_name}" | awk -F "${game}"'/' '{print $2}'`
							echo "${fn}"
							if [ ${fn} = '__init__.py' ];then
									continue
							else
									cp -rf ${file_name} ${EXECUTE_PATH}/${game}_${fn}
									flag=1
							fi
					done
		fi
		done
	elif [ "${exe_type}x" = "interfacex" ];then
		for game in ${all_game}
		do
		if [ ! -d ${GAMENAME_PATH}/${game} ];then
			continue
		else
			for file_name in `ls ${GAMENAME_PATH}/${game}/*.py`
			do
				fn=`echo "${file_name}" | awk -F "${game}"'/' '{print $2}'`
				echo "${fn}"
				if [ ${fn} = '__init__.py' ];then
					continue
				else
					cp -rf ${file_name} ${EXECUTE_PATH}/${game}_${fn}
					flag=1
				fi
			done
		fi
		done
	fi

	if [ ${flag} = 1 ];then
		cd ${EXECUTE_PATH}
		#dos2unix ./*
		rm -rf d2utmp*
		nosetests --with-xunit --cover-package=${EXECUTE_PATH} --all-modules --with-coverage  --traverse-namespace --cover-inclusive -s
		if [ "${exe_type}x" = "interfacex" ];then
			rm -rf /home/app/interface_*.xml
			mv ./nosetests.xml /home/app/interface_`date +%F_%H%M%S`.xml
		elif [ "${exe_type}x" = "uix" ];then
			rm -rf /home/app/ui_*.xml
					mv ./nosetests.xml /home/app/ui_`date +%F_%H%M%S`.xml
		else
			echo "No arg to recognize. type = ${exe_type}."
		fi
	else
		echo "There is no testcase to execute! Please check!"
	fi

	rm -rf ${workspace_path}/Common
	rm -rf ${EXECUTE_PATH}/*

Tag summary

Content type

Image

Digest

Size

59.9 MB

Last updated

almost 9 years ago

docker pull wozijisun/slim-python:3.4