当前位置:网站首页>Selenium automation integration, eight years of testing experience, soft test engineer, an article to teach you
Selenium automation integration, eight years of testing experience, soft test engineer, an article to teach you
2022-07-07 08:51:00 【Software testing】
problem
When we describe a “ Good automated test cases ” when , The standard that often appears is :
accurate
Automated test cases should test one thing , There is only one thing . An error in a part of an application that is not related to a test case should not cause the test case to fail
Independent
Automated test cases should not be affected by any other test cases in the test suite
Fast
It doesn't need much explanation . The faster the automated test case suite runs , The more useful it is
These standards are in Selenium The test suite can be particularly challenging . The reason lies in ,Selenium Of UI Automated testing usually involves registration , Sign in , Some navigation , Settings for form submission or other interaction with the website . Only after doing these things , You can make assertions in some aspects of the website . But this will introduce some errors that are not related to the original test case, resulting in the failure of the automation script .
02、 resolvent
Now many new websites use REST API. If you can access in a script REST API To complete some basic necessary operations , Not in UI On , This will improve the execution efficiency of our tests .
REST API be based on HTTP agreement , This is basically the whole Internet protocol . Almost all modern programming languages can be used to emit HTTP Requested Library , therefore , We can call REST API Add support to almost any test suite .
03、 example
Many tests will encounter the problem of creating new accounts . You need to test the behavior of the new account after logging in . If it can be used REST API To create new users , It can greatly save the time of filling in the form of new account .
Let's assume a virtual REST API
POST http://api.myfakeapp.com/v1/create-user
adopt POST Method to create a new user .
Body It needs filling JSON The data are as follows :
{
'username': 'example-username',
'password': 'abcd1234',
'email': '[email protected]',
'first_name': 'bob',
'last_name': 'example'
}
The following is the code implementation :
require '
rest-cli
ent'
require '
json
'
require '
securerandom
'
class RestApiInterface
@headers = {
'
content-type
' => '
application
/json
',
'
user-agent
' => '
Rest Api Helper
',
}
def post_to_api url, post_body_obj
json_body = JSON.generate(post_body_obj)
response = RestClient.post url, json_body, @headers
end
def create_test_user
# Step 1: Build the user parameters randomly
random_test_user = {
'
username
' => random_string,
'
password
' => random_string,
'
email
' => "
#{random_string}@testing.com
",
'
first_name
' => '
test
',
'
last_name
' => '
user
',
}
# Step 2: Execute the API call
response = post_to_api "
http://api.myfakeapp.com/v1/create-user
",
random_test_user
# Step 3: Ensure the api call returned a success code
if response.code != '
200
'
raise '
User creation failed
'
end
# Final Step: Return the user object so we can use it
response.body['
user
']['
data
']
end
def random_string
# This is an easy way to get a good randomized string
SecureRandom.hex
end
end
$driver
= Selenium::WebDriver.for :firefox
user = RestApiInterface.new.create_test_user
$driver
.get 'http://myfakeapp.com'
$driver
.find_element(:css, 'input[name="
username
"]').send_keys @user['
username
']
$
driver
.find_element(:css, 'input[name="
password
"]').send_keys @user['
password
']
$driver
.find_element(:css, 'button[name="
login
"]').click
puts
$driver
.find_element(:css, '
#user_id
').text
04、 summary
Here is just an example of how to put API Access and UI Idea of combining automation . Under the guidance of this idea , It can be done to UI Automated testing makes many extensions , For example, verify the data sum of interface data elements API Consistency of data in .
The house needs to be built layer by layer , Knowledge needs to be learned at one point one . We should lay a good foundation in the process of learning , More hands-on practice , Don't talk much , The last dry goods here ! I stayed up late to sort out the stages ( function 、 Interface 、 automation 、 performance 、 Test open ) Skills learning materials + Practical explanation , Very suitable for studying in private , It's much more efficient than self-study , Share with you .
Get off w/x/g/z/h: Software testing tips dao
Typing is not easy , If this article is helpful to you , Click a like, collect a hide and pay attention , Give the author an encouragement . It's also convenient for you to find it quickly next time .
边栏推荐
- Greenplum6.x常用语句
- Gson转换实体类为json时报declares multiple JSON fields named
- let const
- Appeler l'interface du moteur de création du service multimédia de jeu Huawei renvoie le Code d'erreur 1002, le message d'erreur: les paramètres sont l'erreur
- Find the original code, inverse code and complement of signed numbers [C language]
- ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
- Introduction to data fragmentation
- Redis summary
- What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking
- About using CDN based on Kangle and EP panel
猜你喜欢
Greenplum6.x监控软件搭建
Routing information protocol rip
[Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources
Greenplum 6.x common statements
指针进阶,字符串函数
NCS Chengdu New Electric interview Experience
Why choose cloud native database
Arm GIC (IV) GIC V3 register class analysis notes.
LeetCode 736. Lisp 语法解析
详解华为应用市场2022年逐步减少32位包体上架应用和策略
随机推荐
Interpolation lookup (two methods)
Upload an e-office V9 arbitrary file [vulnerability recurrence practice]
String operation
mysql分区讲解及操作语句
JS operation
【MySQL】数据库进阶之触发器内容详解
Enterprise manager cannot connect to the database instance
联想混合云Lenovo xCloud:4大产品线+IT服务门户
南京商品房买卖启用电子合同,君子签助力房屋交易在线网签备案
23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP
Frequently Asked Coding Problems
实现自定义内存分配器
redis故障处理 “Can‘t save in background: fork: Cannot allocate memory“
ncs成都新電面試經驗
Rapid integration of authentication services - harmonyos platform
A bug using module project in idea
详解华为应用市场2022年逐步减少32位包体上架应用和策略
What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking
NCS Chengdu New Electric interview Experience
QT charts use (rewrite qchartview to realize some custom functions)