用例结构
用例结构从上到下为用例套件部分TestSuite -> 用例执行的动作action -> 页面实际操作PageObject
关于WebView
测试WebApp有时无法通过直接定位并操作原生控件来完成测试,此时就需要操作WebView来直接在Web页面上进行定位。WebView操作需要依赖于与当前测试手机WebView相同版本的Chromedriver。Webdriver的具体操作在Public -> chromedriver 目录中完成,感兴趣的可以研究一下。
在测试用例中需要用到Webdriver测试时,通过调用如图所示代码来进行Webdriver的设置与回收,并将生成的driver传递给所需的函数/方法。
操作时直接使用生成的selenium.webdriver调用selenium的web元素定位方法定位元素即可,如图所示。
运行流程
1. 通过run_cases .py或者run_all_cases.py开始执行测试
if __name__ == '__main__': # back up old report dir 备份旧的测试报告文件夹到TestReport_backup下 backup_report() cs = CaseStrategy() cases = cs.collect_cases(suite=False) Drivers().run(cases) # Generate zip_report file 压缩测试报告文件 # zip_report() |
1)首先会将Testreport目录剪切到TestReport_backup目录下,备份旧的测试报告。
2)通过CaseStrategy获取到需要执行的测试用例。
3)Drivers().run(cases)开始执行测试。
2. run(cases)执行测试
def run(self, cases): # 根据method 获取android设备 method = ReadConfig().get_method().strip() if method == 'SERVER': # get ATX-Server Online devices # devices = ATX_Server(ReadConfig().get_server_url()).online_devices() print('Checking available online devices from ATX-Server...') devices = get_online_devices() print('\nThere has %s online devices in ATX-Server' % len(devices)) elif method == 'IP': # get devices from config devices list print('Checking available IP devices from config... ') devices = get_devices() print('\nThere has %s devices alive in config IP list' % len(devices)) elif method == 'USB': # get devices connected PC with USB print('Checking available USB devices connected on PC... ') devices = connect_devices() print('\nThere has %s USB devices alive ' % len(devices)) else: raise Exception('Config.ini method illegal:method =%s' % method) if not devices: print('There is no device found,test over.') return # generate test data data.json 准备测试数据 generate_test_data(devices) print('Starting Run test >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>') runs = [] for i in range(len(devices)): runs.append(RunCases(devices[i])) # run on every device 开始执行测试 pool = Pool(processes=len(runs)) for run in runs: pool.apply_async(self._run_cases, args=(run, cases,)) print('Waiting for all runs done........ ') pool.close() pool.join() print('All runs done........ ') ChromeDriver.kill() # Generate statistics report 生成统计测试报告 将所有设备的报告在一个HTML中展示 create_statistics_report(runs) |
1)首先根据config.ini中method的值来判断从atx-serve获取online的设备 还是从config.ini中的ip来获取在线的设备。
2)在获取到设备之后,根据设备生产data.json测试数据。
3)并行多设备执行测试。
4)测试完之后,杀掉执行过程中打开的所有的chromedriver进程。
5)最后在TestReport下生成统计测试报告(自动化测试报告.html)。
结果展示
生成的测试报告路径结构如下:
每个设备的测试结果及报告或存放在单独的文件夹下。
在TestReport_History目录下会有一个统计测试报告(自动化测试报告.html)会将所有设备的报告统一在一个页面展示。
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系51Testing小编(021-64471599-8017),我们将立即处理