当前位置:网站首页>How does JMeter implement interface association?

How does JMeter implement interface association?

2022-06-21 13:50:00 Automated test

Jmeter When used for interface test , The latter interface often needs to use the results returned by the previous interface , How to get the result value of the previous request , Applied to the latter interface , Take a login example to illustrate how to get .

1、 open jmeter, Create a new test plan , Create a new thread group in the test plan , Create a new login http request , As shown in the figure :

2、 View the results returned by login :

3、 The recharge interface can only be operated after logging in , You can use cookie The way , Verify that this user is logged in , Add... In the recharge interface cookie Manager :

there sign It is returned by the last login interface sign value ,

4、 Create a new post processor under the login request , Extract the returned result value :

 5、 View the operation results of the interface :

summary : That's all jmeter The association implementation of , If there are other interfaces that need the result of the previous request , You can also add a post processor to extract variables , Function in the last interface , Realize the dynamic change of parameters . 

Examples of regular expressions :

1、 Extract a single string :
If you want to match Web The following parts of the page :name = "file" value = "readme.txt"> And extract readme.txt. A suitable regular expression :name = "file" value = "(.+?)">.
      (): Encapsulates the matching string to be returned .
      .: Match any single string .
      +: Once or more .
      ?: Don't be greedy , Stop after first match found .

2、 Extract multiple strings :
     If you want to match Web The following parts of the page :name = "file.name" value = "readme.txt"> And extract file.name and readme.txt. A suitable regular expression :name = "(.+?)" value = "(.+?)". This will create 2 A set of , for $1$ and $2$

   such as :

     Quote name :MYREF
     Templates :$1$$2$

    The values of the following variables will be set :
    MYREF:     file.namereadme.txt
    MYREF_g0:   name = "file.name"value = "readme.txt"
    MYREF_g1:  file.name
    MYREF_g2:  readme.txt

   Where you need to quote, you can use :${MYREF}, ${MYREF_g1 To use .

When there is a dependency between requests , For example, the input parameter of one request is the data returned by another request , In this case, we need to use association processing ,Jmeter Can pass “ Post Processors ” Medium “ Regular expression extractor ” To deal with the correlation .

Simple association

For example, when visiting Baidu home page, there is one in the response data title

<title> use Baidu Search , You will know </title> I just want to quote this in other requests title

Add a regular expression extractor and set it as follows :

Add an association request to verify the Association :

After execution, we see that the association is successful

A more complex connection , Like taking multiple values in the regular expression result

For example, the response data of a request is as follows :

Let's try to extract 0.0,84956.0,1019,3 These four data , Add a regular expression extractor and make the following settings

Quote name : Reference name and reference method , Don't explain , Similar to variable parameterization .

Regular expressions : Replace all parts to be quoted with parentheses , For the specific expressions in parentheses, you can refer to the knowledge related to regular expressions separately .

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.

After setting up the regular expression extractor as above , We can add an associated authentication request , as follows :

in fact ,myref_g0,myref_g1...myref_g4 Is the result group of regular expressions , and myref Is the result extracted by template control , Here, in order to more clearly observe the result group of regular expression, so many parameters are added to the verification request , The actual use is to use a myref Just match with the template .

myref_g0={"rent":0.0,"price":84956.0,"totalprice":1019,"roomType":3}

myref_g1=0.0

myref_g2=84956.0

myref_g3=1019

myref_g4=3

1. Templates $0$

2. Templates $1$$2$

3. Templates $3$,$4$

 

In addition, for matching numbers , At present, I only see 0 and 1, There may be other cases of taking other integers , That must be a more complicated situation .

Okay This is the end of learning If you want to know more about it, please pay attention to me ! The following is a letter that Xiaobian wants to write to readers ! Remember to read carefully !

  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 away for free :
① 2000 Multiple software test eBooks ( There should be both mainstream and classic books )
②  software test / Automated test standard library data ( The most complete Chinese version )
③  Project source code ( Forty or fifty interesting and classic training projects and source code )
④ Python programing language 、API Interface automation testing 、web automated testing 、App automated testing ( Suitable for Xiaobai      

 ⑤ Python Learning Roadmap ( Farewell to bad learning ) 
The information above In my QQ In the technology exchange group ( Technical exchange and resource sharing , The ad came in and broke your leg )
You can take it by yourself , Group number 768747503 remarks (csdn999) The free information in the group is the essence of my more than 10 year test career . There is also a great God of the same trade to exchange technology
   ————————————————
「 Learning materials note Tools Document collection 」

 picture

  Scan QR code ,
remarks “csdn999”
Miss, I invite you to study together ~~
Discuss test technology with like-minded test partners !

    It must be Note the code :CSDN999
   ————————————————

 

原网站

版权声明
本文为[Automated test]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221431548978.html