当前位置:网站首页>教你Selenium 测试用例编写
教你Selenium 测试用例编写
2022-06-30 18:00:00 【华为云】
编写Selenium测试用例就是模拟用户在浏览器上的一系列操作,通过脚本来完成自动化测试。
编写测试用例的优势:
开源,免费。
支持多种浏览器 IE,Firefox,Chrome,Safari。
支持多平台 Windows,Linux,Mac。
支持多语言 Python,Java,C#。
对 Web 支持良好。
简单,灵活。
支持分布式测试用例执行。
引入依赖
引入依赖是为了调用 webdriver 中的方法来与浏览器进行交互以实现操作步骤。
- Python版本
from selenium import webdriver测试用例的流程
测试用例是为了实施测试从而向被测试的系统提供的一组集合,这组集合包含:测试环境、操作步骤、测试数据、预期结果等。
注意:一条测试用例的最终结果只有一个:成功或者失败。
三大核心要素为 :标题 、步骤 、预期结果
标题:是对测试用例的描述,标题应该清楚的表达测试用例的内容
步骤:对测试执行过程进行描述
预期结果:提供测试执行的预期结果,预期结果一般是根据需求得出,如果实际结果和预期结果一致则测试通过,反之失败。
实战演练
首先是在代码的最上面导入了 Selenium 的包,其次是测试方法命名、测试步骤、断言。测试用例内容是要断言打开百度页面所展现的内容与所期望的值是否相等。
- Python版本
from selenium import webdriver# 测试的标题即 test_searchdef test_search(): driver = webdriver.Chrome() # 测试的步骤 driver.get('https://www.baidu.com') search = driver.find_element_by_id('su').get_attribute('value') # 断言预期结果 assert search == "百度"这里要断言打开百度页面所展现的内容与所期望的值是否相等。因为实际获取到的内容应该是百度一下而不是百度,所以断言错误。
FAILED [100%]test_demo.py:3 (test_search)百度一下 != 百度Expected :百度Actual :百度一下<Click to see difference>def test_search(): driver = webdriver.Chrome() driver.get('https://www.baidu.com') search = driver.find_element_by_id('su').get_attribute('value')> assert search == "百度"E AssertionError: assert '百度一下' == '百度'test_demo.py:9: AssertionError边栏推荐
- BeanUtils.copyProperties() 对比 mapstruct
- Large file transfer software based on UDP protocol
- 一文详解|Go 分布式链路追踪实现原理
- CTF flow analysis common questions (II) -usb flow
- France a+ France VOC label highest environmental protection level
- Pytorch learning (III)
- JS string interception method summary
- 华兴证券:混合云原生架构下的 Kitex 实践
- Compare the audio librosa library with the Mel spectrogram in the torchaudio library
- 基于STM32F1的环境光与微距离检测系统
猜你喜欢

Redis入门到精通01

Video content production and consumption innovation

VMware16安装Win11虚拟机(最全步骤+踩坑)

Sqlserver SQL Server Management Studio and transact SQL create accounts and create read-only users to access the specified database

Kalman filter -- Derivation from Gaussian fusion

Nodejs 安装与介绍

dtd建模

Nodejs installation and introduction

Regular expressions (regular matching)

链表中环的入口结点-链表专题
随机推荐
The cloud native landing practice of using rainbow for Tuowei information
Evolution of screen display technology
MySQL 索引测试
Delete duplicate elements in the sorting linked list ii[unified operation of linked list nodes --dummyhead]
Adhering to the concept of 'home in China', 2022 BMW children's traffic safety training camp was launched
一点比较有意思的模块
Detailed single case mode
RFFE中MIPI协议
Brief introduction of Feature Engineering in machine learning
nats集群部署
Nodejs 安装与介绍
France a+ France VOC label highest environmental protection level
Swin-transformer --relative positional Bias
mysql修改数据类型_MySQL修改字段类型[通俗易懂]
基于STM32F1的环境光与微距离检测系统
Redis入门到精通01
DTD modeling
NBI visual platform quick start tutorial (V) introduction to editor functions and operations
Lenovo Yoga 27 2022, full upgrade of super configuration
Unlimited cloud "vision" innovation | the 2022 Alibaba cloud live summit was officially launched