1.test01.py 写第一个用例
from selenium import webdriver
import time
import unittest
class Case01(unittest.TestCase):
def test_case01(self):
path = ‘C:\Program Files\internet explorer\IEDriverServer.64.exe’
driver = webdriver.Ie(path)
driver.get(’***********’)
driver.quit()
2.test02.py 写第二个用例 文件名不一定要用test01 02但是函数名 一定要用test_case01 test_case02依此类推
from selenium import webdriver
import time
import unittest
class Case02(unittest.TestCase):
def test_case02(self):
path=‘C:\Program Files\internet explorer\IEDriverServer.64.exe’
driver =webdriver.Ie(path)
driver.get(‘’)
driver.find_element_by_id(‘userId’).send_keys('’)
driver.find_element_by_id(‘passWordPH’).send_keys(’***********’)
driver.find_element_by_id(‘mem_btn_login’).click()
driver.quit()
3.run.py 综合跑所有的用例–先将用例从文件中导入进来,再用suite组件执行用例,再用HTMLTestRunner生成测试报告 测试报告生成后,是在当前项目目录下
import HTMLTestRunner
import unittest
from uitest.test01 import Case01
from uitest.test02 import Case02
suite = unittest.TestSuite()
suite.addTest(Case01(‘test_case01’))
suite.addTest(Case02(‘test_case02’))
st = open(’./report.html’,‘wb’)
HTMLTestRunner.HTMLTestRunner(stream=st,title=u’ui自动化’).run(suite)