当前位置:网站首页>教你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边栏推荐
- German agbb VOC hazardous substances test
- Kalman滤波器--从高斯融合推导
- How to improve the three passive situations in data analysis
- Huaxing Securities: kitex practice under the original hybrid Cloud Architecture
- Teach you to quickly set up a live studio in 30 minutes
- Some interesting modules
- ANSI/UL 94 5-V级垂直燃烧试验
- 拓维信息使用 Rainbond 的云原生落地实践
- com. alibaba. fastjson. Jsonobject tojsonstring eliminate circular reference
- Sqlserver SQL Server Management Studio and transact SQL create accounts and create read-only users to access the specified database
猜你喜欢

不同制造工艺对PCB上的焊盘的影响和要求

Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 1)

充值满赠,IM+RTC+X 全通信服务「回馈季」开启

Entropy - conditional entropy - joint entropy - mutual information - cross entropy

Nodejs 安装与介绍

《所谓情商高,就是会说话》读书笔记

dtd建模

正则表达式(正则匹配)

20220607 fell below the recommended retail price, and the GPU market is moving towards oversupply

DTD modeling
随机推荐
Courage to be hated: Adler's philosophy class: the father of self inspiration
TCP packet sticking problem
一套十万级TPS的IM综合消息系统的架构实践与思考
Where do the guests come from
slice
Introduction to Po mode "suggestions collection"
《客从何处来》
「经验」爬虫在工作中的实战应用『理论篇』
德国AgBB VoC有害物质测试
MySQL download and installation tutorial
Kalman filter -- Derivation from Gaussian fusion
Electron 入门
Unlimited cloud "vision" innovation | the 2022 Alibaba cloud live summit was officially launched
mysql 递归
Video content production and consumption innovation
opencv数据类型代码表 dtype
torch stack() meshgrid()
「干货」数据分析常用的10种统计学方法,附上重点应用场景
CTF flow analysis common questions (II) -usb flow
PyTorch学习(三)