Pytest+Webdriver+Alluer的UI自动化测试框架

这篇具有很好参考价值的文章主要介绍了Pytest+Webdriver+Alluer的UI自动化测试框架。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

作为web自动化的入门学习,搭建框架练习下

一、熟悉项目的测试框架的整体目录

Pytest+Webdriver+Alluer的UI自动化测试框架

二、 PIP安装完所需框架

1、编写main.py

import pytest


if __name__ == '__main__':
 #pytest.main()  # 遍历相同目录下的所以test开头的用例
 #生成测试报告 
#一次执行所有接口测试用例,生成一个测试报告mix
    pytest.main(['--html=../test1/report/test.html', "testwzm.py"])

2、设计登录获取鉴权

import requests
import json
import pytest

#获取环境鉴权
def session():
    #url是固定的获取鉴权接口    
    url = 'https://XXXXXXXXXXXXXX'
    print(url)

    params = {"keywordType":"mobile","keyword":"18111111111","channel":"0","subChannel":"0"}

    headers = {'content-type': "application/json"}

    r = requests.post(url, data=json.dumps(params), headers=headers)

    dict = json.loads(r.text)
    print(dict)
    chanelurl = dict['obj']['channelUrl']
    print(type(chanelurl))
    return chanelurl

3、设计页面测试用例 testwzm.py

from selenium import webdriver
import pytest
import requests
import json
from selenium.webdriver.common.keys import Keys
from testcases import session
from time import sleep

def test_testng():
    """测试页面"""
    option = webdriver.ChromeOptions()
    option.binary_location=r'C:\Program Files\Google\Chrome\Application\chrome.exe'
    driver = webdriver.Chrome()
    url = session.session()
    print(url)
    driver.get(url)
# 测试页面
    driver.get('https://xxxxd')
    driver.maximize_window()
    sleep(1)
    elem = driver.find_element_by_xpath('//*[@id="app"]/div/div[2]/ul/li[1]')
    elem.click()
    sleep(1)
    address = driver.find_element_by_xpath('//*[@id="app"]/div/dl[1]/dd[1]')
    address.click()
    sleep(1)
    button = driver.find_element_by_xpath('//*[@id="app"]/div/button')
    button.click()
    sleep(1)
    check = driver.find_element_by_xpath('//*[@id="app"]/div/div[3]/div[2]/div')
    check.click()
    sleep(1)
    button1 = driver.find_element_by_xpath('//*[@id="app"]/div/div[3]/button')
    button1.click()
    sleep(3)
    alert = driver.find_element_by_xpath('/html/body/div[2]/div/div[2]')
    alert.click()
    sleep(1)
    cancel = driver.find_element_by_xpath('//*[@id="app"]/div/div[4]/input')
    cancel.click()
    sleep(1)
    yes = driver.find_element_by_xpath('//*[@id="app"]/div/div[6]/div[2]/p/a[2]')
    yes.click()
    #text_label = driver.find_element_by_xpath('//*[@id="kw"]')
    sleep(1)
    assert True ==(text_label.is_displayed())
    driver.close()
    driver.quit()

4、设计conftest.py 优化报告样式

from py.xml import html
import pytest



@pytest.mark.optionalhook
def pytest_html_results_table_header(cells):
    cells.insert(1, html.th('Description'))  # 表头添加Description
    cells.pop(-1)  # 删除link


@pytest.mark.optionalhook
def pytest_html_results_table_row(report, cells):
    cells.insert(1, html.td(report.description))  #表头对应的内容
    cells.pop(-1)  # 删除link列


@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):  #description取值为用例说明__doc__
    outcome = yield
    report = outcome.get_result()
    report.description = str(item.function.__doc__)

@pytest.mark.optionalhook
def pytest_html_results_summary(prefix):  #添加summary内容

Pytest+Webdriver+Alluer的UI自动化测试框架文章来源地址https://www.toymoban.com/news/detail-510358.html

到了这里,关于Pytest+Webdriver+Alluer的UI自动化测试框架的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Pytest自动化测试框架---(单元测试框架)

    unittest是python自带的单元测试框架,它封装好了一些校验返回的结果方法和一些用例执行前的初始化操作,使得单元测试易于开展,因为它的易用性,很多同学也拿它来做功能测试和接口测试,只需简单开发一些功能(报告,初始化webdriver,或者http请求方法)便可实现。 但自

    2024年02月14日
    浏览(47)
  • 自动化测试框架selenium之webdriver

    对象的定位应该是自动化测试的核心,要想操作一个对象,首先应该识别这个对象,一个对象有很多的属性,我们可以通过这些属性找到对象。 注意:不管用那种方式,必须保证页面上该属性的唯一性 webdriver 提供了一系列的对象定位方法,常用的有以下几种 id name class nam

    2024年02月12日
    浏览(35)
  • UI自动化测试篇 :Selenium2(Webdriver)&TestNG自动化测试环境搭建

     🔥 交流讨论: 欢迎加入我们一起学习! 🔥 资源分享 : 耗时200+小时精选的「软件测试」资料包 🔥  教程推荐: 火遍全网的《软件测试》教程   📢 欢迎点赞 👍 收藏 ⭐留言 📝 如有错误敬请指正!    最开始学习UI自动化,用的工具是QTP10,用起来确实比较容易上手

    2024年03月10日
    浏览(48)
  • pytest 框架自动化测试

    随笔记录 目录 1. 安装  2. 安装pytest 相关插件 2.1 准备阶段 2.2 安装  2.3 验证安装成功  3. pytest测试用例的运行方式 3.1 主函数模式 3.1.1 主函数执行指定文件  3.1.2 主函数执行指定模块 3.1.3 主函数执行某个文件中的某个类、方法、函数 3.1.4 主函数执行生成allure报告 3.2 命令

    2024年02月19日
    浏览(37)
  • 从0到1精通自动化测试,pytest自动化测试框架,doctest测试框架(十四)

    doctest从字面意思上看,那就是文档测试。doctest是python里面自带的一个模块,它实际上是单元测试的一种。 官方解释:doctest 模块会搜索那些看起来像交互式会话的 Python 代码片段,然后尝试执行并验证结果 doctest测试用例可以放在两个地方 函数或者方法下的注释里面 模块的

    2024年02月11日
    浏览(67)
  • 从0到1精通自动化测试,pytest自动化测试框架,配置文件pytest.ini(十三)

    pytest配置文件可以改变pytest的运行方式,它是一个固定的文件pytest.ini文件,读取配置信息,按指定的方式去运行 pytest里面有些文件是非test文件 pytest.ini pytest的主配置文件,可以改变pytest的默认行为 conftest.py 测试用例的一些fixture配置 _init_.py 识别该文件夹为python的package包

    2024年02月11日
    浏览(38)
  • 自动化测试框架 —— pytest框架入门篇

    今天就给大家说一说pytest框架。 今天这篇文章呢,会从以下几个方面来介绍: 1、首先介绍一下pytest框架 2、带大家安装Pytest框架 3、使用pytest框架时需要注意的点 4、pytest的运行方式 5、pytest框架中常用的插件 pytest 是 python 的第三方单元测试框架,比自带 unittest 更简洁和高效

    2024年02月03日
    浏览(44)
  • pytest接口测试自动化框架

    目录 pytest简介及安装 pytest的使用规则 pytest运行方式 主函数方式 命令行方式 跳过、标记及预期失败特殊场景处理 pytest前后置、夹具 pytest高级用法fixture pytest接口断言 pytest结合allure-pytest生成allure测试报告         谈起用例管理框架:python中的unittest、pytest;java中的test

    2024年02月06日
    浏览(71)
  • Pytest UI自动化测试实战实例

    序号 库/插件/工具 安装命令 1 确保您已经安装了python3.x 2 配置python3+pycharm+selenium2开发环境 3 安装pytest库 pip install pytest 4 安装pytest -html 报告插件 pip install pytest-html 5 安装pypiwin32库(用来模拟按键) pip install pypiwin32 6 安装openpyxl解析excel文件库 pip install openpyxl 7 安装yagmail发送报告

    2024年02月05日
    浏览(51)
  • Selenium+Pytest自动化测试框架

    selenium自动化+ pytest测试框架 本章你需要 一定的python基础——至少明白类与对象,封装继承 一定的selenium基础——本篇不讲selenium,不会的可以自己去看selenium中文翻译网 测试框架有什么优点呢: 代码复用率高,如果不使用框架的话,代码会很冗余 可以组装日志、报告、邮件

    2024年02月07日
    浏览(39)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包