说明
之前分享过自己写的appium框架,有很多待优化的地方,先从selenium开始优化
功能
- yaml维护用例
- 支持多检查点
- excel记录报告,失败有截图展示
- 本地记录日志
- 参数化测试用例管理
用法
配置openurl.yaml
openurl: http://www....com/login
配置用例yaml
testinfo:
- id: 001
moudle: mok模块
intr: 个人
testcase:
- element_info: //*[@id="login"]/div[1]/div[2]/form/div[1]/input
find_type: by_xpath
operate_type: send_keys
text: test
- element_info: //*[@id="login"]/div[1]/div[2]/form/div[2]/input
find_type: by_xpath
operate_type: send_keys
text: 123456
- element_info: //*[@id="login"]/div[1]/div[2]/form/button[1]
find_type: by_xpath
operate_type: click
check:
- element_info: //*[@id="home"]/a
find_type: by_xpath
- element_info: //*[@id="setting111"]/a
find_type: by_xpath
用例管理
基本上是直接复制
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)
from testRunner.runnerBase import TestInterfaceCase
class testSetting(TestInterfaceCase):
def setUp(self, methodName=''):
super(testSetting, self).setUp()
self.bc = webCase.WebCaseBase(driver=self.driver, casename="testSetting")
def tearDown(self):
self.driver.quit()
pass
def test_setting(self):
self.bc.execCase(PATH("../yaml/setting.yaml"))
代码人口
def _report():
workbook = xlsxwriter.Workbook('report.xlsx')
worksheet = workbook.add_worksheet("测试总况")
worksheet2 = workbook.add_worksheet("测试详情")
re = report.OperateReport(wd=workbook)
re.init(worksheet, data=util.DATA)
re.test_detail(worksheet2, data=util.INFO)
re.close()
def runnerCaseWeb():
starttime = datetime.datetime.now()
suite = unittest.TestSuite()
suite.addTest(TestInterfaceCase.parametrize(testLogin)) # 引用测试用例类
suite.addTest(TestInterfaceCase.parametrize(testSetting))#引用测试用例类
unittest.TextTestRunner(verbosity=2).run(suite)
endtime = datetime.datetime.now()
util.DATA["sum_time"] = str((endtime - starttime).seconds) + "秒"
util.DATA["test_date"] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
if __name__ == '__main__':
runnerCaseWeb()
_report()
命名行运行:
pyhton testRunner/runner.py
测试报告
Paste_Image.png