• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

武飞扬头像
全栈开发与测试
帮助1

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

  1.  
    from allure_commons.types import AttachmentType
  2.  
    from selenium import webdriver
  3.  
    from selenium.webdriver.common.by import By
  4.  
    import allure
  5.  
    import pytest
  6.  
    import allure_pytest
  7.  
     
  8.  
    @allure.severity(allure.severity_level.MINOR)
  9.  
    def test_news_display():
  10.  
    chrome_driver = 'D:/Tools/chromedriver.exe'
  11.  
    driver = webdriver.Chrome(executable_path=chrome_driver)
  12.  
    driver.get("https://www.百度.com/")
  13.  
    status = driver.find_element_by_link_text('新闻').is_displayed()
  14.  
    if status == True:
  15.  
    assert True
  16.  
    else:
  17.  
    assert False
  18.  
    driver.close()
  19.  
     
  20.  
    @allure.severity(allure.severity_level.CRITICAL)
  21.  
    def test_search_display():
  22.  
    chrome_driver = 'D:/Tools/chromedriver.exe'
  23.  
    driver = webdriver.Chrome(executable_path=chrome_driver)
  24.  
    driver.get("https://www.百度.com/")
  25.  
    status = driver.find_element(By.ID, 'kw').is_displayed()
  26.  
    if status == True:
  27.  
    assert True
  28.  
    else:
  29.  
    assert False
  30.  
    driver.close()
  31.  
     
  32.  
    @allure.severity(allure.severity_level.NORMAL)
  33.  
    def test_search_steps():
  34.  
    chrome_driver = 'D:/Tools/chromedriver.exe'
  35.  
    driver = webdriver.Chrome(executable_path=chrome_driver)
  36.  
    driver.get("https://www.百度.com/")
  37.  
    driver.find_element(By.ID, 'kw').send_keys('selemium')
  38.  
    if driver.find_element(By.ID, 'kw').is_displayed() == True:
  39.  
    assert True
  40.  
    else:
  41.  
    allure.attach(driver.get_screenshot_as_png(),name="a",attachment_type=AttachmentType.PNG)
  42.  
    assert False
  43.  
    driver.find_element(By.ID, 'su').click()
  44.  
    driver.implicitly_wait(2)
  45.  
    driver.close()
  46.  
     
  47.  
    @allure.severity(allure.severity_level.BLOCKER)
  48.  
    def test_search_result():
  49.  
    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.查看测试报告 

学新通学新通学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgcfacc
系列文章
更多 icon
同类精品
更多 icon
继续加载