*********************************************************************************【browser.py】简化浏览器
import os
from selenium import webdriver
def get_chrome():
driver_path = os.path.dirname(__file__)+'/../webdriver/chromedriver'
driver = webdriver.Chrome(executable_path=driver_path)
return driver
**********************************************************************************【comfig.py】简化地址
class config:
@property
def URL(self):
return 'https://qa-.vip/'
@property
def RORT(self):
return 80
local_config = config()
if __name__=='__main__':
print(local_config.URL)
***********************************************************************************【system_function.py】简化登录
def login(driver,username,password):
driver.find_element_by_xpath('//input[@type="text"]').send_keys('luoguo')
driver.find_element_by_xpath('//input[@type="password"]').send_keys('1234')
driver.find_element_by_xpath('//button[@class="login-btn ant-btn ant-btn-primary ant-btn-lg"]').click()
def exit(driver):
pass
****************************************************************************************【test_login_sucess.py】登录用例
import os,time
import unittest
from selenium import webdriver
from common import browser
from common.comfig import local_config
from common import system_function
class TestLoginsucess(unittest.TestCase):
def setUp(self) -> None:
# driver_path = os.path.dirname(__file__)+'/../../webdriver/chromedriver.exe'
# self.driver=webdriver.Chrome(executable_path=driver_path)
self.driver = browser.get_chrome()
self.driver.maximize_window()
self.driver.implicitly_wait(10)
def tearDown(self) -> None:
time.sleep(2)
self.driver.quit()
def test_login(self):
self._testMethodName = "jy-dl-01"
self._testMethodDoc = '教研系统输入用户名,输入密码'
self.driver.get(local_config.URL)
system_function.login(self.driver,"luong",'128')
# self.driver.find_element_by_xpath('//input[@type="text"]').send_keys('luong')
# self.driver.find_element_by_xpath('//input[@type="password"]').send_keys('128')
# self.driver.find_element_by_xpath('//button[@class="login-btn ant-btn ant-btn-primary ant-btn-lg"]').click()
actual__result=self.driver.find_element_by_xpath('//span[@class="title"]').text
self.assertEqual(actual__result,'桌面')
if __name__=='__main__':
unittest.main()
********************************************************************【run__all__cases.py】全局自动化脚本
import os
import unittest
from common import HTMLTestReportCN
case_path = os.path.dirname(__file__)+'/testcases'
discover=unittest.defaultTestLoader.discover(
start_dir=case_path,
pattern='test_*.py',
top_level_dir=case_path
)
all_case_suit=unittest.TestSuite()
all_case_suit.addTest(discover)
report_path = os.path.dirname(__file__)+'/reports'
report_dir = HTMLTestReportCN.ReportDirectory(report_path)
report_dir.create_dir('教研系统自动化测试项目')
report_html_path=HTMLTestReportCN.GlobalMsg.get_value('report_path')
html_report_file = open(report_html_path,'wb')
test_runner = HTMLTestReportCN.HTMLTestRunner(stream=html_report_file,
title='教研系统自动化测试项目',
tester='罗sir')
test_runner.run(all_case_suit)
*******************************************************************************
UI自动化
1.安装python【注意问题:描述:进入pycharm.py中无法下载selenium解决方法:重新安装python,勾选【】add python to environment variables,添加python路径到环境变量。】
2.下载最新版谷歌浏览器,下载对应版本的webdriver【http://chromedriver.storage.googleapis.com/index.html】
3.进入python.py下载selenium
4.添加截图中模块,编写脚本,网上下载一个HTMLtestReprotCN.py(彩色版网页报告)