自动化测试框架系列-pytest,selenium, allure详细概述+实战

前面文章已经讲解了什么是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 

9.查看测试报告 

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

全栈开发与测试

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值