当前位置:网站首页>Web自动化实战——Selenium4(自动化测试环境的搭建)
Web自动化实战——Selenium4(自动化测试环境的搭建)
2022-07-31 14:44:00 【T_JC】
1. WEB自动化实战—Selenium4
- web自动化测试需求和挑战
- 属于E2的测试,是软件质量保证的最后一道防线
- 点点点:低调,复杂的场合无法测试
- 好的测试,不仅仅模拟用户行为,还要记录、调试网页细节
- 优势:
- 提速增效
- 解放双手
- 技能提示
- 目前主流工具
- Cypress
- Playwright
- Selenium
2. Selenium的优势:
浏览器支持醉的,兼容最好
支持多种编程语言
生态成熟,文档丰富
进行APP自动化测试,事半功倍
pip豆瓣源安装 :pip install xxx包 -i https://pypi.douban.com/simple/
Selenium自动化环境搭建
一键搭建
pip install webdriver-helper
webdriver-helper:
- 自动获取浏览器的版本、操作系统类型
- 自动下载浏览器驱动
- 自动创建和返回WebDriver对象
控制浏览器
with get_webdriver() as driver:
driver.get(“https://baidu.com”)
自动关闭浏览器
3. Selenium自动化实战
web自动化测试三板斧:
- 定位元素
- 交互元素
- 进行断言
3.1 八大定位策略
ID、name、css、xpath、classname、tag_name、link_text
3.2 pytest夹具使用
# 创建一个夹具
@pytest.fixture()
def driver():
driver = get_webdriver() # 启动浏览器
driver.get("http://appfront.huice.com/")
# 前置部分,在测试用例之前执行
# 写登录逻辑
yield driver # yield 生成器的写法
# 后置部分,在测试用例之后执行
print('关闭浏览器')
driver.quit()
浏览器启动的次数 = 测试用例的个数
如何避免,重复启动浏览器(每一次启动大概耗时3秒)
pytest夹具范围:
五种范围:
function:默认,每个用例执行一次
class:每个类执行一次
module:每个文件执行一次
package:每个包执行一次
session:整个测试过程只执行一次
写法:@pytest.fixture(scope=“session”)
4. 解决登录的问题
- 自动登录
- 不必重复登录
5. 解决不登录的问题
- 不重启浏览器
- 保持不登录的状态,以便对登录进行测试
网站的登录状态,是如何保持的?
cookie
selenium可以清除cookies :driver.delete_all_cookies() 清除cookie
6. POM设计模式
- pytest解决了用例层面的问题
- pom解决了页面层面的问题
Page Object Model:页面对象 设计模式
- 使用 对象 代表 页面
- 使用 对象 的 属性 代表 页面的元素
- 使用 对象 的 方法 代表 页面的操作
定义过程:
- 定义 BasePage (抽象类)
- 定义 Page (页面类)
- 定义元素的交互 (对象方法)
使用过程:
- 打开页面,实例化Page
- 调用Page方法,完成交互
边栏推荐
- 架构实战营模块8消息队列表结构设计
- Small test knife: Go reflection helped me convert Excel to Struct
- 小试牛刀:Go 反射帮我把 Excel 转成 Struct
- BigDecimal 简介,常用方法
- Asynchronous processing business using CompletableFuture
- 消息队列消息数据存储MySQL表设计
- redhat/openssl generates a self-signed ca certificate and uses it
- Redis与分布式:主从复制
- NPM淘宝镜像(最新版本)于2021-11-21 16:53:52发布新版本npm镜像[通俗易懂]
- DeepLab Series Learning
猜你喜欢

Uniapp WeChat small application reference standard components

Sentinel热点参数限流

OpenShift 4 - Deploy Redis Cluster with Operator

Sentinel安装与部署

Getting started with UnityShader (3) - Unity's Shader
![Recommendation System - Recall Phase - 2013: DSSM (Twin Towers Model) [Embedding (Semantic Vector) Recall] [Microsoft]](/img/40/b567780ed2cf04f1f1336922816f86.png)
Recommendation System - Recall Phase - 2013: DSSM (Twin Towers Model) [Embedding (Semantic Vector) Recall] [Microsoft]

Essential Learning for Getting Started with Unity Shader - Transparency Effect

OAuth2:搭建授权服务器

Asynchronous processing business using CompletableFuture

Architecture actual combat battalion module 8 message queue table structure design
随机推荐
OpenCV测量物体的尺寸技能 get~
Use of el-tooltip
NPM Taobao mirror (latest version) released a new version of npm mirror at 2021-11-21 16:53:52 [easy to understand]
Spark学习(2)-Spark环境搭建-Local
MySQL【子查询】
el-tooltip的使用
Introduction to BigDecimal, common methods
OAuth2:使用JWT令牌
PDF 拆分/合并
redhat/openssl generates a self-signed ca certificate and uses it
An article makes it clear!What is the difference and connection between database and data warehouse?
The Selenium IDE of the Selenium test automation
How to grab configuration information for DELL SC compellent storage system
最近很火的国产接口神器Apipost体验
ML、DL、CV常见的问题整理
五个维度着手MySQL的优化
The pre-sale of the new Hyundai Paristi is open, and safety and comfort are not lost
Miller_Rabin Miller Rabin probability sieve [template]
[Pytorch] F.softmax() method description
蔚来杯2022牛客暑期多校训练营4