标签:dexp goto main file enabled gen mylog readlines LEDE
这里主要分享一下,如何让脚本运行起来,开始的时候,就是写了一个pytest.ini,然后在控制台输入pytest,就会直接跑脚本,后来又改了一下,直接写了一个bat文件,来运行脚本,下面主要说明一下bat文件怎么运行脚本。
首先有一个run.py文件,就是确定需要测试哪些case,以及生成报告的路径:
# encoding=utf-8 import os import pytest from util.log import MyLog from util.read_config import ReadConfig class RunAll: def __init__(self): self.rc = ReadConfig() self.pro_dir = self.rc.project_dir self.log = MyLog.get_log() self.logger = self.log.get_logger() self.report_xml_path = os.path.join(self.log.log_path, ‘report\\xml‘) self.case_list_file = os.path.join(self.pro_dir, "caselist.txt") self.case_list = [] def set_case_list(self): """将caselist.txt中的case名存到一个list,不包含以#开头的""" try: fb = open(self.case_list_file) except Exception as e: self.logger.error(str(e)) else: for value in fb.readlines(): data = str(value) + ‘.py‘ if data != ‘‘ and not data.startswith("#"): data = ‘./scripts/‘ + data self.case_list.append(data.replace(‘\n‘, ‘‘)) fb.close() # return self.case_list def run(self): logger = self.logger rerun = self.rc.get_test("reruns") try: self.set_case_list() print(self.case_list) if self.case_list is not None: # logger.info("************start appium server**************") # try: # os.system("start startAppiumServer.bat") # except Exception: # logger.error("启动appium服务失败") # time.sleep(15) logger.info("************test start**************") pytest_list = [‘-s‘, ‘-q‘] xml_dir = ‘--alluredir=‘ + self.report_xml_path reruns = ‘-reruns=‘ + rerun pytest_list.append(xml_dir) pytest_list.append(reruns) for case in self.case_list: pytest_list.append(case) pytest.main(pytest_list) else: logger.info("Have no case to test") except Exception as ex: logger.error(str(ex)) finally: logger.info("****************test end**********************") # os.system("start stopAppiumServer.bat") if __name__ == ‘__main__‘: test = RunAll() test.run()
caselist.txt:
test_index
#test_area
test_theme
#test_verify
接下来就是run.bat了:
就新建一个记事本文件,然后修改名字为run.bat就可以,内容如下,bat文件是先执行测试用例,
然后将测试用例下的xml报告转为html报告,放到result下面的以测试时间为文件夹名字的路径下
echo off
python run.py
setlocal enabledelayedexpansion
rem 设置文件所在目录
set src_dir=.\result
rem filename用于存放目标文件名
set filename=""
cd /d %src_dir%
for /f %%a in (‘dir /o-d /tc /b‘) do (
echo 文件完整信息: %%a
set filename=%%~na%%~xa
echo 文件名: !filename!, 最新创建时间: %%~ta
if not !filename! == "" (
goto allurecmd
)
)
:allurecmd
allure generate ./!filename!/report/xml -o ./!filename!/report/html
cmd
over...
标签:dexp goto main file enabled gen mylog readlines LEDE
原文地址:https://www.cnblogs.com/sy_test/p/13072951.html