当前位置: 首页 > news >正文

W30-python03-pytest+selenium+allure访问百度网站实例

此篇文章为总结性,将pystest、selenium、allure结合起来

功能如下,web自动化,输入baidu网站,搜索“雷军”、打开网页中第一条内容

pytestsel.py如下:

import time
import re
import allure
import pytest
from tools.webkeys import Web@allure.feature('#1 电商测试用例demo')
class Test_Obj:def setup_class(self):self.web = Web()self.web.open_browser()@allure.story('#1 打开百度')def test_baidu(self):allure.dynamic.title('登录')allure.dynamic.description('登录百度的描述')with allure.step('输入网址'):self.web.get_url('http://www.baidu.com')time.sleep(3)with allure.step('输入搜索关键字'):self.web.input('kw','雷军')time.sleep(3)with allure.step('点击搜索'):self.web.click('su')time.sleep(3)with allure.step('获取outerHTML'):str = self.web.get_attribute('content_left','outerHTML')allure.attach(self.web.driver.get_screenshot_as_png(), '执行成功', allure.attachment_type.PNG)with allure.step('跳转到第一个链接'):reg = r'mu="(.*?)"\s'url = re.findall(reg, str)self.web.get_url(url[0])allure.attach(self.web.driver.get_screenshot_as_png(), '执行成功', allure.attachment_type.PNG)time.sleep(10)self.web.driver.quit()

程序执行入口

import osimport pytestif __name__ == '__main__':#window下删除报告的命令os.system('rd /s/q result')os.system('rd /s/q result')# pytest.main(['-s', 'pytestallure.py', '--alluredir', './result'])pytest.main(['-s', 'pytestsel.py', '--alluredir', './result'])os.system('allure generate result -o report --clean')

http://www.lryc.cn/news/406893.html

相关文章:

  • 如何在 Debian 8 上安装和使用 PostgreSQL 9.4
  • 【微信小程序】微信小程序设置本地背景图片在真机无法显示的解决方案
  • Arthas在线诊断案例实战整理
  • 使用 XRDP 远程linux主机
  • 学习小型gpt源码(自用)
  • @Transactional使用的注意事项
  • 快手可灵视频生成大模型全方位测评
  • 【JavaScript】`Map` 数据结构
  • Ubuntu22.04使用NVM安装多版本Node.js和版本切换
  • 基于C51和OLED12864实现Goole小恐龙
  • 【Docker】CentOS7环境下的安装
  • 浏览器的最大并发数(http1.1)
  • Android 开发中px、dpi 和 dp三个单位的介绍
  • zookeeper开启SASL权限认证
  • mysql一个小问题引发的思考-mysql类型转换-查询缓存 及 MYSQL查询缓存以及自动选择不使用查询缓存的情况
  • css更改图片颜色
  • 通过POST请求往Elastic批量插入数据
  • JAW:一款针对客户端JavaScript的图形化安全分析框架
  • 错误解决 error CS0117: ‘Buffer‘ does not contain a definition for ‘BlockCopy‘
  • ICMPv6与DHCPv6之网络工程师软考中级
  • 【HTML — 构建网络】HTML 入门
  • javafx的ListView代入项目的使用
  • 基于ABAP OLE技术实现对服务器文件进行读写操作
  • 求教Postgresql在jdbc处理bit(1)字段的预处理解决方案
  • 微信小程序-自定义tabBar
  • vue3+element-plus 实现动态菜单和动态路由的渲染
  • GO-学习-03-基本数据类型
  • 高并发场景下,系统的保护机制
  • 服务器构建私有npm库(Docker + Verdaccio)
  • LabVIEW做二次开发时应该注意哪些方面?