├── __init__.py ├── config ├── __init__.py ├── config.ini ├── __pycache__ │ ├── __init__.cpython-35.pyc │ ├── __init__.cpython-36.pyc │ ├── globalparam.cpython-35.pyc │ └── globalparam.cpython-36.pyc └── globalparam.py ├── data ├── __init__.py ├── testdata │ ├── __init__.py │ ├── datas.xlsx │ ├── __pycache__ │ │ ├── __init__.cpython-35.pyc │ │ ├── __init__.cpython-36.pyc │ │ ├── data_read.cpython-35.pyc │ │ └── data_read.cpython-36.pyc │ └── data_read.py ├── pictures │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ └── 5.jpg └── __pycache__ │ ├── __init__.cpython-35.pyc │ └── __init__.cpython-36.pyc ├── public ├── __init__.py ├── __pycache__ │ ├── log.cpython-35.pyc │ ├── log.cpython-36.pyc │ ├── base.cpython-35.pyc │ ├── base.cpython-36.pyc │ ├── __init__.cpython-35.pyc │ ├── __init__.cpython-36.pyc │ ├── browser.cpython-35.pyc │ ├── browser.cpython-36.pyc │ ├── datainfo.cpython-35.pyc │ ├── datainfo.cpython-36.pyc │ ├── function.cpython-35.pyc │ ├── function.cpython-36.pyc │ ├── myunit.cpython-35.pyc │ ├── myunit.cpython-36.pyc │ ├── readconfig.cpython-35.pyc │ ├── readconfig.cpython-36.pyc │ ├── exceptionscr.cpython-35.pyc │ └── exceptionscr.cpython-36.pyc ├── function.py ├── exceptionscr.py ├── myunit.py ├── readconfig.py ├── datainfo.py ├── browser.py ├── log.py ├── sendmail.py └── base.py ├── report ├── __init__.py ├── log │ ├── __init__.py │ └── 2017-08-24.log ├── image │ ├── __init__.py │ ├── a1_1.jpg │ ├── a1_2.jpg │ └── a1_3.jpg ├── exception_img │ ├── __init__.py │ ├── 2017_09_17_09_35_49.jpg │ ├── 2017_09_17_09_39_50.jpg │ ├── 2017_09_17_09_41_59.jpg │ ├── assert(2017_09_17_09_35_50).jpg │ ├── assert(2017_09_17_09_39_50).jpg │ └── assert(2017_09_17_09_41_59).jpg └── test_report │ ├── __init__.py │ └── 2017-08-24 10-52-39result.html ├── test_case ├── __init__.py ├── page_obj │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-35.pyc │ │ ├── __init__.cpython-36.pyc │ │ ├── a1_loginPage.cpython-35.pyc │ │ ├── a1_loginPage.cpython-36.pyc │ │ ├── a2_forget_password.cpython-35.pyc │ │ └── a2_forget_password.cpython-36.pyc │ ├── login_enter.py │ ├── a1_loginPage.py │ └── a2_forget_password.py ├── __pycache__ │ ├── __init__.cpython-35.pyc │ ├── __init__.cpython-36.pyc │ ├── a1_login_sta.cpython-35.pyc │ ├── a1_login_sta.cpython-36.pyc │ ├── a2_forget_pwd_sta.cpython-35.pyc │ └── a2_forget_pwd_sta.cpython-36.pyc ├── a1_login_sta.py └── a2_forget_pwd_sta.py ├── up_files ├── __init__.py ├── autoit_pic │ ├── __init__.py │ ├── head_sculpture.exe │ └── upload_credentials.exe └── 1.au3 ├── readme ├── 日志.jpg ├── 框架目录.jpg ├── 流程图.xmind └── 测试报告.jpg ├── run_ai_test.py └── README.md /__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /report/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /report/log/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test_case/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /up_files/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/testdata/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /report/image/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /report/exception_img/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /report/test_report/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test_case/page_obj/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /up_files/autoit_pic/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config/config.ini: -------------------------------------------------------------------------------- 1 | [projectConfig] 2 | project_path = /home/selenium_python 3 | -------------------------------------------------------------------------------- /readme/日志.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/readme/日志.jpg -------------------------------------------------------------------------------- /up_files/1.au3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/up_files/1.au3 -------------------------------------------------------------------------------- /readme/框架目录.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/readme/框架目录.jpg -------------------------------------------------------------------------------- /readme/流程图.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/readme/流程图.xmind -------------------------------------------------------------------------------- /readme/测试报告.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/readme/测试报告.jpg -------------------------------------------------------------------------------- /data/pictures/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/data/pictures/1.jpg -------------------------------------------------------------------------------- /data/pictures/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/data/pictures/2.jpg -------------------------------------------------------------------------------- /data/pictures/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/data/pictures/3.jpg -------------------------------------------------------------------------------- /data/pictures/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/data/pictures/4.jpg -------------------------------------------------------------------------------- /data/pictures/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/data/pictures/5.jpg -------------------------------------------------------------------------------- /report/image/a1_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/report/image/a1_1.jpg -------------------------------------------------------------------------------- /report/image/a1_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/report/image/a1_2.jpg -------------------------------------------------------------------------------- /report/image/a1_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/report/image/a1_3.jpg -------------------------------------------------------------------------------- /data/testdata/datas.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/data/testdata/datas.xlsx -------------------------------------------------------------------------------- /public/__pycache__/log.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/log.cpython-35.pyc -------------------------------------------------------------------------------- /public/__pycache__/log.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/log.cpython-36.pyc -------------------------------------------------------------------------------- /public/__pycache__/base.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/base.cpython-35.pyc -------------------------------------------------------------------------------- /public/__pycache__/base.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/base.cpython-36.pyc -------------------------------------------------------------------------------- /up_files/autoit_pic/head_sculpture.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/up_files/autoit_pic/head_sculpture.exe -------------------------------------------------------------------------------- /config/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/config/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /config/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/config/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /data/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/data/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /data/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/data/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /public/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /public/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /public/__pycache__/browser.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/browser.cpython-35.pyc -------------------------------------------------------------------------------- /public/__pycache__/browser.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/browser.cpython-36.pyc -------------------------------------------------------------------------------- /public/__pycache__/datainfo.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/datainfo.cpython-35.pyc -------------------------------------------------------------------------------- /public/__pycache__/datainfo.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/datainfo.cpython-36.pyc -------------------------------------------------------------------------------- /public/__pycache__/function.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/function.cpython-35.pyc -------------------------------------------------------------------------------- /public/__pycache__/function.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/function.cpython-36.pyc -------------------------------------------------------------------------------- /public/__pycache__/myunit.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/myunit.cpython-35.pyc -------------------------------------------------------------------------------- /public/__pycache__/myunit.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/myunit.cpython-36.pyc -------------------------------------------------------------------------------- /up_files/autoit_pic/upload_credentials.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/up_files/autoit_pic/upload_credentials.exe -------------------------------------------------------------------------------- /public/__pycache__/readconfig.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/readconfig.cpython-35.pyc -------------------------------------------------------------------------------- /public/__pycache__/readconfig.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/readconfig.cpython-36.pyc -------------------------------------------------------------------------------- /report/exception_img/2017_09_17_09_35_49.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/report/exception_img/2017_09_17_09_35_49.jpg -------------------------------------------------------------------------------- /report/exception_img/2017_09_17_09_39_50.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/report/exception_img/2017_09_17_09_39_50.jpg -------------------------------------------------------------------------------- /report/exception_img/2017_09_17_09_41_59.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/report/exception_img/2017_09_17_09_41_59.jpg -------------------------------------------------------------------------------- /config/__pycache__/globalparam.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/config/__pycache__/globalparam.cpython-35.pyc -------------------------------------------------------------------------------- /config/__pycache__/globalparam.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/config/__pycache__/globalparam.cpython-36.pyc -------------------------------------------------------------------------------- /public/__pycache__/exceptionscr.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/exceptionscr.cpython-35.pyc -------------------------------------------------------------------------------- /public/__pycache__/exceptionscr.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/public/__pycache__/exceptionscr.cpython-36.pyc -------------------------------------------------------------------------------- /test_case/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/test_case/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /test_case/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/test_case/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /data/testdata/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/data/testdata/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /data/testdata/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/data/testdata/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /test_case/__pycache__/a1_login_sta.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/test_case/__pycache__/a1_login_sta.cpython-35.pyc -------------------------------------------------------------------------------- /test_case/__pycache__/a1_login_sta.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/test_case/__pycache__/a1_login_sta.cpython-36.pyc -------------------------------------------------------------------------------- /data/testdata/__pycache__/data_read.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/data/testdata/__pycache__/data_read.cpython-35.pyc -------------------------------------------------------------------------------- /data/testdata/__pycache__/data_read.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/data/testdata/__pycache__/data_read.cpython-36.pyc -------------------------------------------------------------------------------- /report/exception_img/assert(2017_09_17_09_35_50).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/report/exception_img/assert(2017_09_17_09_35_50).jpg -------------------------------------------------------------------------------- /report/exception_img/assert(2017_09_17_09_39_50).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/report/exception_img/assert(2017_09_17_09_39_50).jpg -------------------------------------------------------------------------------- /report/exception_img/assert(2017_09_17_09_41_59).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/report/exception_img/assert(2017_09_17_09_41_59).jpg -------------------------------------------------------------------------------- /test_case/__pycache__/a2_forget_pwd_sta.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/test_case/__pycache__/a2_forget_pwd_sta.cpython-35.pyc -------------------------------------------------------------------------------- /test_case/__pycache__/a2_forget_pwd_sta.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/test_case/__pycache__/a2_forget_pwd_sta.cpython-36.pyc -------------------------------------------------------------------------------- /test_case/page_obj/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/test_case/page_obj/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /test_case/page_obj/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/test_case/page_obj/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /test_case/page_obj/__pycache__/a1_loginPage.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/test_case/page_obj/__pycache__/a1_loginPage.cpython-35.pyc -------------------------------------------------------------------------------- /test_case/page_obj/__pycache__/a1_loginPage.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/test_case/page_obj/__pycache__/a1_loginPage.cpython-36.pyc -------------------------------------------------------------------------------- /test_case/page_obj/__pycache__/a2_forget_password.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/test_case/page_obj/__pycache__/a2_forget_password.cpython-35.pyc -------------------------------------------------------------------------------- /test_case/page_obj/__pycache__/a2_forget_password.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhangmoumou1/selenium_python/HEAD/test_case/page_obj/__pycache__/a2_forget_password.cpython-36.pyc -------------------------------------------------------------------------------- /public/function.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append('/home/selenium_python') 3 | from config import globalparam 4 | from public.base import Page 5 | 6 | def insert_img(driver,file_name): 7 | """Screenshot function""" 8 | file_path = globalparam.img_path + "\\" + file_name 9 | Page(driver).take_screenshot(file_path) 10 | 11 | -------------------------------------------------------------------------------- /data/testdata/data_read.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append('/home/selenium_python') 3 | from public.datainfo import ExcelUtil 4 | from config import globalparam 5 | 6 | class Test1(): 7 | """Get the excel data""" 8 | def a1_data(self,sheet): 9 | """a1_login_sta's values""" 10 | filepath = globalparam.data_path + "/" + "datas.xlsx" 11 | sheetName = sheet 12 | data = ExcelUtil(filepath, sheetName) 13 | data1 = data.dict_data() 14 | return data1 15 | 16 | # filepath = "F:\git\zhangmoumou1\migu-web-1\data\\testdata\datas.xlsx" 17 | # sheetName = "a1_sta" 18 | # data = ExcelUtil(filepath, sheetName) 19 | # data1 = data.dict_data() 20 | # print(data1[1]['username']) 21 | -------------------------------------------------------------------------------- /run_ai_test.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | import sys 3 | sys.path.append('/home/selenium_python') 4 | from HTMLTestRunner import HTMLTestRunner 5 | from config import globalparam 6 | import unittest 7 | import time 8 | 9 | test_dir = "./test_case" 10 | discover = unittest.defaultTestLoader.discover(test_dir, pattern="*sta.py") 11 | 12 | if __name__ == "__main__": 13 | # Get the current time in a certain format 14 | now = time.strftime("%Y-%m-%d-%H-%M-%S") 15 | # Define the report storage path 16 | filename = globalparam.report_path + "\\" + now + "result.html" 17 | fp = open(filename, "wb") 18 | # Define test report 19 | runner = HTMLTestRunner(stream=fp, title="测试报告", description="用例执行情况:") 20 | runner.run(discover) 21 | fp.close() 22 | 23 | -------------------------------------------------------------------------------- /public/exceptionscr.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from config import globalparam 3 | import sys 4 | sys.path.append('/home/selenium_python') 5 | from public.base import Page 6 | class Screen(object): 7 | """截图功能装饰器""" 8 | def __init__(self, driver): 9 | self.driver = driver 10 | def __call__(self, f): 11 | def inner(*args): 12 | try: 13 | return f(*args) 14 | except: 15 | import time 16 | nowTime = time.strftime("%Y_%m_%d_%H_%M_%S") 17 | file_name = '%s.jpg' % nowTime 18 | file_path = globalparam.eximg_path + "\\" + file_name 19 | self.driver.get_screenshot_as_file(file_path) 20 | raise 21 | return inner 22 | -------------------------------------------------------------------------------- /test_case/page_obj/login_enter.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append('/home/selenium_python') 3 | from public.base import Page 4 | from data.testdata.data_read import Test1 5 | data1 = Test1().a1_data(sheet="a1_sta") 6 | 7 | class Log_on(Page): 8 | """ 9 | User login page 10 | """ 11 | #定位器 12 | login_username_loc = ("id", "username") 13 | login_password_loc = ("id", "password") 14 | login_button_loc = ("css selector", "input[class = 'btn_com btn_blue login_btn_submit sy_in']") 15 | #Action 16 | 17 | def login_entry(self, username=data1[0]['username'], password=data1[0]['password']): 18 | """User login successfully""" 19 | self.clear_type(self.login_username_loc, username) 20 | self.clear_type(self.login_password_loc, password) 21 | self.click(self.login_button_loc) 22 | 23 | -------------------------------------------------------------------------------- /public/myunit.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | import sys 3 | sys.path.append('/home/selenium_python') 4 | import unittest 5 | from public.log import Log 6 | from public import browser 7 | from public.base import Page 8 | from config import globalparam 9 | from selenium import webdriver 10 | 11 | 12 | class MyTest(unittest.TestCase, Page): 13 | 14 | @classmethod 15 | def setUpClass(self): 16 | self.logger = Log() 17 | self.logger.info('############################### START ###############################') 18 | self.driver = browser.select_browser(globalparam.browser) 19 | # self.driver.implicitly_wait(10) 20 | Page(self.driver).max_window() 21 | 22 | @classmethod 23 | def tearDownClass(self): 24 | self.driver.quit() 25 | self.logger.info('############################### End ###############################') 26 | -------------------------------------------------------------------------------- /config/globalparam.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | import os 3 | import sys 4 | sys.path.append('/home/selenium_python') 5 | from public.readconfig import ReadConfig 6 | 7 | # Read configuration file 8 | config_file_path = os.path.split(os.path.realpath(__file__))[0] 9 | read_config = ReadConfig(os.path.join(config_file_path, 'config.ini')) 10 | # Project parameter setting 11 | prj_path = read_config.getValue('projectConfig', 'project_path') 12 | # Log path 13 | log_path = os.path.join(prj_path, 'report', 'log') 14 | # Screenshot file path 15 | img_path = os.path.join(prj_path, 'report', 'image') 16 | #Exception screenshot file path 17 | eximg_path = os.path.join(prj_path, 'report', 'exception_img') 18 | #Test report path 19 | report_path = os.path.join(prj_path, 'report', 'test_report') 20 | #Upload the autoit file path 21 | auto_path = os.path.join(prj_path, 'up_files', 'autoit_pic') 22 | # Default browser 23 | browser = 'phantomjs' 24 | # Test data path 25 | data_path = os.path.join(prj_path, 'data', 'testdata') 26 | -------------------------------------------------------------------------------- /public/readconfig.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | import sys 3 | sys.path.append('/home/selenium_python') 4 | import configparser 5 | import codecs 6 | 7 | class ReadConfig: 8 | """ 9 | 专门读取配置文件的,.ini文件格式 10 | """ 11 | def __init__(self, filename): 12 | # configpath = os.path.join(prjDir,filename) 13 | configpath = filename 14 | # print(configpath) 15 | fd = open(configpath) 16 | data = fd.read() 17 | # remove BOM 18 | if data[:3] == codecs.BOM_UTF8: 19 | data = data[3:] 20 | files = codecs.open(configpath, "w") 21 | files.write(data) 22 | files.close() 23 | fd.close() 24 | 25 | self.cf = configparser.ConfigParser() 26 | self.cf.read(configpath) 27 | 28 | def getValue(self, env, name): 29 | """ 30 | [projectConfig] 31 | project_path=E:/fengsulian 32 | :param env:[projectConfig] 33 | :param name:project_path 34 | :return:E:/fengsulian 35 | """ 36 | return self.cf.get(env, name) 37 | 38 | -------------------------------------------------------------------------------- /public/datainfo.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import xlrd 3 | import sys 4 | sys.path.append('/home/selenium_python') 5 | class ExcelUtil(): 6 | def __init__(self, excelPath, sheetName): 7 | self.data = xlrd.open_workbook(excelPath) 8 | self.table = self.data.sheet_by_name(sheetName) 9 | # Get the first row as the key value 10 | self.keys = self.table.row_values(0) 11 | # Get the total number of rows 12 | self.rowNum = self.table.nrows 13 | # Get the total number of columns 14 | self.colNum = self.table.ncols 15 | 16 | def dict_data(self): 17 | if self.rowNum <= 1: 18 | print("总行数小于1") 19 | else: 20 | r = [] 21 | j = 1 22 | for i in range(self.rowNum-1): 23 | s = {} 24 | # 从第二行取对应values值 25 | values = self.table.row_values(j) 26 | for x in range(self.colNum): 27 | s[self.keys[x]] = values[x] 28 | r.append(s) 29 | j += 1 30 | return r 31 | 32 | # if __name__ == "__main__": 33 | # filepath = "F:\\Git\\migu-web\\data\\testdata\datas.xlsx" 34 | # sheetName = "a1_sta" 35 | # data = ExcelUtil(filepath, sheetName) 36 | # print(data.dict_data()) 37 | 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🎉 当前框架应用于web自动化测试,APP自动化可使用云真机平台点击查阅 2 | #### 一、实现步骤参考 3 | 1、理解框架各个模块和调用流程(如不理解可参考readme文件下的xmind流程图)
4 |
5 | 2、以页面为单位编写自动化测试用例
6 |
7 | 3、封装公共模块(webdriver定位方法、截图、日志、登录、数据读写等)
8 |
9 | 4、可以先单独写脚本对元素定位和操作进行调试,成功后再引入框架
10 |
11 | 5、使用PageObject模式来编写测试脚本,实现页面操作、定位、用例、测试数据的分离,提高代码维护性
12 |
13 | 6、最后可通过Jenkins+tomcat+git持续集成平台,实现脚本的维护、构建控制并输出测试报告
14 | 15 | #### 二、框架目录讲解
16 | ![no view](https://github.com/zhangmoumou1/selenium-python/blob/master/readme/%E6%A1%86%E6%9E%B6%E7%9B%AE%E5%BD%95.jpg)
17 | 1、config文件夹:config.ini 配置项目的路径;globalparam.py 封装所有需要获取或者保存的路径,如日志、截图、测试报告、上传文件、测试数据;
18 |
19 | 2、data文件夹:dataread.py读取excel数据,把字典存储在列表中;datas.xlsx存储测试数据;
20 |
21 | 3、public文件夹:公共方法的封装,如webdriver操作、logging、读取excel数据、截图、日志、读取配置文件、发送报告;
22 |
23 | 4、report文件夹:用例失败截图、用例成功截图、存放日志和测试报告;
24 |
25 | ![no view](https://github.com/zhangmoumou1/selenium-python/blob/master/readme/%E6%B5%8B%E8%AF%95%E6%8A%A5%E5%91%8A.jpg)
26 | ![no view](https://github.com/zhangmoumou1/selenium-python/blob/master/readme/%E6%97%A5%E5%BF%97.jpg)
27 |
28 | 5、test_case文件夹:page_obj下主要写元素定位和动作流程;*sta.py根据page页面写测试用例;
29 |
30 | 6、up_files文件夹:根据autoit工具保存上传文件.exe文件;
31 |
32 | 7、run_ai_test.py:测试用例执行文件并生成测试报告。
33 | -------------------------------------------------------------------------------- /public/browser.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | import sys 3 | sys.path.append('/home/selenium_python') 4 | 5 | def select_browser(browser='chrome', remoteAddress=None): 6 | dc = {'platform': 'ANY', 'browserName': 'chrome', 'version': '', 'javascriptEnabled': True} 7 | dr = None 8 | if remoteAddress is None: 9 | if browser == "firefox" or browser == "ff": 10 | dr = webdriver.Firefox() 11 | elif browser == "chrome" or browser == "Chrome": 12 | dr = webdriver.Chrome() 13 | elif browser == "internet explorer" or browser == "ie": 14 | dr = webdriver.Ie() 15 | elif browser == "opera": 16 | dr = webdriver.Opera() 17 | elif browser == "phantomjs": 18 | dr = webdriver.PhantomJS() 19 | elif browser == "edge": 20 | dr = webdriver.Edge() 21 | else: 22 | if browser == "RChrome": 23 | dr = webdriver.Remote(command_executor='http://' + remoteAddress + '/wd/hub', 24 | desired_capabilities=dc) 25 | elif browser == "RIE": 26 | dc['browserName'] = 'internet explorer' 27 | dr = webdriver.Remote(command_executor='http://' + remoteAddress + '/wd/hub', 28 | desired_capabilities=dc) 29 | elif browser == "RFirefox": 30 | dc['browserName'] = 'firefox' 31 | dc['marionette'] = False 32 | dr = webdriver.Remote(command_executor='http://' + remoteAddress + '/wd/hub', 33 | desired_capabilities=dc) 34 | return dr 35 | -------------------------------------------------------------------------------- /test_case/a1_login_sta.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append('/home/selenium_python') 3 | import unittest 4 | #import ddt 5 | from public.exceptionscr import Screen 6 | from data.testdata.data_read import Test1 7 | from public.myunit import MyTest 8 | from public import function 9 | from public.base import Page 10 | from test_case.page_obj.a1_loginPage import login 11 | data1 = Test1().a1_data(sheet = "a1_sta") 12 | 13 | # @ddt.ddt 14 | # @unittest.skip("跳过此用例") 15 | class loginTest(MyTest,Page): 16 | """用户密码登录""" 17 | 18 | # @Screen(driver) 19 | def test_login1(self,expected=True): 20 | """用户名输入有误""" 21 | po = login(self.driver) 22 | po.user_login(username=data1[1]['username']) 23 | self.assert_equal(po.user_error_hint(actual=data1[1]['result']),expected) 24 | function.insert_img(self.driver,data1[1]['screenshot_name']) 25 | 26 | def test_login2(self,expected=True): 27 | """密码输入有误""" 28 | po = login(self.driver) 29 | po.user_login(password=data1[2]['password']) 30 | self.assert_equal(po.pawd_error_hint(actual=data1[2]['result']),expected) 31 | function.insert_img(self.driver, data1[2]['screenshot_name']) 32 | 33 | #@ddt.data(*data1) 34 | @unittest.skip("跳过此用例") 35 | def test_login3(self,expected=True): 36 | """用户名密码正确,登录成功""" 37 | po = login(self.driver) 38 | po.user_login(username=data1[3]['username'], password=data1[3]['password']) 39 | self.assert_equal(po.user_login_success(actual=data1[3]['result']), expected) 40 | function.insert_img(self.driver, data1[3]['screenshot_name']) 41 | 42 | if __name__ == "__main__": 43 | unittest.main() 44 | 45 | 46 | -------------------------------------------------------------------------------- /public/log.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | import logging 3 | import time 4 | import os 5 | import sys 6 | sys.path.append('/home/selenium_python') 7 | from config import globalparam 8 | 9 | log_path = globalparam.log_path 10 | class Log: 11 | def __init__(self): 12 | self.logname = os.path.join(log_path, '{0}.log'.format(time.strftime('%Y-%m-%d-%H-%M-%S'))) 13 | 14 | def __printconsole(self, level, message): 15 | # 创建一个logger 16 | logger = logging.getLogger() 17 | logger.setLevel(logging.DEBUG) 18 | # 创建一个handler,用于写入日志文件 19 | fh = logging.FileHandler(self.logname,'a',encoding='utf-8') 20 | fh.setLevel(logging.DEBUG) 21 | # 再创建一个handler,用于输出到控制台 22 | ch = logging.StreamHandler() 23 | ch.setLevel(logging.DEBUG) 24 | # 定义handler的输出格式 25 | formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') 26 | fh.setFormatter(formatter) 27 | ch.setFormatter(formatter) 28 | # 给logger添加handler 29 | logger.addHandler(fh) 30 | logger.addHandler(ch) 31 | # 记录一条日志 32 | if level == 'info': 33 | logger.info(message) 34 | elif level == 'debug': 35 | logger.debug(message) 36 | elif level == 'warning': 37 | logger.warning(message) 38 | elif level == 'error': 39 | logger.error(message) 40 | logger.removeHandler(ch) 41 | logger.removeHandler(fh) 42 | # 关闭打开的文件 43 | fh.close() 44 | 45 | def debug(self, message): 46 | self.__printconsole('debug', message) 47 | 48 | def info(self, message): 49 | self.__printconsole('info', message) 50 | 51 | def warning(self, message): 52 | self.__printconsole('warning', message) 53 | 54 | def error(self, message): 55 | self.__printconsole('error', message) 56 | -------------------------------------------------------------------------------- /test_case/page_obj/a1_loginPage.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append('/home/selenium_python') 3 | from data.testdata.data_read import Test1 4 | from public.base import Page 5 | data1 = Test1().a1_data(sheet="a1_sta") 6 | 7 | class login(Page): 8 | """ 9 | User login page 10 | """ 11 | url = "" 12 | #定位器 13 | login_iframe_loc = ("xpath", "//iframe[contains(@src,'https://wap.cmread.com/sso/auth?e_p=1&response_type=token')]") 14 | login_username_loc = ("id", "unameInput") 15 | login_password_loc = ("id", "pwdInput") 16 | login_button_loc = ("css selector", "input[name = 'login']") 17 | #Action 18 | def login_iframe(self): 19 | self.switch_to_frame(self.login_iframe_loc) 20 | def login_username(self,username): 21 | self.clear_type(self.login_username_loc, username) 22 | def login_password(self,password): 23 | self.clear_type(self.login_password_loc, password) 24 | def login_button(self): 25 | self.click(self.login_button_loc) 26 | 27 | #login inlet 28 | def user_login(self, username=data1[0]['username'], password=data1[0]['password']): 29 | """ 30 | User name password login 31 | """ 32 | self.open() 33 | self.login_iframe() 34 | self.login_username(username) 35 | self.login_password(password) 36 | self.login_button() 37 | 38 | #定位器 39 | input_error_loc = ("class name", "wrong") 40 | user_login_success_loc = ("css selector", "span[title = '好的好的d']") 41 | #Action 42 | def user_error_hint(self,actual): 43 | """用户名输入有误""" 44 | return self.is_text_in_element(self.input_error_loc, actual) 45 | def pawd_error_hint(self,actual): 46 | """密码输入有误""" 47 | return self.is_text_in_element(self.input_error_loc, actual) 48 | def user_login_success(self,actual): 49 | """成功登录获取当前账号""" 50 | return self.is_text_in_element(self.user_login_success_loc, actual) 51 | -------------------------------------------------------------------------------- /public/sendmail.py: -------------------------------------------------------------------------------- 1 | #coding:utf-8 2 | import os 3 | import sys 4 | sys.path.append('/home/selenium_python') 5 | import smtplib 6 | import time 7 | from email.mime.text import MIMEText 8 | from email.mime.multipart import MIMEMultipart 9 | from public.log import Log 10 | from config import globalparam 11 | 12 | # 测试报告的路径 13 | reportPath = globalparam.report_path 14 | logger = Log() 15 | # 配置收发件人 16 | recvaddress = ['xxx.xx@xxx.com','xxxx@qq.com'] 17 | # 163的用户名和密码 18 | sendaddr_name = 'xxxxx@163.com' 19 | sendaddr_pswd = 'xxxxx' 20 | 21 | class SendMail: 22 | def __init__(self,recver=None): 23 | """接收邮件的人:list or tuple""" 24 | if recver is None: 25 | self.sendTo = recvaddress 26 | else: 27 | self.sendTo = recver 28 | 29 | def __get_report(self): 30 | """获取最新测试报告""" 31 | dirs = os.listdir(reportPath) 32 | dirs.sort() 33 | newreportname = dirs[-1] 34 | print('The new report name: {0}'.format(newreportname)) 35 | return newreportname 36 | 37 | def __take_messages(self): 38 | """生成邮件的内容,和html报告附件""" 39 | newreport = self.__get_report() 40 | self.msg = MIMEMultipart() 41 | self.msg['Subject'] = '测试报告主题' 42 | self.msg['date'] = time.strftime('%a, %d %b %Y %H:%M:%S %z') 43 | 44 | with open(os.path.join(reportPath,newreport), 'rb') as f: 45 | mailbody = f.read() 46 | html = MIMEText(mailbody,_subtype='html',_charset='utf-8') 47 | self.msg.attach(html) 48 | 49 | # html附件 50 | att1 = MIMEText(mailbody, 'base64', 'gb2312') 51 | att1["Content-Type"] = 'application/octet-stream' 52 | att1["Content-Disposition"] = 'attachment; filename="TestReport.html"'#这里的filename可以任意写,写什么名字,邮件中显示什么名字 53 | self.msg.attach(att1) 54 | 55 | def send(self): 56 | """发送邮件""" 57 | self.__take_messages() 58 | self.msg['from'] = sendaddr_name 59 | try: 60 | smtp = smtplib.SMTP('smtp.163.com',25) 61 | smtp.login(sendaddr_name,sendaddr_pswd) 62 | smtp.sendmail(self.msg['from'], self.sendTo,self.msg.as_string()) 63 | smtp.close() 64 | logger.info("发送邮件成功") 65 | except Exception: 66 | logger.error('发送邮件失败') 67 | raise 68 | 69 | if __name__ == '__main__': 70 | sendMail = SendMail() 71 | sendMail.send() 72 | 73 | 74 | -------------------------------------------------------------------------------- /test_case/page_obj/a2_forget_password.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append('/home/selenium_python') 3 | from public.base import Page 4 | from config import globalparam 5 | from data.testdata.data_read import Test1 6 | data1 = Test1().a1_data(sheet = "a2_sta") 7 | 8 | class forget(Page): 9 | """ 10 | Forget password page 11 | """ 12 | url = "/www/goFindPwd" 13 | #定位器 14 | forget_name_loc = ("id", "username") 15 | forget_submit_loc = ("css selector", "img[src = 'images/tj2.gif']") 16 | input_answer_loc = ("id", "answer") 17 | answer_determine_loc = ("css selector", "img[src = 'images/qd.gif']") 18 | 19 | #action 20 | def forget_name(self, username): 21 | """Enter username""" 22 | self.clear_type(self.forget_name_loc, username) 23 | def forget_submit(self): 24 | """Click on the submit""" 25 | self.click(self.forget_submit_loc) 26 | def input_answer(self,answer): 27 | """Enter the answer""" 28 | self.clear_type(self.input_answer_loc, answer) 29 | def answer_determine(self): 30 | """Click ok""" 31 | self.click(self.answer_determine_loc) 32 | 33 | #answer inlet 34 | def forget_pwd1(self, username=data1[0]['username']): 35 | """Forget password 1""" 36 | self.open() 37 | self.forget_name(username) 38 | self.forget_submit() 39 | def forget_pwd2(self, username=data1[0]['username']): 40 | """Forget password 2""" 41 | for i in range(3): 42 | self.forget_name(username) 43 | self.forget_submit() 44 | def answer1(self, answer=data1[6]["answer"]): 45 | """Enter the answer""" 46 | self.input_answer(answer) 47 | self.answer_determine() 48 | 49 | #定位器 50 | username_error_loc = ("id", "usernameId") 51 | username_succ_loc = ("css selector", "font[class='bold font14']") 52 | answer_error1_loc = ("id", "answerMsg") 53 | answer_error2_loc = ("id", "resultMsg") 54 | 55 | #action 56 | def username_error(self, actual): 57 | """用户名为空/至少5位数/纯数字/未设置密保/输入错误超过3次""" 58 | return self.is_text_in_element(self.username_error_loc, actual) 59 | def username_succ(self, actual): 60 | """账户正确,进入密保""" 61 | return self.is_text_in_element(self.username_succ_loc, actual) 62 | def answer_error1(self, actual): 63 | """答案为空""" 64 | return self.is_text_in_element(self.answer_error1_loc, actual) 65 | def answer_error2(self, actual): 66 | """超过三次""" 67 | return self.is_text_in_element(self.answer_error2_loc, actual) 68 | 69 | 70 | -------------------------------------------------------------------------------- /test_case/a2_forget_pwd_sta.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import sys 3 | sys.path.append('/home/selenium_python') 4 | from public import myunit, function 5 | from public.base import Page 6 | from test_case.page_obj.a2_forget_password import forget 7 | from data.testdata.data_read import Test1 8 | data1 = Test1().a1_data(sheet = "a2_sta") 9 | 10 | # @unittest.skip("跳过此用例") 11 | class PersonalTest(myunit.MyTest,Page): 12 | """ 忘记密码,找回密码""" 13 | 14 | def test_forget_pwd1(self, expected=True): 15 | """用户名输入为空""" 16 | po = forget(self.driver) 17 | po.forget_pwd1(username=data1[1]['username']) 18 | self.assert_equal(po.username_error(actual=data1[1]['result']), expected) 19 | function.insert_img(self.driver, data1[1]['screenshot_name']) 20 | 21 | def test_forget_pwd2(self, expected=True): 22 | """输入4位数的用户名有误""" 23 | po = forget(self.driver) 24 | po.forget_pwd1(username=data1[2]['username']) 25 | self.assert_equal(po.username_error(actual=data1[2]['result']), expected) 26 | function.insert_img(self.driver, data1[2]['screenshot_name']) 27 | 28 | def test_forget_pwd3(self, expected=True): 29 | """输入纯数字的用户名有误""" 30 | po = forget(self.driver) 31 | po.forget_pwd1(username=data1[3]['username']) 32 | self.assert_equal(po.username_error(actual=data1[3]['result']), expected) 33 | function.insert_img(self.driver, data1[3]['screenshot_name']) 34 | 35 | def test_forget_pwd4(self, expected=True): 36 | """当前用户未设置密保""" 37 | po = forget(self.driver) 38 | po.forget_pwd1(username=data1[4]['username']) 39 | self.assert_equal(po.username_error(actual=data1[4]['result']), expected) 40 | function.insert_img(self.driver, data1[4]['screenshot_name']) 41 | 42 | def test_forget_pwd5(self, expected=True): 43 | """输入错误次数已超过三次""" 44 | po = forget(self.driver) 45 | po.forget_pwd1(username=data1[5]['username']) 46 | po.forget_pwd2(username=data1[5]['username']) 47 | self.assert_equal(po.username_error(actual=data1[5]['result']), expected) 48 | function.insert_img(self.driver, data1[5]['screenshot_name']) 49 | 50 | def test_forget_pwd6(self, expected=True): 51 | """输入账号正确,进入密保""" 52 | po = forget(self.driver) 53 | po.forget_pwd1(username=data1[6]['username']) 54 | self.assert_equal(po.username_succ(actual=data1[6]['result']), expected) 55 | function.insert_img(self.driver, data1[6]['screenshot_name']) 56 | 57 | def test_forget_pwd7(self, expected=True): 58 | """密保答案输入为空""" 59 | po = forget(self.driver) 60 | po.forget_pwd1() 61 | po.answer1(answer=data1[7]['answer']) 62 | self.assert_equal(po.answer_error1(actual=data1[7]['result']), expected) 63 | function.insert_img(self.driver, data1[6]['screenshot_name']) 64 | 65 | def test_forget_pwd8(self, expected=True): 66 | """密保答案失败请求已超过3次机会""" 67 | po = forget(self.driver) 68 | po.forget_pwd1() 69 | po.answer1(answer=data1[8]['answer']) 70 | self.assert_equal(po.answer_error2(actual=data1[8]['result']), expected) 71 | function.insert_img(self.driver, data1[8]['screenshot_name']) 72 | 73 | if __name__ == "__main__": 74 | unittest.main() 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /report/log/2017-08-24.log: -------------------------------------------------------------------------------- 1 | 2017-08-24 10:52:39,254 - root - INFO - ############################### START ############################### 2 | 2017-08-24 10:52:44,065 - root - INFO - SUCCESS Set browser window maximized, Spend 1.1670665740966797 seconds 3 | 2017-08-24 10:52:45,491 - root - INFO - SUCCESS Navigated to http://www.cmread.com/u/tologin.do?preUrl=http%3A%2F%2Fwww.cmread.com%2Fu%2Findex, Spend 1.426081895828247 seconds 4 | 2017-08-24 10:52:45,533 - root - INFO - SUCCESS Switch to frame element: //iframe[contains(@src,'https://wap.cmread.com/sso/auth?e_p=1&response_type=token')]>, Spend 0.04000210762023926 seconds 5 | 2017-08-24 10:52:45,600 - root - INFO - SUCCESS Clear and type element: unameInput> content: , Spend 0.06700348854064941 seconds 6 | 2017-08-24 10:52:45,677 - root - INFO - SUCCESS Clear and type element: pwdInput> content: zyc12345, Spend 0.0760045051574707 seconds 7 | 2017-08-24 10:52:45,823 - root - INFO - SUCCESS Clicked element: input[name = 'login']>, Spend 0.14600825309753418 seconds 8 | 2017-08-24 10:52:45,858 - root - INFO - SUCCESS positioned to element: wrong> , Spend 0.03500175476074219 seconds 9 | 2017-08-24 10:52:45,859 - root - INFO - SUCCESS say with certainty: True == True, Spend 0.0 seconds 10 | 2017-08-24 10:52:46,096 - root - INFO - SUCCESS Get the current window screenshot,path: F:\Git\migu-web\report\image\a1_1.jpg, Spend 0.23601365089416504 seconds 11 | 2017-08-24 10:52:46,204 - root - INFO - SUCCESS Navigated to http://www.cmread.com/u/tologin.do?preUrl=http%3A%2F%2Fwww.cmread.com%2Fu%2Findex, Spend 0.10700631141662598 seconds 12 | 2017-08-24 10:52:46,228 - root - INFO - SUCCESS Switch to frame element: //iframe[contains(@src,'https://wap.cmread.com/sso/auth?e_p=1&response_type=token')]>, Spend 0.02300095558166504 seconds 13 | 2017-08-24 10:52:46,295 - root - INFO - SUCCESS Clear and type element: unameInput> content: 15868147450, Spend 0.06700396537780762 seconds 14 | 2017-08-24 10:52:46,351 - root - INFO - SUCCESS Clear and type element: pwdInput> content: , Spend 0.05600333213806152 seconds 15 | 2017-08-24 10:52:46,468 - root - INFO - SUCCESS Clicked element: input[name = 'login']>, Spend 0.11600661277770996 seconds 16 | 2017-08-24 10:52:46,492 - root - INFO - SUCCESS positioned to element: wrong> , Spend 0.022001266479492188 seconds 17 | 2017-08-24 10:52:46,492 - root - INFO - SUCCESS say with certainty: True == True, Spend 0.0 seconds 18 | 2017-08-24 10:52:46,678 - root - INFO - SUCCESS Get the current window screenshot,path: F:\Git\migu-web\report\image\a1_2.jpg, Spend 0.18501067161560059 seconds 19 | 2017-08-24 10:52:46,753 - root - INFO - SUCCESS Navigated to http://www.cmread.com/u/tologin.do?preUrl=http%3A%2F%2Fwww.cmread.com%2Fu%2Findex, Spend 0.0740041732788086 seconds 20 | 2017-08-24 10:52:46,781 - root - INFO - SUCCESS Switch to frame element: //iframe[contains(@src,'https://wap.cmread.com/sso/auth?e_p=1&response_type=token')]>, Spend 0.026001691818237305 seconds 21 | 2017-08-24 10:52:46,848 - root - INFO - SUCCESS Clear and type element: unameInput> content: 15868147450, Spend 0.06700372695922852 seconds 22 | 2017-08-24 10:52:46,910 - root - INFO - SUCCESS Clear and type element: pwdInput> content: zyc12345, Spend 0.06100320816040039 seconds 23 | 2017-08-24 10:52:48,805 - root - INFO - SUCCESS Clicked element: input[name = 'login']>, Spend 1.894108533859253 seconds 24 | 2017-08-24 10:52:48,862 - root - INFO - SUCCESS positioned to element: span[title = '好的好的d']> , Spend 0.05600333213806152 seconds 25 | 2017-08-24 10:52:48,863 - root - INFO - SUCCESS say with certainty: True == True, Spend 0.0 seconds 26 | 2017-08-24 10:52:49,112 - root - INFO - SUCCESS Get the current window screenshot,path: F:\Git\migu-web\report\image\a1_3.jpg, Spend 0.24701428413391113 seconds 27 | 2017-08-24 10:52:52,163 - root - INFO - ############################### End ############################### 28 | 2017-08-24 10:52:52,166 - root - INFO - ############################### START ############################### 29 | 2017-08-24 10:52:57,050 - root - INFO - SUCCESS Set browser window maximized, Spend 1.180067539215088 seconds 30 | 2017-08-24 10:52:58,058 - root - INFO - SUCCESS Navigated to http://www.cmread.com/www/goFindPwd, Spend 1.0060575008392334 seconds 31 | 2017-08-24 10:52:58,143 - root - INFO - SUCCESS Clear and type element: username> content: , Spend 0.08300471305847168 seconds 32 | 2017-08-24 10:52:58,201 - root - INFO - SUCCESS Clicked element: img[src = 'images/tj2.gif']>, Spend 0.057003021240234375 seconds 33 | 2017-08-24 10:52:58,232 - root - INFO - SUCCESS positioned to element: usernameId> , Spend 0.031001806259155273 seconds 34 | 2017-08-24 10:52:58,233 - root - INFO - SUCCESS say with certainty: True == True, Spend 0.0 seconds 35 | 2017-08-24 10:52:58,499 - root - INFO - SUCCESS Get the current window screenshot,path: F:\Git\migu-web\report\image\a2_1.jpg, Spend 0.26601505279541016 seconds 36 | 2017-08-24 10:52:58,709 - root - INFO - SUCCESS Navigated to http://www.cmread.com/www/goFindPwd, Spend 0.20901179313659668 seconds 37 | 2017-08-24 10:52:58,773 - root - INFO - SUCCESS Clear and type element: username> content: 1111, Spend 0.0630037784576416 seconds 38 | 2017-08-24 10:52:58,824 - root - INFO - SUCCESS Clicked element: img[src = 'images/tj2.gif']>, Spend 0.05100274085998535 seconds 39 | 2017-08-24 10:52:58,848 - root - INFO - SUCCESS positioned to element: usernameId> , Spend 0.022001266479492188 seconds 40 | 2017-08-24 10:52:58,848 - root - INFO - SUCCESS say with certainty: True == True, Spend 0.0 seconds 41 | 2017-08-24 10:52:59,092 - root - INFO - SUCCESS Get the current window screenshot,path: F:\Git\migu-web\report\image\a2_2.jpg, Spend 0.24201369285583496 seconds 42 | 2017-08-24 10:52:59,373 - root - INFO - SUCCESS Navigated to http://www.cmread.com/www/goFindPwd, Spend 0.2800161838531494 seconds 43 | 2017-08-24 10:52:59,440 - root - INFO - SUCCESS Clear and type element: username> content: 11111, Spend 0.06700372695922852 seconds 44 | 2017-08-24 10:52:59,493 - root - INFO - SUCCESS Clicked element: img[src = 'images/tj2.gif']>, Spend 0.052002668380737305 seconds 45 | 2017-08-24 10:52:59,516 - root - INFO - SUCCESS positioned to element: usernameId> , Spend 0.023001432418823242 seconds 46 | 2017-08-24 10:52:59,517 - root - INFO - SUCCESS say with certainty: True == True, Spend 0.0 seconds 47 | 2017-08-24 10:52:59,775 - root - INFO - SUCCESS Get the current window screenshot,path: F:\Git\migu-web\report\image\a2_3.jpg, Spend 0.25701451301574707 seconds 48 | 2017-08-24 10:52:59,966 - root - INFO - SUCCESS Navigated to http://www.cmread.com/www/goFindPwd, Spend 0.1910109519958496 seconds 49 | 2017-08-24 10:53:00,041 - root - INFO - SUCCESS Clear and type element: username> content: dddddddddddddddddddd, Spend 0.0740044116973877 seconds 50 | 2017-08-24 10:53:00,101 - root - INFO - SUCCESS Clicked element: img[src = 'images/tj2.gif']>, Spend 0.05800342559814453 seconds 51 | 2017-08-24 10:53:00,849 - root - INFO - SUCCESS positioned to element: usernameId> , Spend 0.7480428218841553 seconds 52 | 2017-08-24 10:53:00,850 - root - INFO - SUCCESS say with certainty: True == True, Spend 0.0 seconds 53 | 2017-08-24 10:53:01,097 - root - INFO - SUCCESS Get the current window screenshot,path: F:\Git\migu-web\report\image\a2_4.jpg, Spend 0.24601411819458008 seconds 54 | 2017-08-24 10:53:01,248 - root - INFO - SUCCESS Navigated to http://www.cmread.com/www/goFindPwd, Spend 0.1500086784362793 seconds 55 | 2017-08-24 10:53:01,317 - root - INFO - SUCCESS Clear and type element: username> content: zhangyancheng, Spend 0.06800389289855957 seconds 56 | 2017-08-24 10:53:01,366 - root - INFO - SUCCESS Clicked element: img[src = 'images/tj2.gif']>, Spend 0.04800271987915039 seconds 57 | 2017-08-24 10:53:01,401 - root - INFO - SUCCESS Clear and type element: username> content: zhangyancheng, Spend 0.03500223159790039 seconds 58 | 2017-08-24 10:53:01,435 - root - INFO - SUCCESS Clicked element: img[src = 'images/tj2.gif']>, Spend 0.03300189971923828 seconds 59 | 2017-08-24 10:53:01,479 - root - INFO - SUCCESS Clear and type element: username> content: zhangyancheng, Spend 0.04300236701965332 seconds 60 | 2017-08-24 10:53:01,505 - root - INFO - SUCCESS Clicked element: img[src = 'images/tj2.gif']>, Spend 0.02500152587890625 seconds 61 | 2017-08-24 10:53:01,540 - root - INFO - SUCCESS Clear and type element: username> content: zhangyancheng, Spend 0.03500175476074219 seconds 62 | 2017-08-24 10:53:01,564 - root - INFO - SUCCESS Clicked element: img[src = 'images/tj2.gif']>, Spend 0.024001598358154297 seconds 63 | 2017-08-24 10:53:01,586 - root - INFO - SUCCESS positioned to element: usernameId> , Spend 0.021001338958740234 seconds 64 | 2017-08-24 10:53:01,587 - root - INFO - SUCCESS say with certainty: True == True, Spend 0.0 seconds 65 | 2017-08-24 10:53:01,856 - root - INFO - SUCCESS Get the current window screenshot,path: F:\Git\migu-web\report\image\a2_5.jpg, Spend 0.26801538467407227 seconds 66 | 2017-08-24 10:53:02,008 - root - INFO - SUCCESS Navigated to http://www.cmread.com/www/goFindPwd, Spend 0.1520087718963623 seconds 67 | 2017-08-24 10:53:02,072 - root - INFO - SUCCESS Clear and type element: username> content: zhang, Spend 0.0630035400390625 seconds 68 | 2017-08-24 10:53:02,121 - root - INFO - SUCCESS Clicked element: img[src = 'images/tj2.gif']>, Spend 0.04800271987915039 seconds 69 | 2017-08-24 10:53:02,717 - root - INFO - SUCCESS positioned to element: font[class='bold font14']> , Spend 0.5960335731506348 seconds 70 | 2017-08-24 10:53:02,718 - root - INFO - SUCCESS say with certainty: True == True, Spend 0.0 seconds 71 | 2017-08-24 10:53:02,973 - root - INFO - SUCCESS Get the current window screenshot,path: F:\Git\migu-web\report\image\a2_6.jpg, Spend 0.2540144920349121 seconds 72 | 2017-08-24 10:53:03,114 - root - INFO - SUCCESS Navigated to http://www.cmread.com/www/goFindPwd, Spend 0.1390078067779541 seconds 73 | 2017-08-24 10:53:03,189 - root - INFO - SUCCESS Clear and type element: username> content: zhang, Spend 0.07500433921813965 seconds 74 | 2017-08-24 10:53:03,241 - root - INFO - SUCCESS Clicked element: img[src = 'images/tj2.gif']>, Spend 0.0500025749206543 seconds 75 | 2017-08-24 10:53:03,489 - root - INFO - SUCCESS Clear and type element: answer> content: , Spend 0.24801421165466309 seconds 76 | 2017-08-24 10:53:03,547 - root - INFO - SUCCESS Clicked element: img[src = 'images/qd.gif']>, Spend 0.057003021240234375 seconds 77 | 2017-08-24 10:53:03,578 - root - INFO - SUCCESS positioned to element: answerMsg> , Spend 0.03000164031982422 seconds 78 | 2017-08-24 10:53:03,579 - root - INFO - SUCCESS say with certainty: True == True, Spend 0.0 seconds 79 | 2017-08-24 10:53:03,810 - root - INFO - SUCCESS Get the current window screenshot,path: F:\Git\migu-web\report\image\a2_6.jpg, Spend 0.23101329803466797 seconds 80 | 2017-08-24 10:53:03,958 - root - INFO - SUCCESS Navigated to http://www.cmread.com/www/goFindPwd, Spend 0.14700841903686523 seconds 81 | 2017-08-24 10:53:04,022 - root - INFO - SUCCESS Clear and type element: username> content: zhang, Spend 0.0630035400390625 seconds 82 | 2017-08-24 10:53:04,070 - root - INFO - SUCCESS Clicked element: img[src = 'images/tj2.gif']>, Spend 0.04800295829772949 seconds 83 | 2017-08-24 10:53:04,735 - root - INFO - SUCCESS Clear and type element: answer> content: 1111111111111, Spend 0.6640379428863525 seconds 84 | 2017-08-24 10:53:04,793 - root - INFO - SUCCESS Clicked element: img[src = 'images/qd.gif']>, Spend 0.05800318717956543 seconds 85 | 2017-08-24 10:53:05,367 - root - INFO - SUCCESS positioned to element: resultMsg> , Spend 0.5740327835083008 seconds 86 | 2017-08-24 10:53:05,370 - root - INFO - SUCCESS say with certainty: True == True, Spend 0.0 seconds 87 | 2017-08-24 10:53:05,648 - root - INFO - SUCCESS Get the current window screenshot,path: F:\Git\migu-web\report\image\a2_8.jpg, Spend 0.27701568603515625 seconds 88 | 2017-08-24 10:53:08,689 - root - INFO - ############################### End ############################### 89 | -------------------------------------------------------------------------------- /report/test_report/2017-08-24 10-52-39result.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 测试报告 6 | 7 | 8 | 9 | 92 | 93 | 94 | 95 | 189 | 190 |
191 |

测试报告

192 |

Start Time: 2017-08-24 10:52:39

193 |

Duration: 0:00:29.435684

194 |

Status: Pass 11

195 | 196 |

用例执行情况:

197 |
198 | 199 | 200 | 201 |

Show 202 | Summary 203 | Failed 204 | All 205 |

206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 255 | 256 | 257 | 258 | 259 | 279 | 280 | 281 | 282 | 283 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 336 | 337 | 338 | 339 | 340 | 360 | 361 | 362 | 363 | 364 | 384 | 385 | 386 | 387 | 388 | 408 | 409 | 410 | 411 | 412 | 432 | 433 | 434 | 435 | 436 | 456 | 457 | 458 | 459 | 460 | 480 | 481 | 482 | 483 | 484 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 |
Test Group/Test caseCountPassFailErrorView
a1_login_sta.loginTest: 用户密码登录3300Detail
test_login1: 用户名输入有误
236 | 237 | 238 | 239 | pass 240 | 241 | 252 | 253 | 254 |
test_login2: 密码输入有误
260 | 261 | 262 | 263 | pass 264 | 265 | 276 | 277 | 278 |
test_login3: 用户名密码正确,登录成功
284 | 285 | 286 | 287 | pass 288 | 289 | 300 | 301 | 302 |
a2_forget_pwd_sta.PersonalTest: 忘记密码,找回密码8800Detail
test_forget_pwd1: 用户名输入为空
317 | 318 | 319 | 320 | pass 321 | 322 | 333 | 334 | 335 |
test_forget_pwd2: 输入4位数的用户名有误
341 | 342 | 343 | 344 | pass 345 | 346 | 357 | 358 | 359 |
test_forget_pwd3: 输入纯数字的用户名有误
365 | 366 | 367 | 368 | pass 369 | 370 | 381 | 382 | 383 |
test_forget_pwd4: 当前用户未设置密保
389 | 390 | 391 | 392 | pass 393 | 394 | 405 | 406 | 407 |
test_forget_pwd5: 输入错误次数已超过三次
413 | 414 | 415 | 416 | pass 417 | 418 | 429 | 430 | 431 |
test_forget_pwd6: 输入账号正确,进入密保
437 | 438 | 439 | 440 | pass 441 | 442 | 453 | 454 | 455 |
test_forget_pwd7: 密保答案输入为空
461 | 462 | 463 | 464 | pass 465 | 466 | 477 | 478 | 479 |
test_forget_pwd8: 密保答案失败请求已超过3次机会
485 | 486 | 487 | 488 | pass 489 | 490 | 501 | 502 | 503 |
Total111100 
515 | 516 |
 
517 | 518 | 519 | 520 | -------------------------------------------------------------------------------- /public/base.py: -------------------------------------------------------------------------------- 1 | import time 2 | import os.path 3 | import sys 4 | sys.path.append('/home/selenium_python') 5 | from selenium import webdriver 6 | from selenium.webdriver.common.action_chains import ActionChains 7 | from selenium.webdriver.support.wait import WebDriverWait 8 | from selenium.webdriver.support import expected_conditions as EC 9 | from selenium.webdriver.common.keys import Keys 10 | from selenium.common.exceptions import TimeoutException 11 | from public.log import Log 12 | from config import globalparam 13 | 14 | success = "SUCCESS " 15 | fail = "FAIL " 16 | logger = Log() 17 | 18 | class Page(): 19 | """ 20 | 页面基础类,用于所有页面的继承 21 | 22 | """ 23 | ai_url = "" 24 | def __init__(self,selenium_driver,base_url = ai_url,parent = None): 25 | self.base_url = base_url 26 | self.driver = selenium_driver 27 | # self.timeout = 30 28 | self.parent = parent 29 | 30 | def my_print(self,msg): 31 | logger.info(msg) 32 | 33 | def fail_img(self): 34 | file_name = '%s.jpg' % time.strftime("%Y_%m_%d_%H_%M_%S") 35 | file_path = globalparam.eximg_path + "\\" + file_name 36 | self.driver.get_screenshot_as_file(file_path) 37 | 38 | def assert_img(self): 39 | file_name = 'assert(%s).jpg' % time.strftime("%Y_%m_%d_%H_%M_%S") 40 | file_path = globalparam.eximg_path + "\\" + file_name 41 | self.driver.get_screenshot_as_file(file_path) 42 | 43 | def select_browser(self,browser='chrome', remoteAddress=None): 44 | t1 = time.time() 45 | dc = {'platform': 'ANY', 'browserName': 'chrome', 'version': '', 'javascriptEnabled': True} 46 | dr = None 47 | if remoteAddress is None: 48 | if browser == "firefox" or browser == "ff": 49 | dr = webdriver.Firefox() 50 | elif browser == "chrome" or browser == "Chrome": 51 | dr = webdriver.Chrome() 52 | elif browser == "internet explorer" or browser == "ie": 53 | dr = webdriver.Ie() 54 | elif browser == "opera": 55 | dr = webdriver.Opera() 56 | elif browser == "phantomjs": 57 | dr = webdriver.PhantomJS() 58 | elif browser == "edge": 59 | dr = webdriver.Edge() 60 | else: 61 | if browser == "RChrome": 62 | dr = webdriver.Remote(command_executor='http://' + remoteAddress + '/wd/hub', 63 | desired_capabilities=dc) 64 | elif browser == "RIE": 65 | dc['browserName'] = 'internet explorer' 66 | dr = webdriver.Remote(command_executor='http://' + remoteAddress + '/wd/hub', 67 | desired_capabilities=dc) 68 | elif browser == "RFirefox": 69 | dc['browserName'] = 'firefox' 70 | dc['marionette'] = False 71 | dr = webdriver.Remote(command_executor='http://' + remoteAddress + '/wd/hub', 72 | desired_capabilities=dc) 73 | try: 74 | self.driver = dr 75 | self.my_print( 76 | "{0} Start a new browser: {1}, Spend {2} seconds".format(success, browser, time.time() - t1)) 77 | except Exception: 78 | raise NameError("Not found {0} browser,You can enter 'ie','ff'," 79 | "'chrome','RChrome','RIe' or 'RFirefox'.".format(browser)) 80 | 81 | def _open(self,url): 82 | url = self.base_url + url 83 | self.driver.get(url) 84 | # assert self.on_page(),"did not land on %s " % url 85 | 86 | def element_wait(self, css, secs=8): 87 | """ 88 | Waiting for an element to display. 89 | 90 | Usage: 91 | driver.element_wait("id->kw",10) 92 | """ 93 | # if "->" not in css: 94 | # raise NameError("Positioning syntax errors, lack of '->'.") 95 | 96 | # by = css.split("->")[0].strip() 97 | # value = css.split("->")[1].strip() 98 | by = css[0].strip() 99 | messages = 'Element: {0} not found in {1} seconds.'.format(css, secs) 100 | 101 | if by == "id": 102 | WebDriverWait(self.driver, secs, 0.5).until(EC.presence_of_element_located(css), messages) 103 | elif by == "name": 104 | WebDriverWait(self.driver, secs, 0.5).until(EC.presence_of_element_located(css), messages) 105 | elif by == "class name": 106 | WebDriverWait(self.driver, secs, 0.5).until(EC.presence_of_element_located(css), messages) 107 | elif by == "link text": 108 | WebDriverWait(self.driver, secs, 0.5).until(EC.presence_of_element_located(css), messages) 109 | elif by == "xpath": 110 | WebDriverWait(self.driver, secs, 0.5).until(EC.presence_of_element_located(css), messages) 111 | elif by == "css selector": 112 | WebDriverWait(self.driver, secs, 0.5).until(EC.presence_of_element_located(css), messages) 113 | else: 114 | raise NameError("Please enter the correct targeting elements,'id','name','class','link_text','xpath','css'.") 115 | 116 | def get_element(self, css): 117 | """ 118 | Judge element positioning way, and returns the element. 119 | 120 | Usage: 121 | driver.get_element('id->kw') 122 | """ 123 | # if "->" not in css: 124 | # raise NameError("Positioning syntax errors, lack of '->'.") 125 | 126 | # by = css.split("->")[0].strip() 127 | # value = css.split("->")[1].strip() 128 | by = css[0].strip() 129 | value = css[1].strip() 130 | if by == "id": 131 | element = self.driver.find_element(by,value) 132 | elif by == "name": 133 | element = self.driver.find_element(by,value) 134 | elif by == "class name": 135 | element = self.driver.find_element(by,value) 136 | elif by == "link text": 137 | element = self.driver.find_element(by,value) 138 | elif by == "xpath": 139 | element = self.driver.find_element(by,value) 140 | elif by == "css selector": 141 | element = self.driver.find_element(by,value) 142 | else: 143 | raise NameError("Please enter the correct targeting elements,'id','name','class','link_text','xpath','css'.") 144 | return element 145 | 146 | def open(self): 147 | """ 148 | open url. 149 | Usage: 150 | driver.open("http://www.fengsulian.com") 151 | """ 152 | t1 = time.time() 153 | nowTime = time.strftime("%Y_%m_%d_%H_%M_%S") 154 | file_name = 'open->%s.jpg' % nowTime 155 | file_path = globalparam.eximg_path + "\\" + file_name 156 | try: 157 | self._open(self.url) 158 | self.my_print("{0} Navigated to {1}, Spend {2} seconds".format(success,self.base_url+self.url,time.time()-t1)) 159 | except Exception: 160 | self.my_print("{0} Unable to load {1}, Spend {2} seconds".format(fail,self.base_url+self.url,time.time()- t1)) 161 | self.fail_img() 162 | raise 163 | 164 | def on_page(self): 165 | return self.driver.current_url == (self.base_url + self.url) 166 | 167 | def max_window(self): 168 | """ 169 | set browser window maximized. 170 | """ 171 | t1 = time.time() 172 | self.driver.maximize_window() 173 | self.my_print("{0} Set browser window maximized, Spend {1} seconds".format(success, time.time() - t1)) 174 | 175 | def set_window(self, wide, high): 176 | """ 177 | Set browser window wide and high. 178 | 179 | Usage: 180 | driver.set_window(wide,high) 181 | """ 182 | t1 = time.time() 183 | self.driver.set_window_size(wide, high) 184 | self.my_print("{0} Set browser window wide: {1},high: {2}, Spend {3} seconds".format(success, 185 | wide,high,time.time() - t1)) 186 | 187 | def type(self, css, text): 188 | """ 189 | Operation input box. 190 | 191 | Usage: 192 | driver.type("id->kw","selenium") 193 | """ 194 | t1 = time.time() 195 | css1 = css[0] + "->" + css[1] 196 | base_dir = print(os.path.dirname(os.path.abspath(__file__))) 197 | try: 198 | self.element_wait(css) 199 | el = self.get_element(css) 200 | el.send_keys(text) 201 | self.my_print("{0} Typed element: <{1}> content: {2}, Spend {3} seconds -- from{4}".format(success, 202 | css1,text,time.time() - t1,base_dir)) 203 | except Exception: 204 | self.my_print("{0} Unable to type element: <{1}> content: {2}, Spend {3} seconds-- from{4}".format(fail, 205 | css1, text, time.time() - t1,base_dir)) 206 | self.fail_img() 207 | raise 208 | 209 | def clear_type(self, css, text): 210 | """ 211 | Clear and input element. 212 | 213 | Usage: 214 | driver.clear_type("id->kw","selenium") 215 | """ 216 | t1 = time.time() 217 | css1 = css[0] + "->" + css[1] 218 | try: 219 | self.element_wait(css) 220 | el = self.get_element(css) 221 | el.clear() 222 | el.send_keys(text) 223 | self.my_print("{0} Clear and type element: <{1}> content: {2}, Spend {3} seconds".format(success, 224 | css1, text,time.time() - t1)) 225 | except Exception: 226 | self.my_print("{0} Unable to clear and type element: <{1}> content: {2}, Spend {3} seconds".format(fail, 227 | css1, text,time.time() - t1)) 228 | self.fail_img() 229 | raise 230 | 231 | def click(self, css): 232 | """ 233 | It can click any text / image can be clicked 234 | Connection, check box, radio buttons, and even drop-down box etc.. 235 | 236 | Usage: 237 | driver.click("id->kw") 238 | """ 239 | t1 = time.time() 240 | css1 = css[0] + "->" + css[1] 241 | 242 | 243 | try: 244 | self.element_wait(css) 245 | el = self.get_element(css) 246 | el.click() 247 | self.my_print("{0} Clicked element: <{1}>, Spend {2} seconds".format(success,css1,time.time() - t1)) 248 | except Exception: 249 | self.my_print("{0} Unable to click element: <{1}>, Spend {2} seconds".format(fail, css1, time.time() - t1)) 250 | self.fail_img() 251 | raise 252 | 253 | def right_click(self, css): 254 | """ 255 | Right click element. 256 | 257 | Usage: 258 | driver.right_click("id->kw") 259 | """ 260 | t1 = time.time() 261 | css1 = css[0] + "->" + css[1] 262 | try: 263 | self.element_wait(css) 264 | el = self.get_element(css) 265 | ActionChains(self.driver).context_click(el).perform() 266 | self.my_print("{0} Right click element: <{1}>, Spend {2} seconds".format(success, css1, time.time() - t1)) 267 | except Exception: 268 | self.my_print("{0} Unable to right click element: <{1}>, Spend {2} seconds".format(fail, css1, time.time() - t1)) 269 | self.fail_img() 270 | raise 271 | 272 | def move_to_element(self, css): 273 | """ 274 | Mouse over the element. 275 | 276 | Usage: 277 | driver.move_to_element("id->kw") 278 | """ 279 | t1 = time.time() 280 | css1 = css[0] + "->" + css[1] 281 | try: 282 | self.element_wait(css) 283 | el = self.get_element(css) 284 | ActionChains(self.driver).move_to_element(el).perform() 285 | self.my_print("{0} Move to element: <{1}>, Spend {2} seconds".format(success, css1, time.time() - t1)) 286 | except Exception: 287 | self.my_print("{0} unable move to element: <{1}>, Spend {2} seconds".format(fail, css1, time.time() - t1)) 288 | self.fail_img() 289 | raise 290 | 291 | def double_click(self, css): 292 | """ 293 | Double click element. 294 | 295 | Usage: 296 | driver.double_click("id->kw") 297 | """ 298 | t1 = time.time() 299 | css1 = css[0] + "->" + css[1] 300 | try: 301 | self.element_wait(css) 302 | el = self.get_element(css) 303 | ActionChains(self.driver).double_click(el).perform() 304 | self.my_print("{0} Double click element: <{1}>, Spend {2} seconds".format(success, css1, time.time() - t1)) 305 | except Exception: 306 | self.my_print("{0} Unable to double click element: <{1}>, Spend {2} seconds".format(fail, css1, time.time() - t1)) 307 | self.fail_img() 308 | raise 309 | 310 | def drag_and_drop(self, el_css, ta_css): 311 | """ 312 | Drags an element a certain distance and then drops it. 313 | 314 | Usage: 315 | driver.drag_and_drop("id->kw","id->su") 316 | """ 317 | t1 = time.time() 318 | try: 319 | self.element_wait(el_css) 320 | element = self.get_element(el_css) 321 | self.element_wait(ta_css) 322 | target = self.get_element(ta_css) 323 | ActionChains(self.driver).drag_and_drop(element, target).perform() 324 | self.my_print("{0} Drag and drop element: <{1}> to element: <{2}>, Spend {3} seconds".format(success, 325 | el_css,ta_css, time.time() - t1)) 326 | except Exception: 327 | self.my_print("{0} Unable to drag and drop element: <{1}> to element: <{2}>, Spend {3} seconds".format(fail, 328 | el_css, ta_css, time.time() - t1)) 329 | self.fail_img() 330 | raise 331 | 332 | def click_text(self, text): 333 | """ 334 | Click the element by the link text 335 | 336 | Usage: 337 | driver.click_text("新闻") 338 | """ 339 | t1 = time.time() 340 | try: 341 | self.driver.find_element_by_partial_link_text(text).click() 342 | self.my_print("{0} Click by text content: {1}, Spend {2} seconds".format(success, text,time.time() - t1)) 343 | except Exception: 344 | self.my_print("{0} Unable to Click by text content: {1}, Spend {2} seconds".format(fail, text, time.time() - t1)) 345 | self.fail_img() 346 | raise 347 | 348 | def close(self): 349 | """ 350 | Simulates the user clicking the "close" button in the titlebar of a popup 351 | window or tab. 352 | 353 | Usage: 354 | driver.close() 355 | """ 356 | t1 = time.time() 357 | self.driver.close() 358 | self.my_print("{0} Closed current window, Spend {1} seconds".format(success, time.time() - t1)) 359 | 360 | def quit(self): 361 | """ 362 | Quit the driver and close all the windows. 363 | 364 | Usage: 365 | driver.quit() 366 | """ 367 | t1 = time.time() 368 | self.driver.quit() 369 | self.my_print("{0} Closed all window and quit the driver, Spend {1} seconds".format(success, time.time() - t1)) 370 | 371 | def submit(self, css): 372 | """ 373 | Submit the specified form. 374 | 375 | Usage: 376 | driver.submit("id->kw") 377 | """ 378 | t1 = time.time() 379 | css1 = css[0] + "->" + css[1] 380 | try: 381 | self.element_wait(css) 382 | el = self.get_element(css) 383 | el.submit() 384 | self.my_print("{0} Submit form args element: <{1}>, Spend {2} seconds".format(success,css1, time.time() - t1)) 385 | except Exception: 386 | self.my_print("{0} Unable to submit form args element: <{1}>, Spend {2} seconds".format(fail, css1, time.time() - t1)) 387 | self.fail_img() 388 | raise 389 | 390 | def F5(self): 391 | """ 392 | Refresh the current page. 393 | 394 | Usage: 395 | driver.F5() 396 | """ 397 | t1 = time 398 | self.driver.refresh() 399 | self.my_print("{0} Refresh the current page, Spend {1} seconds".format(success, time.time() - t1)) 400 | 401 | def js(self, script): 402 | """ 403 | Execute JavaScript scripts. 404 | 405 | Usage: 406 | driver.js("window.scrollTo(200,1000);") 407 | """ 408 | t1 = time.time() 409 | try: 410 | self.driver.execute_script(script) 411 | self.my_print("{0} Execute javascript scripts: {1}, Spend {2} seconds".format(success,script, time.time() - t1)) 412 | except Exception: 413 | self.my_print("{0} Unable to execute javascript scripts: {1}, Spend {2} seconds".format(fail, 414 | script, time.time() - t1)) 415 | self.fail_img() 416 | raise 417 | 418 | def get_attribute(self, css, attribute): 419 | """ 420 | Gets the value of an element attribute. 421 | 422 | Usage: 423 | driver.get_attribute("id->su","href") 424 | """ 425 | t1 = time.time() 426 | try: 427 | el = self.get_element(css) 428 | attr = el.get_attribute(attribute) 429 | self.my_print("{0} Get attribute element: <{1}>,attribute: {2}, Spend {3} seconds".format(success, 430 | css,attribute,time.time()-t1)) 431 | return attr 432 | except Exception: 433 | self.my_print("{0} Unable to get attribute element: <{1}>,attribute: {2}, Spend {3} seconds".format(fail, 434 | css, attribute,time.time() - t1)) 435 | self.fail_img() 436 | raise 437 | 438 | def get_text(self, css): 439 | """ 440 | Get element text information. 441 | 442 | Usage: 443 | driver.get_text("id->kw") 444 | """ 445 | t1 = time.time() 446 | css1 = css[0] + "->" + css[1] 447 | try: 448 | self.element_wait(css) 449 | text = self.get_element(css).text 450 | self.my_print("{0} Get element text element: <{1}>, Spend {2} seconds".format(success,css1,time.time()-t1)) 451 | return text 452 | except Exception: 453 | self.my_print("{0} Unable to get element text element: <{1}>, Spend {2} seconds".format(fail, css1, time.time() - t1)) 454 | self.fail_img() 455 | raise 456 | 457 | def get_title(self): 458 | """ 459 | Get window title. 460 | 461 | Usage: 462 | driver.get_title() 463 | """ 464 | 465 | t1 = time.time() 466 | title = self.driver.title 467 | self.my_print("{0} Get current window title, Spend {1} seconds".format(success, time.time() - t1)) 468 | return title 469 | 470 | def get_url(self): 471 | """ 472 | Get the URL address of the current page. 473 | 474 | Usage: 475 | driver.get_url() 476 | """ 477 | t1 = time.time() 478 | url = self.driver.current_url 479 | self.my_print("{0} Get current window url, Spend {1} seconds".format(success, time.time() - t1)) 480 | return url 481 | 482 | def wait(self, secs): 483 | """ 484 | Implicitly wait.All elements on the page. 485 | 486 | Usage: 487 | driver.wait(10) 488 | """ 489 | t1 = time.time() 490 | self.driver.implicitly_wait(secs) 491 | self.my_print("{0} Set wait all element display in {1} seconds, Spend {2} seconds".format(success, 492 | secs,time.time() - t1)) 493 | 494 | def accept_alert(self): 495 | """ 496 | Accept warning box. 497 | 498 | Usage: 499 | driver.accept_alert() 500 | """ 501 | t1 = time.time() 502 | self.driver.switch_to.alert.accept() 503 | self.my_print("{0} Accept warning box, Spend {1} seconds".format(success, time.time() - t1)) 504 | 505 | def dismiss_alert(self): 506 | """ 507 | Dismisses the alert available. 508 | 509 | Usage: 510 | driver.dismiss_alert() 511 | """ 512 | t1 = time.time() 513 | self.driver.switch_to.alert.dismiss() 514 | self.my_print("{0} Dismisses the alert available, Spend {1} seconds".format(success, time.time() - t1)) 515 | 516 | def switch_to_frame(self, css): 517 | """ 518 | Switch to the specified frame. 519 | 520 | Usage: 521 | driver.switch_to_frame("id->kw") 522 | """ 523 | t1 = time.time() 524 | css1 = css[0] + "->" + css[1] 525 | try: 526 | self.element_wait(css) 527 | iframe_el = self.get_element(css) 528 | self.driver.switch_to.frame(iframe_el) 529 | self.my_print("{0} Switch to frame element: <{1}>, Spend {2} seconds".format(success,css1, time.time() - t1)) 530 | except Exception: 531 | self.my_print("{0} Unable switch to frame element: <{1}>, Spend {2} seconds".format(fail, css1, time.time() - t1)) 532 | self.fail_img() 533 | raise 534 | 535 | def switch_to_frame_out(self): 536 | """ 537 | Returns the current form machine form at the next higher level. 538 | Corresponding relationship with switch_to_frame () method. 539 | 540 | Usage: 541 | driver.switch_to_frame_out() 542 | """ 543 | t1 = time.time() 544 | self.driver.switch_to.default_content() 545 | self.my_print("{0} Switch to frame out, Spend {1} seconds".format(success, time.time() - t1)) 546 | 547 | def open_new_window(self, css): 548 | """ 549 | Open the new window and switch the handle to the newly opened window. 550 | 551 | Usage: 552 | driver.open_new_window("id->kw") 553 | """ 554 | t1 = time.time() 555 | css1 = css[0] + "->" + css[1] 556 | try: 557 | original_windows = self.driver.current_window_handle 558 | el = self.get_element(css) 559 | el.click() 560 | all_handles = self.driver.window_handles 561 | for handle in all_handles: 562 | if handle != original_windows: 563 | self.driver.switch_to.window(handle) 564 | self.my_print("{0} Click element: <{1}> open a new window and swich into, Spend {2} seconds".format(success, 565 | css1,time.time() - t1)) 566 | except Exception: 567 | self.my_print("{0} Click element: <{1}> open a new window and swich into, Spend {2} seconds".format(fail, 568 | css1,time.time() - t1)) 569 | self.fail_img() 570 | raise 571 | 572 | def element_exist(self, css): 573 | """ 574 | judge element is exist,The return result is true or false. 575 | 576 | Usage: 577 | driver.element_exist("id->kw") 578 | """ 579 | t1 = time.time() 580 | css1 = css[0] + "->" + css[1] 581 | try: 582 | self.element_wait(css) 583 | self.my_print("{0} Element: <{1}> is exist, Spend {2} seconds".format(success,css1, time.time() - t1)) 584 | return True 585 | except TimeoutException: 586 | self.my_print("{0} Element: <{1}> is not exist, Spend {2} seconds".format(fail, css1, time.time() - t1)) 587 | self.fail_img() 588 | return False 589 | 590 | def take_screenshot(self, file_path): 591 | """ 592 | Get the current window screenshot. 593 | 594 | Usage: 595 | driver.take_screenshot('c:/test.png') 596 | """ 597 | t1 = time.time() 598 | try: 599 | self.driver.get_screenshot_as_file(file_path) 600 | self.my_print("{0} Get the current window screenshot,path: {1}, Spend {2} seconds".format(success, 601 | file_path, time.time() - t1)) 602 | except Exception: 603 | self.my_print("{0} Unable to get the current window screenshot,path: {1}, Spend {2} seconds".format(fail, 604 | file_path,time.time() - t1)) 605 | self.fail_img() 606 | raise 607 | 608 | def into_new_window(self): 609 | """ 610 | Into the new window. 611 | 612 | Usage: 613 | dirver.into_new_window() 614 | """ 615 | t1 = time.time() 616 | try: 617 | all_handle = self.driver.window_handles 618 | flag = 0 619 | while len(all_handle) < 2: 620 | time.sleep(1) 621 | all_handle = self.driver.window_handles 622 | flag += 1 623 | if flag == 5: 624 | break 625 | self.driver.switch_to.window(all_handle[-1]) 626 | self.my_print("{0} Switch to the new window,new window's url: {1}, Spend {2} seconds".format(success, 627 | self.driver.current_url,time.time() - t1)) 628 | except Exception: 629 | self.my_print("{0} Unable switch to the new window, Spend {1} seconds".format(fail, time.time() - t1)) 630 | self.fail_img() 631 | raise 632 | 633 | def type_and_enter(self, css, text, secs=0.5): 634 | """ 635 | Operation input box. 1、input message,sleep 0.5s;2、input ENTER. 636 | 637 | Usage: 638 | driver.type_css_keys('id->kw','beck') 639 | """ 640 | t1 = time.time() 641 | css1 = css[0] + "->" + css[1] 642 | try: 643 | self.element_wait(css) 644 | ele = self.get_element(css) 645 | ele.send_keys(text) 646 | time.sleep(secs) 647 | ele.send_keys(Keys.ENTER) 648 | self.my_print("{0} Element <{1}> type content: {2},and sleep {3} seconds,input ENTER key, Spend {4} seconds".format( 649 | success,css1,text,secs,time.time() - t1)) 650 | except Exception: 651 | self.my_print("{0} Unable element <{1}> type content: {2},and sleep {3} seconds,input ENTER key, Spend {4} seconds". 652 | format(fail, css1, text, secs, time.time() - t1)) 653 | self.fail_img() 654 | raise 655 | 656 | def js_click(self, css): 657 | """ 658 | Input a css selecter,use javascript click element. 659 | 660 | Usage: 661 | driver.js_click('#buttonid') 662 | """ 663 | t1 = time.time() 664 | js_str = "$('{0}').click()".format(css) 665 | try: 666 | self.driver.execute_script(js_str) 667 | self.my_print("{0} Use javascript click element: {1}, Spend {2} seconds".format(success,js_str,time.time()-t1)) 668 | except Exception: 669 | self.my_print("{0} Unable to use javascript click element: {1}, Spend {2} seconds".format(fail, 670 | js_str, time.time() - t1)) 671 | self.fail_img() 672 | raise 673 | 674 | def scroll_bar(self,horizontal,vertical): 675 | """ 676 | Control scrollbar 677 | """ 678 | return self.driver.execute_script(self.window.scrollTo(horizontal,vertical)) 679 | 680 | 681 | def find_elements(self,*loc): 682 | try: 683 | if len(self.driver.find_elements(*loc)): 684 | return self.driver.find_elements(*loc) 685 | except: 686 | print("%s cannot find elements %s in page." % (self,loc)) 687 | 688 | def is_text_in_element(self, locator, text, timeout=10): 689 | """ 690 | 判断文本在元素里,没定位到元素返回False,定位到返回判断结果布尔值 691 | Usage: 692 | result = driver.text_in_element(locator, text) 693 | """ 694 | t1 = time.time() 695 | locator1 = locator[0] + "->" + locator[1] 696 | try: 697 | result = WebDriverWait(self.driver, timeout, 0.5).until(EC.text_to_be_present_in_element(locator, text)) 698 | except TimeoutException: 699 | self.my_print("{0} element not positioned: <{1}> , Spend {2} seconds".format(fail, 700 | locator1, time.time() - t1)) 701 | self.fail_img() 702 | return False 703 | else: 704 | self.my_print("{0} positioned to element: <{1}> , Spend {2} seconds".format(success, 705 | locator1, time.time() - t1)) 706 | return result 707 | 708 | def is_text_in_value(self, locator, value, timeout=10): 709 | """ 710 | 判断元素的value值,没定位到元素返回false,定位到返回判断结果布尔值 711 | Usage: 712 | result = driver.text_in_element(locator, text) 713 | """ 714 | t1 = time.time() 715 | locator1 = locator[0] + "->" + locator[1] 716 | try: 717 | result = WebDriverWait(self.driver, timeout, 0.5).until(EC.text_to_be_present_in_element_value(locator, 718 | value)) 719 | except TimeoutException: 720 | self.my_print("{0} element not positioned: <{1}> , Spend {2} seconds".format(fail, 721 | locator1, time.time() - t1)) 722 | self.fail_img() 723 | return False 724 | else: 725 | self.my_print("{0} positioned to element: <{1}> , Spend {2} seconds".format(success, 726 | locator1, time.time() - t1)) 727 | return result 728 | 729 | def assert_equal(self,loc,text): 730 | """ 731 | say with certainty 732 | 733 | Usage: 734 | assertNotEqual(loc,text) 735 | """ 736 | t1 = time.time() 737 | try: 738 | self.assertEqual(loc,text) 739 | self.my_print("{0} say with certainty: {1} == {2}, Spend {3} seconds".format(success,loc, 740 | text,time.time()-t1)) 741 | except Exception: 742 | self.my_print("{0} say with certainty: {1} != {2}, Spend {3} seconds".format(fail, loc, 743 | text, time.time() - t1)) 744 | self.assert_img() 745 | raise 746 | 747 | def assert_notequal(self, loc, text): 748 | """ 749 | say with certainty 750 | 751 | Usage: 752 | assertEqual(loc,text) 753 | """ 754 | t1 = time.time() 755 | try: 756 | self.assertNotEqual(loc, text) 757 | self.my_print("{0} say with certainty: {1} != {2}, Spend {3} seconds".format(success, loc, 758 | text, time.time() - t1)) 759 | except: 760 | self.my_print("{0} say with certainty: {1} == {2}, Spend {3} seconds".format(fail, loc, 761 | text, time.time() - t1)) 762 | self.assert_img() 763 | raise 764 | 765 | def js1(self,css): 766 | """ 767 | Handle the target property as empty 768 | 769 | """ 770 | css1 = css[0].capitalize() 771 | css2 = css[1] 772 | css3 = css[0] + "->" + css[1] 773 | t1 = time.time() 774 | try: 775 | ele = "document.getElementBy{0}({1}).target=' ';" .format(css1, css2) 776 | self.driver.execute_script(ele) 777 | except: 778 | self.my_print("{0} positioned to element: <{1}> , Spend {2} seconds".format(success, 779 | css3, time.time() - t1)) --------------------------------------------------------------------------------