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深似海

    从此偷懒成路人

    好好学习吧,骚年

  • 相关阅读:
    “图”以致用组
    水体频率小组
    2021年云开发组三等奖作品展示
    毫秒级百万数据分页存储过程[欢迎转载]
    SQL Server 数据备份存储过程[原创]
    博客园居然被中国电信提醒有病毒,有图为证
    网络文件夹例子
    小技巧:在DropDownList数据绑定前插入固定文字
    ASP.NET整合Discuz!NT3.5实例说明(含用户登录、评论等)
    Visual Studio 2008的性能改进以及十大新功能(转)
  • 原文地址:https://www.cnblogs.com/hanxiaobei/p/13872300.html
Copyright © 2011-2022 走看看