当前位置:网站首页>Jmeter- (II) basic interface and common components for interface testing

Jmeter- (II) basic interface and common components for interface testing

2022-06-25 21:18:00 Hello, test

Preface :

This is mainly about Jmeter test http Interface , Common components involved , Include :

        ( One ) Basic interface and component concepts

        ( Two ) Common configuration components

        ( 3、 ... and )HTTP Request standard components


( One ) Basic interface and component concepts

1. test plan : It's using jmeter The starting point for testing , It's something else jmeter Containers for test elements

2. Thread group : Represents a certain number of concurrent users , It can be used to simulate the sending request of concurrent users . The actual request content is in the thread group -> Defined in the sampler , It is contained by the thread group , This can be done in the test plan --> add to --> Thread group to create

Parameter interpretation :

Number of threads : Maximum number of threads used in the test , The default is 1, It can be used to set the number of concurrent users .

Ramp-Up Period : Jmeter Time to reach the specified maximum number of threads .

① 0 Concurrent on behalf of ;

②  If the number of threads is 3, The required duration is 3S, be 3/3=1  every other 1S Start a thread ;

③  General Settings Ramp-Up= Number of threads , Then adjust it up and down to the desired .

cycles : If it is Forever, The threads in the thread group will continuously test the system , Of course, you can also set the number of tests per thread , When the specified number of times has been completed , The thread will automatically exit the thread group .

Scheduler : It is mainly used to specify some time information of the test , For example, from what time to what time to run the test , If the test is not completed at the specified time , The test will also be stopped ( This is rarely used )

( Two ) Common configuration components

test http Interface request , You need to add a definition first header Related components :

1. HTTP Header Manager :

        HTTP The header manager allows you to customize JMeter stay HTTP What message does the request message send . The message header includes something like "User-Agent", "Pragma", "Referer" Equal attribute .

        HTTP The header manager is like HTTP Cookie The manager is the same , If you don't want to be different in your test for some reason HTTP The request object specifies a different header , Can be added to the thread group level .

         Select Add --> The configuration element -->HTTP Header Manager         

Parameter interpretation

name / notes : You can customize .

Message header : You can add interface parameters by yourself , Set the corresponding name and value .

         It needs to be said here , If R & D does not provide relevant header information , We can also open the console ourselves ,F12( Developer model ) Go down and get it !!

 2. HTTP Cookie Manager

         Unless your application explicitly does not use Cookies, Almost all web applications use cookie Support . You want to add cookie Support , You can simply add one to each thread group in your test plan HTTP Cookie Manager . This ensures that each thread group has its own cookies.

         add to HTTP Cookie Manager , Simply choose this Thread group , Select Add --> The configuration element -->HTTP Cookie Manager , You can also add from the edit menu or by right clicking .    

         It needs to be said here , If R & D does not provide relevant header information , We can also open the console ourselves ,F12( Developer model ) Go down and get it !!

 3. User defined variables : Select sampler , Right click : add to - The configuration element - User defined variables

      It usually parameterizes the values common to the whole thread , It is easy to maintain later , If there are changes, you do not need to modify each interface one by one .

( 3、 ... and )Http Request standard components

We have already introduced the basic components , Next, we can add interface requests under the thread .

1. HTTP request : Thread group -> Sampler ->http Request add

explain : Some interfaces have no message body , You need to directly transfer parameters on the interface path , In this case, we can directly add interface parameters .

2. Response assertion : Mainly used to judge http Whether the request is called successfully , This and http The request is standard . Add a path :http request -> Assertion -> Response assertion add

Parameter interpretation :

Test fields : Select the location where you want to judge the content , For example, the response header information is used to determine whether it is successful , This can be selected according to your own needs .

Matching specifications : The literal meaning is easy to read , Choose exact match or include, and so on ...

Test mode : This is the real judgment condition , Be consistent with the response information of the interface , If there is no match, the interface call fails .

3.  The regular expression extractor gets : The main user obtains the parameters returned by the interface , Next to get token For example

     Add location : Post Processors - Regular expression extractor

  name + notes : It is not necessary to modify , Just for the convenience of self identification

Fields to check : Main body, etc , Generally, we choose the subject , That is, the main body information of the page returned by the server

  【 Quote name 】: Is the parameter name , Quote elsewhere ; Such as the input TOKEN, Use when quoting elsewhere ${TOKEN}

  【 Regular expressions 】: Expression () The contents in the are to be extracted . Such as "token": "(.+)", "userUpdate", Expression lookup token/ What follows the string , Until the first user End of time ;( Note the extracted content in parentheses )

             (): The enclosed part is to be extracted .

    .: Match any string .

     +: Once or more .

     ?: Stop after first match found .

  【 Templates 】: use $$ To quote , If there are multiple regular expressions in a regular expression ( What's in brackets ), It can be $1$( Indicates that there is only one set of data ),$2$ wait , Represents resolved to 1 individual 、 The first 2 Give a value to mysid

  【 Match the Numbers 】:0 Represents a random value ,-1 On behalf of all ,1 Represents all values

  【 The default value 】: If the parameter does not get a value , Then use the default value here

4. Commissioning the samplers : The main user prints the parameter values obtained , Convenient for debugging

Add location : Thread group -> Sampler -> Commissioning the samplers

5. Look at the fruit tree : Used to view the returned results of the interface , It can be used directly after adding without configuration .

Add location : Thread group -> Monitor -> View the result tree

Hello Test, So far we jmeter That's all for the basic components of , According to this document, we should be able to write a simple http Interface test script , Let's try it ~~ The following screenshot was written by me The user login -- Get login token-- A new user Script for , You can refer to the structure , In the next chapter, I will introduce how to write a simple script for creating a new user , Everyone pays attention in time , finger heart ~

原网站

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