当前位置:网站首页>How to realize the association between interfaces in JMeter?
How to realize the association between interfaces in JMeter?
2022-07-19 04:01:00 【Xiaowu knock code】
The connection is Jmeter A very important technology in tools . Because in the process of testing, some data is often changed , To get and use this data , We're going to use correlation .
such as : After the user logs in ,session The information is different , Some operations need to use session, You need to save this dynamic information . There are also scenes that we often encounter , The parameters submitted by the second request are obtained from the return data of the first request .
The specific methods :
One 、 Regular expression extractor
Add a thread group to the default test plan , Then add the sampler .
Right click to add post processor → Regular expression extractor , The regular expression extractor interface is as follows :
explain :
Post Processors : Play a role at the end of a request or when a response is returned
Regular expression extractor : Allow users to use... From the server's response perl The regular expression extract value of . This element acts on the specified range sampler , Extract the required value with regular expression , Generate template string , And store the result in the given variable name .
APPly to: Scope of action ( Returns the assertion range of the content )
Main sample and sub-samples: The sampler acting on the parent node and the sampler corresponding to the child node
Main sample only: Samplers acting only on the parent node
Sub-samples only: Samplers acting only on child nodes
JMeter Variable: Act on jmeter Variable ( Enter... In the input box jmeter The variable name of )
Response fields to check : The range of response messages to be checked
The main body : The body of the response message
Body(unescaped): The main body , The main content of the response and all of the html Escape character , Be careful html Escape characters are processed without regard to context , So there may be incorrect conversions , Not recommended
Body as a Document: Extract text from different types of files , Note that this option affects performance
Response Headers: Response headers
Request Headers: Request headers
URL: Uniform resource locator , namely Internet The string used to describe information resources
Response code : Response status code , such as 200、404 etc.
Response information : Response information
Quote name (Reference Name):Jmeter The name of the variable , Store the extracted results ; The value to be referenced by the next request 、 Field 、 Variable name ( What I extracted from the example is SOCIAL_NO)
Regular expressions (Regular Expression): Use regular expressions to parse response results ,“()” Represents extracting partial values from a string , Please do not use “||”, Unless you need to match the character yourself .
Common regular expression operators :
Templates : Represents the style referenced from the regular expression result , In fact, the result is a group of , Instead of a . 0 0 0 Represents all of this set of results , 1 1 1 The number one that represents this set of results 1 individual , And so on ; 1 1 1 2 2 2 Represents the... Th in a set of results of the regular expression 1 And the first 2 individual , The two ended up next to each other without a gap between them ; 3 3 3, 4 4 4 Represents the... Th in a set of results of the regular expression 3 And the first 4 individual , There is a comma between the two results .
Match the Numbers :0 Represents random... In the regular expression result group ,1 Represent all .
The default value : Display the information passed when the reference is not correct , Write one smoothly ERROR.
Last , Follow the instructions above , Complete the configuration , Then you can add a monitor first ( View the result tree ), Check whether the corresponding value is taken ; The extracted parameters , Use when calling s e s s i o n i d 1 , {sessionid_1}, sessionid1,{sessionid_2}…, If you want to get the number of matched parameters ,${sessionid_matchNr}.
Two 、json path postprocessor(JSON Extractor)
use :
The current interface response returns json Extract content from , As a variable, it can be passed in different requests . as follows , From the login interface json Extract from user id, The variable name is set to id, You can call this variable directly in other requests , Or as post Parameters . Secondary plug-in for restful The interface is very easy to use .
Variable names : name
JSONPath Expression:JSON expression
Match Numbers: Match which , It can be empty, that is, the first one is the default
Default Value: When no value is taken, the default value is
For example, the return value is as follows :
1 {
2 "userSession": {
3 "businessCode": "900000",
4 "createTime": "2018-05-25 03:24:17",
5 "userCode": "29feaa3c98014e02bec16c6f448a6459",
6 "userName": "lip-vpn",
7 "sessionId": "10a4cee035d044d8b2f25e2cebb2843e"
8 }
9}
be json Expression for :$.userSession.sessionId
If the return value is an array , You need to add the position of the array , Such as
1{
2 "userSession": [
3 {
4 "businessCode": "900000",
5 "createTime": "2018-05-25 03:24:17",
6 "userCode": "29feaa3c98014e02bec16c6f448a6459",
7 "userName": "lip-vpn",
8 "sessionId": "10a4cee035d044d8b2f25e2cebb2843e"
9 }
10 ]
11}
be json Expression for :$.userSession[0].sessionId, Extract the first value .
3、 ... and 、XPath Extractor
Jmeter The support provided for association includes the following 2 In terms of :
① It can save the specified content on the returned page in the parameter ;( Regular expression extractor and JSON Extractor)
② To be able to GET or POST The data in the method is replaced with this parameter ;(XPath Extractor)
XPath Extractor And regular expression extractor (Regular Expression Extractor) similar , It's just that Expression Is not a regular expression specified in , It's given XPath route .
Post Processors (Post Processor) In essence, it's a kind of right sampler After sending the request, the received response data is processed ( post-processing ) Methods . The postprocessor components must be placed in the right place to achieve the desired effect .
Create a new thread group , And then right-click - add to - Post Processors -XPath Extractor:
APPly to: Scope of action ( Returns the assertion range of the content )
Main sample and sub-samples: The sampler acting on the parent node and the sampler corresponding to the child node
Main sample only: Samplers acting only on the parent node
Sub-samples only: Samplers acting only on child nodes
JMeter Variable: Act on jmeter Variable ( Enter... In the input box jmeter The variable name of )
XML Parsing Options: To parse XML Parameters
Use Tidy: When the page to be processed is HTML When the format , You must check this option ; If it is XML or XHTML Format ( for example RSS return ), Then uncheck ;
Quiet Show only what you need HTML page ,Report errors Indicates that the display response reports an error ,Show warnings Indicates that a warning is displayed ;
Use Namespaces: If this option is enabled , Follow up XML The parser will use the namespace to distinguish ;
Validate XML: Check and parse according to the page element pattern ;
Ignore Whitespace: Ignore blank content ;
Fetch external DTDs: If it is checked , The outside will use DTD Rules to get page content ;
Return entire XPath fragment of text content: Return the whole content of the text XPath fragment ;
Reference Name: Parameters that store the extracted values .
XPath Query: For extracting values XPath expression .
Default Value: The default value of the parameter .
Regular expression extractors and XPath Extractor The difference between :
① Regular expression extractor can be used to extract any text from a page , The extracted content is text matching in the page content according to the regular expression ;
②XPath Extractor You can extract any attribute of any element on the returned page ;
③ If the text to be extracted is the attribute value of an element on the page , It is recommended to use XPath Extractor;
④ If the position of the text to be extracted on the page is not fixed , Or not an attribute of an element , Regular expression extractors are recommended .
Finally, thank everyone who reads my article carefully , The following online link is also a very comprehensive one that I spent a few days sorting out , I hope it can also help you in need !
These materials , For those who want to change careers 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful ……
If you don't want to grow up alone , Unable to find the information of the system , The problem is not helped , If you insist on giving up after a few days , You can click the small card below to join our group , We can discuss and exchange , There will be various software testing materials and technical exchanges .
Click the small card at the end of the document to receive it |
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 .
Self study recommendation B Stop video :
Zero basis transition software testing : Self taught software testing , Got the byte test post offer, Is the B The best video station !
Advanced automation testing : Huawei has landed , Salary increase 20K,2022 Most suitable for self-study python Automated test tutorial , Spend it yourself 16800 Bought , Free sharing
边栏推荐
猜你喜欢
随机推荐
Get to know esp8266 (II) -- build a network server to realize remote control
(21) blender source code analysis: click the mouse to add the message to the queue
How session and cookies work
dapr系列(一)
The software supply chain security risk that makes enterprise digitalization and it executives bear the brunt of the cauldron points to the north
电脑绘画软件哪个好用:试试Artweaver Plus吧,媲美sai绘画软件 | 最新版本的artweaver下载
A Tutorial on Learned Multi-dimensional Indexes
DataX DorisWriter 插件文档
go环境安装
51单片机——双字节乘以双字节
Hcip Experiment 5
Automake Chinese Manual_ incomplete
A robust deformation convolution neural network image denoising
7.16模拟赛总结
IDEA配置SFTP,SSH非常方便的部署以及定位错误日志
1255. 得分最高的单词集合 状态压缩动态规划
Explanation of Hoff transformation
Penetration test-01 information collection
Tutorial: Adaptive Replication and Partitioning in Data Systems
micro、M3O微服务系列(三)