当前位置:网站首页>Dry goods | record your first web automation test case
Dry goods | record your first web automation test case
2022-04-21 15:07:00 【Hua Weiyun】
Web Acceptance testing of applications often involves some manual tasks , For example, open a browser , And perform the operations described in a test case . However, manual tasks are prone to human errors , It takes more time and cost . therefore , Automate these tasks , You can eliminate human factors .Selenium Can help us automatically complete the acceptance test , By building more rigorous tests , This makes the software more reliable and easier to maintain .
Selenium Test framework and case writing
Selenium What is it? ?
Selenium It's for testing Web Application user interface (UI) Common framework of . It is a powerful tool for running end-to-end functional tests . You can write tests in multiple programming languages , also Selenium Is the ability to perform these tests in one or more browsers .
Write code using client Of api then client and Selenium Communication how to operate , after selenium Through the browser driver Operate the browser to perform various actions .
The latest version is Selenium 3,Selenium Core components include :
- Selenium WebDriver
- Selenium IDE
- Selenium Grid
Selenium Source code :
https://github.com/SeleniumHQ/selenium,[Selenium Client Driver]
(https://seleniumhq.github.io/selenium/docs/api/py/):
Selenium WebDriver Of Python Language implementation .
Reference resources :Selenium with Python
1. Install browser :Firefox、Chrome
2. Download browser Driver:
3.GeckoDriver(Firefox)、ChromeDriver(Chrome),WebDriver The version needs to be consistent with the browser version .
4. install Selenium Client Driver:
pip install selenium
A test case is a set of sets provided to the system under test for the purpose of testing , 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 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 .
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 .
from selenium import webdriverdef test_search(): # The title of the test is test_search driver = webdriver.Chrome() driver.get('https://www.baidu.com') # Test steps search = driver.find_element_by_id('su').get_attribute('value') # assert search == " Baidu " # Assert the expected result
After installation , Start by clicking the icon in the browser's menu bar .

First step : After creating a new project , named hogwarts_demo1.
The second step : Then you need to fill in URL( The website to record the test script URL). What we use here is https://ceshiren.com/.
The third step : After setting up , A new browser window will open , load URL And start recording the script . All actions on the page will be recorded in IDE in . After the operation is completed , Switch to IDE Window and click the stop recording button .

Step four : After the stop , Name the test case you just recorded ceshiren_demo1
Export use case analysis
utilize Selenium IDE export pytest Format code .
The exported use case code is as follows :
# Comments are made by Selenium IDE Generated code # Generated by Selenium IDE # Import possible dependencies import pytest from selenium import webdriver from selenium.webdriver.common.by import By class TestDemo(): #setup_module() It will only run once at the beginning of the test def setup_method(self, method): # initialization webdriver self.driver = webdriver.Chrome() self.vars = {} #teardown_module() Only run once at the end of the test def teardown_method(self, method): # Close the browser and close startup ChromeDriver Start the ChromeDriver Executable file self.driver.quit() # The test method def test_demo(self): # Visit website self.driver.get("https://ceshiren.com/") # Set window size self.driver.set_window_size(1473, 866) # Click on the action self.driver.find_element(By.LINK_TEXT, " All categories ").click() self.driver.find_element(By.CSS_SELECTOR, "#ember201 .category-name").click() # Close the current window self.driver.close()
This code simply realizes the simple automation of the browser



Get more :https://qrcode.ceba.ceshiren.com/link?name=article&project_id=qrcode&from=hwyun×tamp=1650522766
版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211504107119.html
边栏推荐
- ENSP三层交换机连接二层交换机及路由器的做法
- .Net C# Newtonsoft. JSON serializersettings configuration
- Insect 1602
- Legendary server setup tutorial, legendary GM permission command setting tutorial
- 京东云重磅发布云电脑,面向未来打造无界办公体验
- It's been 2 years since the career change test. Give some advice to girls who are still hesitating
- SWOOLE高性能内存数据库的使用和配置教程
- The conversion between RDD and dataframe in pyspark is realized by RDD processing dataframe: data segmentation and other functions
- MySQL下载和安装教程
- VMware horizon 8 2111 deployment series (XIII) creating application pool
猜你喜欢

数字化时代,SaaS软件如何成为国产化替代的轻骑兵?

突然掉电,为啥MySQL也不会丢失数据?(收藏)

你真的会用`timescale吗?

Druid database link problem

pytorch图像分类篇:pytorch官方demo实现一个分类器(LeNet)

The use of toString and wrapper class

Ali's monthly salary is 15K. The interview is so simple

.Net C# Newtonsoft. JSON serializersettings configuration

DBeaver无法连接数据库,如何解决?

嵌入式开发:重新利用开发板进行测试的3个技巧
随机推荐
How to insert a file into excel? What is the difference between excel insert object and attachment? (the inserted object can directly display the content, but I didn't display it?)
阿里P9详解高并发,带你了解淘宝怎么抗住双11等大型秒杀活动
怎么去约束代码的统一性
How to apply for a free SSL certificate? Pagoda panel SSL certificate installation and deployment complete tutorial
Dbaver cannot connect to the database. How to solve it?
scala安装及环境配置
【天梯赛】L2-040 哲哲打游戏 (25 point(s))(模拟)
Distributed database -- Plan hint of SQL optimization
Golang Gorm框架初始化的优美解决方案
干货 | 录制你的第一个web 自动化测试用例
SAP ui5 application development tutorial 70 - how to use button controls to trigger page routing jump trial version
pyspark中RDD和DataFrame之间的转换利用RDD处理DataFrame:数据分段等功能实现
虫子 插入 希尔
如何批量修改文件名、照片文件名
Why is it necessary to override the hashcode () method when overriding the equals () method
京东云重磅发布云电脑,面向未来打造无界办公体验
Lightgbm topic 4: lightgbm model saving under pyspark platform
使用wx.showActionSheet选择框修改数据库中的信息,为什么会报data未定义的错呢
Technology sharing | black box testing methodology - boundary value
Mysql database (2)