zoukankan      html  css  js  c++  java
  • pytest+allure+selenium网页自动化并生成图标报告

    一、前言

    pytest+allure+selenium是目前市面上应用比较广泛的前端自动化测试组合。

    二、目录结构

    ·report 生成html报告的目录

    ·result 执行allure生成的源文件

    ·screenshot 是截图后保存的目录

    ·data.yaml 存放的参数化的数据

    ·test_data.py 真正的执行程序

    三、代码示例

    data.yaml

    1 - allure
    2 - pytest
    3 - selenium

    test_data.py

     1 import allure
     2 from selenium import webdriver
     3 import pytest
     4 import yaml
     5 import time
     6 
     7 
     8 @allure.testcase('http://www.github.com')
     9 @allure.feature('百度搜索')
    10 @pytest.mark.parametrize('data', yaml.safe_load(open("data.yaml")))
    11 def test_steps_demo(data):
    12     with allure.step("打开百度首页"):
    13         driver = webdriver.Chrome()
    14         driver.get("http://www.baidu.com")
    15         driver.maximize_window()
    16 
    17     with allure.step(f"输入关键词:{data}"):
    18         driver.find_element_by_id('kw').send_keys(data)
    19         time.sleep(2)
    20         driver.find_element_by_id('su').click()
    21         time.sleep(2)
    22 
    23     with allure.step("保存图片"):
    24         driver.save_screenshot("./screenshot/"+data+".png")
    25         allure.attach.file("./screenshot/"+data+".png")
    26         attachment_type = allure.attachment_type.PNG
    27 
    28     with allure.step("关闭浏览器"):
    29         driver.quit()

    四、程序执行

    1、执行程序:

    1  pytest test_data.py -s -q --alluredir=./result/

    执行后可在result目录中生成原始的allure源文件

    2、生成html报告:

    1  allure generate ./result -o ./report --clean

    执行后可在report中生成可视化的html报告

    3、启动站点服务查看html报告(可步不是必须的,也可直接打开report目录中的index.html查看报告)

    1 allure open -h 127.0.0.1 -p 8883 ./report 

    五、后语

    是不是感觉高大上了?

    一入IT深似海

    从此偷懒成路人

    好好学习吧,骚年

  • 相关阅读:
    从 PHP 到 Java
    用Lua定制Redis命令
    见招拆招-PostgreSQL中文全文索引效率优化
    通过2-3-4树理解红黑树
    代码迁移之旅(二)- 渐进式迁移方案
    多线程编程
    Gotorch
    使用PostgreSQL进行中文全文检索
    代码重构之旅(一) 项目结构
    Linux“体检”指标
  • 原文地址:https://www.cnblogs.com/hanxiaobei/p/13872300.html
Copyright © 2011-2022 走看看