当前位置:网站首页>I'm afraid I won't use the JMeter interface testing tool if I accept this practical case
I'm afraid I won't use the JMeter interface testing tool if I accept this practical case
2022-07-27 19:02:00 【Test kid】
One 、 brief introduction
JMeter, One 100% Pure Java Desktop application , from Apache Organization's open source projects , It is an interface function 、 automation 、 sex Tools that can be tested . High scalability 、 Support HTTP、HTTPS、TCP、 Other protocols , You can also write your own Java Script pair Protocol extension .
Official website :https://jmeter.apache.org
Two 、 install and configure
1、 This machine is installed jdk Environmental Science
2、 Download the compressed package on the official website , Unzip... In any directory
3、 Modify the configuration file , open Jmeter Of bin Under the table of contents jmeter.properties, modify :
language=zh_CN
sampleresult.default.encoding=utf-84、 Enter into Jmeter Of bin Under the table of contents , double-click jmeter.bat start-up

3、 ... and 、Jmeter Common components
stay Jmeter in , Can pass Add different components , To achieve different functions , Common components are :
test plan
One of the most basic components , All other components must run inside it .
Thread group
A thread group represents a group of users , It can simulate 1 One or more users , Can initiate 1 One or more requests , It can also be sent continuously n Of a second request .
Sampler
The sampler represents a request , such as HTTP request ,TCP Request etc. , By configuring the interface of the server ip、 Port number and parameters Rest , You can send data to the server , And get the response .
Assertion
An assertion is an expected result , Assertions are usually directed at a HTTP Requested , Judge HTTP Whether the return value of conforms to the rules of assertion , For example, whether it contains “success”, Whether the status code is 200 etc. . If the assertion passes ,Jmeter I think HTTP The request is successful , Otherwise, mark Mark as failure .
Monitor
The listener is Jmeter During the test , Get some running data , For example, how many requests have been sent 、 How many times , failed How many times . Specific contents of each request and response, etc .
Four 、 Write a HTTP Interface script
Open the background login page of code classmate mall seller Management , Enter the user name and password to log in , adopt fiddler, You can capture the information of the login interface :
url:/seller/loginRequest mode :GET
Parameters :username=mtx-001&password=e10adc3949ba59abbe56e057f20f883e&captcha=1512&uuid=c9835a40-047b- 11ec-ae8f-41d7ee6b2a89
First step : Create thread group
Right click on the test plan , Add thread group , Keep default

The second step : establish HTTP request
Right click on the thread group , Add sampler -HTTP Sampler , And according to the information of the interface , Fill in the agreement type 、 The server ip、 Port number 、 Request mode 、 route 、 Request parameters and other information

The third step : Create a listener
Right click on the thread group , Add listener - View the result tree ,, Click the run button in the menu bar , In this way, you can see the request and after the interface is running Return the data

Fourth 、 Assertion
By default ,Jmeter According to whether the response status code of the interface is 200 To determine whether the interface is successful , But a lot of times ,200 It can only represent HTTP Request succeeded , But it may not be successful in business . Therefore, it is also necessary to judge the returned data of the interface . So you can use Jmeter Assert to judge the returned data .
Assertions are usually directed at a HTTP Requested , Judge HTTP Whether the return value of conforms to the rules of assertion , For example, whether it contains “success” etc. , If Assertion passed ,Jmeter I think HTTP The request is successful , Otherwise, Mark as failure , Marked in red in the view results tree .
Common assertions are Json Assertions and responses .
Json Assertion
The return for the interface is json Format data , have access to json Assertion , It can judge json Whether a value in the string is as expected .
such as , After the login interface is successful , The server will return the name of this user username and nickname
{
"access_token":
"eyJhbGciOiJIUzUxMiJ9.eyJzZWxmT3BlcmF0ZWQiOjAsInN1YiI6IkNMRVJLIiwicm9sZSI6IlNVUE VSX1NFTExFUiIsImZvdW5kZXIiOm51bGwsInJvbGVzIjpbIkJVWUVSIiwiU0VMTEVSIiwiQ0xFUksiXS wic2VsbGVyTmFtZSI6IjExMSIsImNsZXJrSWQiOjE2LCJ1dWlkIjpudWxsLCJ1aWQiOjE5NjUsInNlbG xlcklkIjo0MSwiY2xlcmtOYW1lIjoibXR4LTAwMSIsImV4cCI6MTYyOTg3MDU5OCwidXNlcm5hbWUiOi JtdHgtMDAxIn0.BEnmRfCU2nfkqMwQVajaxMP5uoUtcyoAsTHMkaK_9RoHwaxS0GNUDY- 9I048wx8LX7pmyMqWl70Q4B31dlVTHw",
"uid": 1965,
"refresh_token":
"eyJhbGciOiJIUzUxMiJ9.eyJzZWxmT3BlcmF0ZWQiOjAsInN1YiI6IkNMRVJLIiwicm9sZSI6IlNVUE VSX1NFTExFUiIsImZvdW5kZXIiOm51bGwsInJvbGVzIjpbIkJVWUVSIiwiU0VMTEVSIiwiQ0xFUksiXS wic2VsbGVyTmFtZSI6IjExMSIsImNsZXJrSWQiOjE2LCJ1dWlkIjpudWxsLCJ1aWQiOjE5NjUsInNlbG xlcklkIjo0MSwiY2xlcmtOYW1lIjoibXR4LTAwMSIsImV4cCI6MTYyOTg3MTE5OCwidXNlcm5hbWUiOi JtdHgtMDAxIn0.54MSaFcXIuGexBeXY-79oO5_8tAHvmEvtbJ0qKUE9A5VpqKmbECahX4zcb_2XQEox- H0aIZX49P9ncRrH22Jgg",
"face": null,
"role_id": 0,
"founder": 1,
"nickname": "mtx-001",
"username": "mtx-001"
}add to json Assertion , Determine the number of messages returned by the server username Is it in line with expectations .
stay HTTP On the request , Right click to add json Assertion

explain :
Assert JSON Path exists: Fill in Json Path expression , among $ On behalf of the entire json,$.username Namely username Corresponding value
Additionally assert value: Whether the Json Determine the value corresponding to the path expression
Expected Value: The content of expectations , Fill in your expectations
Json Path For more detailed usage, see :https://github.com/json-path/JsonPath
Response assertion
Response assertions have a wider range of applications , As long as the returned response content is text content , Whatever the format ,HTML、Json etc. , ring It should be asserted that stay HTTP Right click on the request , Add response assertion

explain :
Test fields : Judge which part of the data , The default is the response content
Pattern matching rules : Rule of judgement , The default is to include a string
Test mode : Specific judgment content
Finally, I also sorted out some software testing learning materials , It should be very helpful for small partners learning software testing , In order to better organize each module
Need my keywords for private messages 【555】 Get it for free Note that the keywords are :555
Full set of software test automation test teaching video

300G Download tutorial materials 【 Video tutorial +PPT+ Project source code 】

A complete set of software testing automation testing factory has been

边栏推荐
猜你喜欢
随机推荐
USB rechargeable hand warmer chip dltap602sc Jericho
Aircraft battle with enemy aircraft
Product name fuzzy search:
Bathroom with demister vanity mirror touch chip-dlt8t10s
【npm】 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
Order submission
Matplotlib (basic usage)
大冤种们,新进测试行业,如何正确选择意向企业?
瑞吉外卖笔记
normal distribution, lognormal distribution,正态随机数的生成
Hash、Set、List、Zset、BitMap、Scan
The understanding of string in C.
怎样产生标准分布或高斯分布的随机数
Kinect2 for Unity3D——AvatarDemo学习
Typeerror: conv2d(): argument 'padding' (position 5) must be multiple of ints, not STR [error]
Led learning eye protection table lamp touch chip-dlt8t10s-jericho
Interceptor拦截器
Baidu map eagle eye track service
Was not registered for synchronization because synchronization is not active[resolved]
MySQL create event execution task








