当前位置:网站首页>教你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边栏推荐
- 基于STM32F1的环境光与微距离检测系统
- 20200525-生物技术-四川师范大学自考生物技术(本科)考试计划.txt
- Cloud Native Landing Practice Using rainbond for extension dimension information
- BeanUtils.copyProperties() 对比 mapstruct
- 法国A+ 法国VOC标签最高环保级别
- 正则表达式(正则匹配)
- Kubernetes----Pod配置容器启动命令
- Lenovo Yoga 27 2022, full upgrade of super configuration
- Unlimited cloud "vision" innovation | the 2022 Alibaba cloud live summit was officially launched
- 新版EasyGBS如何配置WebRTC视频流格式播放?
猜你喜欢

MySQL事务并发问题和MVCC机制

传统微服务框架如何无缝过渡到服务网格 ASM

ArcGIS无插件加载(无偏移)天地图

Swin-transformer --relative positional Bias

Electron 入门

亲测flutter打包apk后大小,比较满意

联想YOGA 27 2022,超强配置全面升级

Unlimited cloud "vision" innovation | the 2022 Alibaba cloud live summit was officially launched

Teach you to quickly set up a live studio in 30 minutes

PC端微信多开
随机推荐
【社区明星评选】第23期 7月更文计划 | 点滴创作,汇聚成塔!华为FreeBuds 4E等酷爽好礼送不停
简述机器学习中的特征工程
Reading notes of "high EQ means being able to talk"
《Go题库·15》go struct 能不能比较?
一点比较有意思的模块
Full recharge, im+rtc+x full communication service "feedback season" starts
com. alibaba. fastjson. Jsonobject tojsonstring eliminate circular reference
NEON优化2:ARM优化高频指令总结
ANSI/UL 94 5-V级垂直燃烧试验
RFFE中MIPI协议
企业选型作业上常犯的一个错误
20220528【聊聊假芯片】贪便宜往往吃大亏,盘点下那些假的内存卡和固态硬盘
Four tips tell you how to use SMS to promote business sales?
CODING 正式入驻腾讯会议应用市场!
Some interesting modules
Huaxing Securities: kitex practice under the original hybrid Cloud Architecture
4个技巧告诉你,如何使用SMS促进业务销售?
Ambient light and micro distance detection system based on stm32f1
法国A+ 法国VOC标签最高环保级别
Year after year, why is breaking the data island still the primary task of enterprise development