当前位置:网站首页>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 !
边栏推荐
- Introduction to promql of # yyds dry goods inventory # Prometheus
- Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
- 黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)
- GTSAM中李群的運用
- F - true liars (category and search set +dp)
- Embedded point test of app
- [postman] the monitors monitoring API can run periodically
- [web security] nodejs prototype chain pollution analysis
- 数学三大核心领域概述:几何
- Online and offline problems
猜你喜欢
随机推荐
[C language] string left rotation
通过修改style设置打印页样式
Software test interview questions - Test Type
一文揭开,测试外包公司的真 相
[postman] test script writing and assertion details
【C语言】qsort函数
Seven imperceptible truths in software testing
[web security] nodejs prototype chain pollution analysis
功能安全之故障(fault),错误(error),失效(failure)
Application du Groupe Li dans gtsam
Pat (Grade B) 2022 summer exam
Dynamic programming -- knapsack problem
多线程应用的测试与调试
【eolink】PC客户端安装
[wechat applet] build a development tool environment
MPLS test report
【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能
「 WEB测试工程师 」岗位一面总结
自定义指定路由上的Gateway过滤器工厂
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