当前位置:网站首页>How to realize the association between interfaces in JMeter?
How to realize the association between interfaces in JMeter?
2022-07-19 10:20:00 【Test Xiaona】
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$ Represents all of this set of results ,$1$ The number one that represents this set of results 1 individual , And so on ;$1$$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$,$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 ${sessionid_1},${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 , Watching the rise and attention of fans all the way , Reciprocity is always necessary , Although it's not very valuable , If you can use it, you can take it

These materials , For doing 【 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 experience it again, you can't find information when you study on your own , No one answers the question , If you insist on giving up after a few days , You can add mine below qq Group discussion and Exchange , There are also various software testing materials and technical exchanges .
边栏推荐
猜你喜欢

押注.NET 是件好事

卫星网络中基于时变图的节能资源分配策略

Network Security Learning (Qianfeng network security notes) 1-- building virtual machines

【MySQL】MySQL的增删查改(进阶)

半监督学习在恶意软件流量检测中的应用

SSH連接華為ModelArts notebook

自己创建的模块 使用cmd打开报 ModuleNotFoundError: No module named 解决方案

华为昇思MindSpore详细教程

【OpenCV 例程200篇】233. 区域特征之矩不变量

Packet knowledge
随机推荐
What is pytest? Automated testing is a must
Cmake -- Notes
Three.js基本元素使用
Packet knowledge
Overview of 6G oriented smart reflector wireless communication
【附下载】带你使用frp实现内网穿透详细教程!
ty_ Gr551x code framework
vc查看内存泄漏
Microsoft OneNote 教程,如何在 OneNote 中插入数学公式?
[C language] shallow selection, circular statements, functions and arrays
2022-07-16: what is the output of the following go language code? A:[]; B:[5]; C:[5 0 0 0 0]; D:[0 0 0 0 0]。 package main imp
pfSense配置Tailscal站点到站点连接
Blender数字孪生制作教程
[separate hyperimage classification platform] use those exciting models in deep learning to build an image classification platform
中科磐云—D模块web远程代码执行漏洞解析
Flink入门到实战-阶段五(处理函数)
ty_gr551x 代码框架
TLS four handshakes
机械臂速成小指南(零点五):机械臂相关资源
HCIA RIP实验 7.11
