当前位置:网站首页>还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
2022-07-06 06:07: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_search
def 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
最后: 可以在公众号:伤心的辣条 ! 自行领取一份216页软件测试工程师面试宝典文档资料【免费的】。以及相对应的视频学习教程免费分享!,其中包括了有基础知识、Linux必备、Shell、互联网程序原理、Mysql数据库、抓包工具专题、接口测试工具、测试进阶-Python编程、Web自动化测试、APP自动化测试、接口自动化测试、测试高级持续集成、测试架构开发测试框架、性能测试、安全测试等。
我推荐一个【Python自动化测试交流群:746506216】,大家可以一起探讨交流软件测试,共同学习软件测试技术、面试等软件测试方方面面,助你快速进阶Python自动化测试/测试开发,走向高薪之路。
喜欢软件测试的小伙伴们,如果我的博客对你有帮助、如果你喜欢我的博客内容,请 “点赞” “评论” “收藏” 一 键三连哦!
边栏推荐
- nodejs实现微博第三方登录
- LTE CSFB process
- Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误
- Investment strategy discussion and market scale prediction report of China's solid state high power amplifier industry from 2022 to 2028
- CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
- 【Postman】Collections-运行配置之导入数据文件
- OSPF configuration command of Huawei equipment
- [web security] nodejs prototype chain pollution analysis
- 公司視頻加速播放
- Bit operation rules
猜你喜欢

LeetCode 729. 我的日程安排表 I

IPv6 comprehensive experiment

【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能

Idea new UI usage

MySQL之数据类型

【Postman】Collections-运行配置之导入数据文件

LAN communication process in the same network segment

10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module

CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全

【eolink】PC客户端安装
随机推荐
曼哈顿距离和-打印菱形
MPLS test report
Sqlmap tutorial (III) practical skills II
isam2运行流程
Significance of unit testing
A complete collection of necessary learning websites for office programmers
Fault, error, failure of functional safety
公司視頻加速播放
HCIA review
What are the test sites for tunnel engineering?
HCIA复习
Title 1093: character reverse order
Commodity price visualization
Application of Lie group in gtsam
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
(中)苹果有开源,但又怎样呢?
Accélération de la lecture vidéo de l'entreprise
Memory and stack related concepts
Clock in during winter vacation
Investment strategy discussion and market scale prediction report of China's solid state high power amplifier industry from 2022 to 2028