- 项目文件结构
common:
存放经常被引用的文件,如HTMLTestRunner
Locator:
存放页面元素的位置和对应url,如oper_userName = (By.ID, “username”)
pages:
对于网站有不同的页面,可分开写
reports:
存放测试生成的报告
screenshots:
存放测试中截屏的图片
每个用例都是一个class。拥有自己的浏览器启动函数。具体形式如下:
import sys
import time
import unittest
from selenium import webdriver
class TestCase1(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(getChromeDriver())
####中间插入该用例的其他函数
def tearDown(self):
self.driver.quit()
如果有很多个用例,则需要一个总函数来进行批量运行,并生成测试报告。单个运行太麻烦了。首先建立一个casesuit,在当前文件中进行查找对应的case。
import os,sys
import unittest
import time
import HtmlTestRunner
os_path = os.getcwd()
casesPath = os_path + "\\test_case"
reportPath = os_pat