前面文章已经讲解了什么是pytest,关于selenium相信大家也不陌生,下面我们就首先来了解一些Allure。
1. 什么是allure?
Allure是由Qameta Software团队开源的一款旨在于解决让每个人能更容易生成并更简洁阅读的测试报告框架。它支持大多数的测试框架,如:Pytest、TestNG等,简单易用便于集成。
2. allure特点
- 开源
- 轻量级,灵活,易于集成
- 支持多语言
- 支持多平台
- 报告丰富详尽奢华,包括测试功能,测试故事,测试步骤,测试日志
- 有各种统计报表
- java语言开发的,支持TestNG、Pytest、JUint,JavaS,PHP,ruby等
3. Allure环境搭建
- pip3 install pytest
- pip3 install allure-pytest
- 下载 allure 包 download from docs.qameta.io/allure/
3.1 pip3 install allure-pytest
3.1 下载 allure
- download from docs.qameta.io/allure/
3.3 添加环境变化
4. 写python脚本
from allure_commons.types import AttachmentType
from selenium import webdriver
from selenium.webdriver.common.by import By
import allure
import pytest
import allure_pytest
@allure.severity(allure.severity_level.MINOR)
def test_news_display():
chrome_driver = 'D:/Tools/chromedriver.exe'
driver = webdriver.Chrome(executable_path=chrome_driver)
driver.get("https://www.baidu.com/")
status = driver.find_element_by_link_text('新闻').is_displayed()
if status == True:
assert True
else:
assert False
driver.close()
@allure.severity(allure.severity_level.CRITICAL)
def test_search_display():
chrome_driver = 'D:/Tools/chromedriver.exe'
driver = webdriver.Chrome(executable_path=chrome_driver)
driver.get("https://www.baidu.com/")
status = driver.find_element(By.ID, 'kw').is_displayed()
if status == True:
assert True
else:
assert False
driver.close()
@allure.severity(allure.severity_level.NORMAL)
def test_search_steps():
chrome_driver = 'D:/Tools/chromedriver.exe'
driver = webdriver.Chrome(executable_path=chrome_driver)
driver.get("https://www.baidu.com/")
driver.find_element(By.ID, 'kw').send_keys('selemium')
if driver.find_element(By.ID, 'kw').is_displayed() == True:
assert True
else:
allure.attach(driver.get_screenshot_as_png(),name="a",attachment_type=AttachmentType.PNG)
assert False
driver.find_element(By.ID, 'su').click()
driver.implicitly_wait(2)
driver.close()
@allure.severity(allure.severity_level.BLOCKER)
def test_search_result():
pytest.skip("Skipping test..later I will implement it")
5 创建report目录
6. 执行脚本
pytest -v -s --alluredir="D:\pythonProject1\report" test_selenium.py
7. 产生的报告文件
8. 生产报告
allure serve D:\pythonProject1\report