当前位置:网站首页>Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
2022-07-06 06:15:00 【The elegance of testing】
To write Selenium The test case is to simulate a series of operations of the user on the browser , Complete automated testing through scripts .
Advantages of writing test cases :
Open source , free .
Support multiple browsers IE,Firefox,Chrome,Safari.
Support for multiple platforms Windows,Linux,Mac.
Support for multiple languages Python,Java,C#.
Yes Web Good support .
Simple , flexible .
Support distributed test case execution .
Introduce dependencies
Dependency is introduced to call webdriver To interact with the browser to realize the operation steps .
- Python edition
from selenium import webdriver
Flow of test cases
A test case is a set of sets provided to the system under test in order to implement the test , This set of collections contains : Test environment 、 Operation steps 、 Test data 、 Expected results, etc .
Be careful : The final result of a test case is only one : Success or failure .
The three core elements are : title 、 step 、 Expected results
- title : Is a description of the test case , The title should clearly express the content of the test case
- step : Describe the test execution process
- Expected results : Provide the expected results of test execution , The expected results are generally based on demand , If the actual results are consistent with the expected results, the test passes , On the contrary, failure .
Practical drill
The first is to import... At the top of the code Selenium My bag , The second is the naming of test methods 、 testing procedure 、 Assertion . The content of the test case is to assert whether the content displayed by opening Baidu page is equal to the expected value .
Python edition
from selenium import webdriver
# The title of the test is test_search
def test_search():
driver = webdriver.Chrome()
# Test steps
driver.get('https://www.baidu.com')
search = driver.find_element_by_id('su').get_attribute('value')
# Assert the expected result
assert search == " Baidu "
Here to assert whether the content displayed by opening Baidu page is equal to the expected value . Because the content actually obtained should be Baidu, not Baidu , So the assertion is wrong .
FAILED [100%]
test_demo.py:3 (test_search)
use Baidu Search != Baidu
Expected : Baidu
Actual : use Baidu Search
<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 == " Baidu "
E AssertionError: assert ' use Baidu Search ' == ' Baidu '
test_demo.py:9: AssertionError
Last : It can be in the official account : Sad spicy bar ! Get one by yourself 216 Page software testing engineer interview guide document information 【 Free of charge 】. And the corresponding video learning tutorial is free to share !, It includes basic knowledge 、Linux necessary 、Shell、 The principles of the Internet 、Mysql database 、 Special topic of bag capturing tools 、 Interface testing tool 、 Test advanced -Python Programming 、Web automated testing 、APP automated testing 、 Interface automation testing 、 Testing advanced continuous integration 、 Test architecture development test framework 、 Performance testing 、 Safety test, etc. .
I recommend one 【Python Automated test communication group :746506216】, We can discuss communication software testing together , Learn software testing together 、 Interview and other aspects of software testing , Help you advance quickly Python automated testing / Test Development , On the road to high pay .
Friends who like software testing , If my blog helps you 、 If you like my blog content , please “ give the thumbs-up ” “ Comment on ” “ Collection ” One Key triple connection !
边栏推荐
猜你喜欢
Manhattan distance sum - print diamond
[eolink] PC client installation
JDBC Requset 对应内容及功能介绍
10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
[postman] collections configuration running process
Summary of anomaly detection methods
What are the test sites for tunnel engineering?
【eolink】PC客户端安装
[C language] string left rotation
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
随机推荐
通过修改style设置打印页样式
全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
Overview of three core areas of Mathematics: algebra
【API接口工具】postman-界面使用介绍
还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
Basic knowledge of error
Online and offline problems
Detailed explanation of BF and KMP
黑猫带你学UFS协议第4篇:UFS协议栈详解
Sqlmap tutorial (III) practical skills II
Manhattan distance and Manhattan rectangle - print back font matrix
10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块
JMeter做接口测试,如何提取登录Cookie
Eigen sparse matrix operation
数据库隔离级别
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
Clock in during winter vacation
properties文件
LeetCode 729. 我的日程安排表 I
Usage of test macro of GTEST