领导跟你要测试报告 ,报告太丑拿不出手?

参考链接

allure 官网网址:http://allure.qatools.ru/

课程重点

参考代码

class TestBaidu:
    @allure.title("搜索词:{searchkey}")
    @pytest.mark.parametrize("searchkey", [
        "selenium", "appium", "requests", "httprunner"
    ])
    def test_search(self, searchkey):
        # 配置 chromdriver 的环境变量,选择对应版本的chromedriver
        driver = webdriver.Chrome()
        driver.get("https://www.baidu.com")
        # 找到搜索框,输入 搜索词
        driver.find_element(By.ID, "kw").send_keys(searchkey)
        # 找到搜索按钮,点击
        driver.find_element(By.ID, "su").click()
        sleep(1)
        img_file = "./imgs/result.png"
        driver.get_screenshot_as_file(img_file)
        allure.attach.file(img_file, name="截图", attachment_type=allure.attachment_type.PNG)
        driver.quit()