当前位置:网站首页>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 .
边栏推荐
- POJ - 3616 Milking Time(DP+LIS)
- Tronapi wave field interface - source code without encryption - can be opened twice - interface document attached - package based on thinkphp5 - detailed guidance of the author - July 6, 2022 - Novice
- [Yugong series] February 2022 U3D full stack class 006 unity toolbar
- Redis summary
- LeetCode 715. Range 模块
- Golan idea IntelliJ cannot input Chinese characters
- 详解华为应用市场2022年逐步减少32位包体上架应用和策略
- opencv之图像分割
- Enterprise manager cannot connect to the database instance
- [Yu Yue education] C language programming reference of Zhongbei College of Nanjing Normal University
猜你喜欢
Why choose cloud native database
JS operation
Greenplum 6.x monitoring software setup
Routing information protocol rip
快速集成认证服务-HarmonyOS平台
如何在HarmonyOS应用中集成App Linking服务
Virtual address space
let const
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
Data type - floating point (C language)
随机推荐
如何在HarmonyOS应用中集成App Linking服务
Leetcode 1984. Minimum difference in student scores
Mountaineering team (DFS)
Image segmentation in opencv
Markdown编辑器Editor.md插件的使用
opencv 将16位图像数据转为8位、8转16
opencv之图像分割
xray的简单使用
Greenplum 6.x common statements
Novice entry SCM must understand those things
Greenplum 6.x version change record common manual
Componentspace2022, assertions, protocols, bindings, and configuration files
Tips for using jeditabletable
使用AGC重签名服务前后渠道号信息异常分析
Redis summary
Why choose cloud native database
What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking
注解@ConfigurationProperties的三种使用场景
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
[machine learning] watermelon book data set_ data sharing