当前位置:网站首页>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 .
边栏推荐
- Sign and authenticate API interface or H5 interface
- 如何在图片的目标中添加目标的mask
- Greenplum 6.x monitoring software setup
- Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error
- ncs成都新電面試經驗
- Speaking of a software entrepreneurship project, is there anyone willing to invest?
- go写一个在一定时间内运行的程序
- Novice entry SCM must understand those things
- 【MySQL】数据库进阶之触发器内容详解
- let const
猜你喜欢

Category of IP address
![[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology](/img/2a/01db1b84c26502c851786aaca56abe.jpg)
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology

Oracle makes it clear at one time that a field with multiple separators will be split into multiple rows, and then multiple rows and columns. Multiple separators will be split into multiple rows, and
![[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University](/img/e2/519a5267cd5425a83434d2da65ebe6.jpg)
[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University

Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022

LeetCode 715. Range 模块

数据分析方法论与前人经验总结2【笔记干货】

Greenplum6.x监控软件搭建

idea里使用module项目的一个bug

Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot
随机推荐
let const
Greenplum 6.x reinitialization
NCS Chengdu Xindian interview experience
[Nanjing University] - [software analysis] course learning notes (I) -introduction
opencv 将16位图像数据转为8位、8转16
如何在HarmonyOS应用中集成App Linking服务
Greenplum 6.x build_ Environment configuration
Data analysis methodology and previous experience summary 2 [notes dry goods]
Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University
Data type - integer (C language)
数字三角形模型 AcWing 1027. 方格取数
Pointer advanced, string function
为什么要选择云原生数据库
LeetCode 715. Range 模块
[MySQL] detailed explanation of trigger content of database advanced
详解华为应用市场2022年逐步减少32位包体上架应用和策略
Greenplum6.x搭建_安装
Frequently Asked Coding Problems
redis故障处理 “Can‘t save in background: fork: Cannot allocate memory“