一、整体思路
在实战1中我们设计了准备测试的功能测试场景,现在我们理一下自动化的思路。
1、功能测试的流程在pytest的测试用例中实现
2、不同的参数放在Excel表格中
3、采用参数化来实现数据驱动,这样就要求执行测试前将Excel中的数据生成python的列表,然后当参数传给测试用例
4、测试报告利用allure生成
5、元素定位、APP操作利用appium,并对操作进行封装,将数据当参数传入就实现APP的各种操作。
各个包的结构和介绍如下
架子搭起来后,后面我们结合前面app自动化测试的内容和pytest的内容,逐步完善起来,最后能得到一个可用的自动化测试框架
二、main入口代码示意
'''
LastEditTime: 2023-03-16 23:46:16
FilePath: \AutoTest\main.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
from common.ComLog import LOGGER
from base import BaseGenerateData
import pytest
import allure
import datetime
import os
from config import config
if __name__ == '__main__':
LOGGER.info("测试开始!")
if config.IsGenerateData:
# 生成数据
LOGGER.info("测试前生成测试数据")
#TODO
# 生成数据
pass
now = datetime.datetime.now()
time_str = now.strftime("%Y-%m-%d-%H%M%S")
#此处命令 --alluredir 生成了报告的原始文件
#执行冒烟测试用例
pytest.main(["-vs","testcase","-m smoke","--alluredir","./report/{}xml".format(time_str)])
#执行所有用例
#pytest.main(["-vs","testcase","--alluredir","./report/{}xml".format(time_str)])
#此处命令 allure generate 将起那么生成的json文件转换为html的报告
os.system("allure generate ./Report/{}xml -o ./Report/{}html --clean".format(time_str,time_str))
# 生成的报告index.html不能直接用Chrome打开,打开后看不到内容,需要用allure open打开才能渲染出样式和显示内容
os.system("allure open ./Report/{}html".format(time_str))