首页 > 其他分享 >pytest+selenium+allure

pytest+selenium+allure

时间:2023-04-15 10:57:16浏览次数:43  
标签:search allure -- selenium pytest pip 安装

 
您可以使用pip安装Selenium WebDriver:
``` pip install selenium ```
3. 安装pytest
您可以使用pip安装pytest:
``` pip install pytest ```
4. 安装pytest-xdist
pytest-xdist是一个pytest插件,用于并行运行测试。您可以使用以下命令安装:
``` pip install pytest-xdist ```
5. 安装pytest-rerunfailures
pytest-rerunfailures是一个pytest插件,用于运行失败的测试用例。您可以使用以下命令安装:
``` pip install pytest-rerunfailures ```
6. 安装pytest-html
pytest-html是一个pytest插件,用于生成HTML测试报告。您可以使用以下命令安装:
``` pip install pytest-html ```
7. 安装allure-pytest
allure-pytest是一个pytest插件,用于生成Allure测试报告。您可以使用以下命令安装:
``` pip install allure-pytest   8. 安装allure,并配置环境变量   8.1 allure官方地址:Central Repository: io/qameta/allure/allure-commandline (apache.org)   8.2 配置环境变量:进入 高级系统设置 - 环境变量 - 系统变量 - path - 编辑。[复制自己本地的bin目录,eg:D:\Python3.8\Scripts\allure-2.13.2\bin] 9. 修改pycharm的allure环境变量配置:   File  --> Setting --> Bulid,Execution,Deployment --> Consonle  -->Python Console:   [复制自己本地的bin目录,egEnvironment variables:PATH=D:\Python3.8\Scripts\allure-2.13.2\bin] 例子:   1. 创建一个名为test_example.py的文件,并编写测试用例。以下是一个示例: ``` import pytest from selenium import webdriver
@pytest.mark.parametrize("search_text", ["Python", "Selenium", "pytest"]) def test_search(search_text):     driver = webdriver.Chrome()     driver.get("https://www.google.com/")     search_box = driver.find_element_by_name("q")     search_box.send_keys(search_text)     search_box.submit()     assert search_text in driver.title     driver.quit() ```
在这个例子中,我们编写了一个名为test_search的测试用例,并使用pytest.mark.parametrize装饰器实现了数据驱动。
2. 运行测试用例
使用以下命令运行测试用例:
``` pytest -n 3 --reruns 2 --html=report.html --alluredir=allure-results ```
上述命令将运行测试用例,并使用3个进程并行运行测试。如果测试失败,它将重试2次。它还将生成一个HTML测试报告,并将Allure测试报告输出到allure-results目录中。
3. 生成Allure测试报告
使用以下命令生成Allure测试报告:
``` allure serve allure-results    

标签:search,allure,--,selenium,pytest,pip,安装
From: https://www.cnblogs.com/fogwithtears/p/17320670.html

相关文章

  • Python+Requests+Pytest接口自动化测试微信接口实例
         pytest.ini配置文件[pytest]log_cli=truelog_level=NOTSETlog_format=%(asctime)s%(levelname)s%(message)slog_date_format=%Y-%m-%d%H:%M:%Saddopts=-vs--alluredir./temp-m'file'log_file=./log/test.loglog_file_level=infol......
  • pytest + yaml 框架 -24.单个用例中参数化功能实现
    前言早期版本参数化功能实现只支持在config中全局的地方写parameters关键字,只实现了基本的功能。v1.2.1版本对parameters参数化功能做了进一步的细分,支持在case用例中针对单个用例的参数化了。parameters参数化用例参数化的实现,我设计了2种实现方式参数化方式1:con......
  • pytest学习笔记
    pytest是python的一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高。根据pytest的官方网站介绍,它具有如下特点:非常容易上手,入门简单,文档丰富,文档中有很多实例可以参考能够支持简单的单元测试和复杂的功能测试支持参数化执行测......
  • selenium:
    1.为什么要学习selenium2.安装selenium3.selenium基本使用......
  • selenium操作网页再练手
    #coding:utf-8fromselenium.commonimportNoSuchElementException,TimeoutExceptionfromselenium.webdriver.supportimportexpected_conditionsasECfromtkinterimport*importthreadingfromtkinterimportttkimportpandasaspdfromselenium.webdriver......
  • Python+selenium点击网页上指定坐标
     fromseleniumimportwebdriverfromselenium.webdriver.common.action_chainsimportActionChainsdefclick_locxy(dr,x,y,left_click=True):'''dr:浏览器x:页面x坐标y:页面y坐标left_click:True为鼠标左键点击,否则为右键点击''&#......
  • pytest中的monkeypatch
    一、猴子补丁简介在有些场景下的测试可能需要修改全局配置或者系统变量等操作,而这些操作仅仅是为了做一些测试,不希望永久的修改,此时就需要使用猴子补丁了,猴子补丁,即monkeypatch,是一个fixture,它提供了以下方法:monkeypatch.setattr(obj,name,value,raising=True)monkeypatch.se......
  • 使用 selenium 自动化抓取百度案例
    #1.导入fromselenium.webdriver.chrome.serviceimportServicefromseleniumimportwebdriverfromselenium.webdriver.common.byimportByimporttime#下面是阻止闪退的#fromselenium.webdriver.chrome.optionsimportOptions#options=Options()#2.创建......
  • selenium 常用的选择器
    新版本Selenium代码需要引入:fromselenium.webdriver.common.byimportBy选择器也变了,而后做如下修改#inputTag=driver.find_element_by_id("value")#利用ID查找#改为:inputTag=driver.find_element(By.ID,"value")#inputTags=driver.find_element_by_cla......
  • 安装 selenium
    安装 selenium查看谷歌版本  Chrome驱动下载地址(跟谷歌版本一定要对上):  http://chromedriver.storage.googleapis.com/index.html    下载好以后   放入项目的根目录  创建文件并安装引入selenium  打开浏览器百度网站案例#1.导入froms......