执行和生成报告:
1)在main文件中加入如下代码:
1)在main文件中加入如下代码:
if __name__ == '__main__':
# 指定临时json文件生成位置
pytest.main(["./case/test_visit_url_screenshot.py",
"-sv", "--alluredir", "./report/temp_jsonreport"])
# 指定html报告生成位置,清理上次生成的报告
os.system("allure generate ./report/temp_jsonreport -o ./report/html --clean")
2)生成报告包含两个文件:
先生成temp_jsonreport,再生成html,用浏览器打开index.html即可
@allure.feature()、@allure.story()、@allure.title()、with allure.step 使用
使用举例1***:
1、把基础操作,写成函数放到action.py,方便重复调用
2、在测试用例里写清feature用例模块、story用例场景、title用例名称、用例步骤step,调用action里的函数即可
import allure
import logging
from utils.yaml_reader import *
from utils.path_dealer import *
from utils.url_dealer import *
from utils.action import *
from conf.conf import *
@allure.feature("模块")
class TestUrlScreenshot:
"""
Step1、input one URL
Step2、generate multi-language URL
Step3、visit URL, take screenshot
"""
@allure.story("生成指定多语言URL后访问")
def test_take_screenshot(self, driver):
url_list = read_yaml(data_folder, "url.yaml")
# logging.info("urls list: %s" % url_list)
language_dict = read_yaml(data_folder, "language.yaml")
if not language_dict:
language_dict = default_language_dict
# logging.info("language dict: %s" % language_dict)
task_name = read_yaml(data_folder, "other.yaml")["task_name"]
logging.info("task_name: %s" % task_name)
urls = gen_multi_language_url(language_dict=language_dict, url_list=url_list)
folder_path = gene_folder_path(task_name_pa=task_name)
# 设置访问