当前位置:网站首页>CSDN salary increase technology - learn about the use of several common logic controllers of JMeter

CSDN salary increase technology - learn about the use of several common logic controllers of JMeter

2022-07-07 09:40:00 Test Architect Bei fan

Preface :

jmeter Logics are the necessary knowledge for every test bird , Here are a few commonly used .

【 At the end of the article, we will prepare a lot of benefits 】

1、 Simple controller  

   effect : Used to combine sampler and other logic controllers

 1.1 Create a simple controller , route : Thread group --> add to --> Logic controller --> Simple controller

  

   1.2 After adding the controller , A sampler can be added to the controller HTTP request , There will be no interaction between the added requests

  1.3 Run the simple controller , After running, you can see , Each added HTTP Request to run from top to bottom

 

 2、 Random controller

   effect : As the name suggests, it is under this controller HTTP Randomly choose one of the requests HTTP Request to run

  2.1  Create a random controller , route : Thread group --> add to --> Logic controller --> Random controller

  2.2 Add several under the controller HTTP request , And run , Running results : All under the controller HTTP Requests are running , But the order is not top-down , It's random

   2.3 Other controllers are included under the random controller , Uncheck 【 Ignore sub controller blocks 】, If it comes to the controller randomly , Will execute the entire controller

  2.4  Other controllers are included under the random controller , Check 【 Ignore sub controller blocks 】, If it comes to the controller randomly , Only one request under the sub controller will be executed

3、 Random sequence controller

  effect : Similar to simple controller , The sampler request under each child node will be executed once , But the execution is random

  3.1 Create a random controller , route : Thread group --> add to --> Logic controller --> Random controller

  3.2 Add several under the controller HTTP request , And run , Running results : Only one of these requests was run

4、 Only once the controller

  effect : In a multithreaded loop , The sampler request under its child nodes will be run only once

  4.1 Create a controller only once , route : Thread group --> add to --> Logic controller --> Only once the controller

  4.2 Add several under the controller HTTP request , And run

  4.2.1 Number of threads 1, loop 1: Each request under the controller runs only once

  4.2.2 Number of threads 5, loop 1: Each request under the controller executes 5 Time

  4.2.3  Number of threads 1, loop 5 : Each request under the controller runs only once

5、 Circulation controller

  effect : The sampler request under the controller can run circularly

  5.1 Create a loop controller , route : Thread group --> add to --> Logic controller --> Circulation controller

   The thread group is set to 1, The number of cycles is 1  

  

   5.2 Set the number of cycles of the cycle controller to 3

   cycles (Loop Count): Enter the number of cycles in the input box , The request under the controller can run circularly

   forever (forever): If this item is checked , Then the request under the controller can run all the time

  5.3 Add several under the controller HTTP request , And run , Running results : take http The request is executed three times in sequence , Execute once at a time ( A concurrent )

6、Switch controller

  effect :Switch The controller gives the Value assignment , To specify which sampler to run . There are two ways to assign values :

  • The first is numerical ,Switch The child nodes under the controller are from 0 Start counting , Determine which element to execute by specifying the value of the child node .
  • The second is to specify the name of the child element directly , For example, the of the sampler Name To match . When the specified name does not exist , No elements are executed .
  • When Value It's empty time , By default, the second step is executed 1 Child node element . 

  6.1 establish Switch controller , route : Thread group --> add to --> Logic controller -->Switch controller

  6.2 Add several under the controller HTTP request , And run

  6.2.1 switch value It's empty , Default execution switch The first request under the controller

 

  6.2.2 switch value by 2, perform switch The... Under the controller 3 A request ( Because from 0 Start counting )

  6.2.3 switch value by 6, perform switch The... Under the controller 1 A request ( Because from 0 Start counting , Out of range , Default to the first )

   

 6.2.4 switch value by demo_switch_02, perform switch The sampler under the controller is named ”demo_switch_02“ Request

7、ForEach controller

  effect :ForEach Controllers are generally used with user-defined variables . It reads a series of related variables in user-defined variables , The sampler or controller under the controller will be executed one or more times , Read different variable values each time .

Parameters :

  • Input Variable Prefix: Input variable prefix ---- Is to define the name of the user variable
  • Output variable name: Output variable name ---- Function on interface value
  • Start index for loop(exclusive): The index at the beginning of the loop ( If you don't fill in here , The default from the 1 Start , without 1 The starting variable , Error will be reported during execution )--- from X The variable of sequence number starts
  • End index for loop(inclusive): The index at the end of the loop ( When the set variable index is exceeded , Only execute to set the index of variables , No further execution )
  • Add”_”before number: Enter whether to use... In the variable name “_” Carry out interval .

  7.1 establish ForEach controller , route : Thread group --> add to --> Logic controller -->ForEach controller   

  

  7.2  Add user-defined variables as input parameters of the interface , Path is : Thread group --> add to --> The configuration element --> User defined variables

   

 

  7.3  Set various parameters of the controller , And change the path of the sampler to variable form :${baby}

 

  7.4 Running results : Bring the set user variables into the request in turn , Three user variables are substituted into the request three times

 

8、While controller

  effect : Run the sampler under its child nodes / controller , Until the condition is “ false ”

Condition(function or variable): Conditions ( Function or variable ): The conditions on which the judgment is based can be filled , Refer to the usage , Possible conditional values are :

  ①. blank : The last example exits the loop when the loop fails

  ②. Last value : The last example exits the loop when the loop fails . If the last example before is just a loop failure , Don't go into the cycle .

  ③. otherwise : Exit time ( Or no input ) The loop condition is equal to the string “  false  ”

The condition can be any variable or function , Finally equal to string ”  false  ”. It should be noted that : The condition is to evaluate twice , Before one sampling , One random sampling

  8.1 establish While controller , route : Thread group --> add to --> Logic controller -->While controller

  

  8.2  Do not fill in while Conditional value

·  

     8.2.1 The first request failed , Running results : The first request failed , Subsequent requests continue to be executed and the cycle execution is not broken

    

    8.2.2 Intermediate request execution failed , Running results : Intermediate request execution failed , Subsequent requests continue to be executed and the cycle execution is not broken

  

·    8.2.3 The last request failed , Running results : The last request failed , Subsequent requests are no longer executed circularly

  

  8.3  while The condition value is LAST

  

    8.3.1 While The last sampler under the controller failed to execute , Out of the loop

    

    8.3.2  While The previous example of the controller failed to execute , Will not enter While Loop through the following child nodes

    

9、Runtime controller

    effect : Control operation once runtime Time of all samplers under the controller

  9.1 establish Runtime controller , Setup time 6 second , route : Thread group --> add to --> Logic controller -->Runtime controller

  9.2 Add several under the controller HTTP request , And run , Running results :

10、 If (If) controller

  effect : According to the value of the given expression, decide whether to execute the child node under the node , By default javascript The grammar of .

Parameters :

  • Conditions ( Default JavaScript)(Expression: Use JavaScript Function or variable to evaluate whether the condition is true or false
  • A condition is interpreted as a variable expression (interpret condition as variable expression): If this item is checked , It will be expression Evaluate the variable expression in , And with “ture” or “false” Compare , Without having to use JavaScript----- Such as _groovy function
  • Execute on all sub conditions (evaluate for all children): If this item is checked , Then the controller performs expression judgment once before each child node executes ;
  • By default , The controller can execute all the runnable elements contained below it , But only once at the entrance

  10.1 establish Runtime controller , route : Thread group --> add to --> Logic controller -->Runtime controller

  

  10.2 Use the function assistant to add IF Conditions , route :Tools---> Function Assistant dialog

  

   adopt 【 Choose a function 】 Find the function to use , And then in 【 Expression evaluation 】 Write the equation you need to use , Click on 【 Generate 】 You can get a complete expression

   

  10.3 Copy and paste the expression generated by the function assistant into if (If) controller , Because it's string comparison , So adjust the expression to ${__groovy("${istrue}"=="1",)}

  10.4  add to BeanShell Sampler , Add a script vars.put("istrue","1");---- take istrue The variable is set to 1

  vars namely JMeterVariables, operation jmeter Variable , This variable actually references JMeter Local variable container in thread ( Essentially, Map), Common methods :

  • vars.get(String key): from jmeter Get the value of the variable ;
  • vars.put(String key,String value): Data stored in jmeter variable ;

   10.5 Add one HTTP request , Running results , perform if Under the controller HTTP request

  10.6  take BeanShell The value in the sampler is changed to 2( That is, the controller condition is not satisfied ), Run again , Running results : Don't execute if Under the controller HTTP request

11、CSV Data file settings

  11.1 Add one CSV Data files , Path is : Thread group --> add to --> The configuration element -->CSV Data file settings

  

  11.2  Create a new one TXT file , Renamed as basedata.csv, Add fields and interface related data after opening , Choose to use the name to query the student interface , Specify the name of the interface input parameter 【name】

    

  11.3  CSV Data file settings : 

    1. adopt 【 file name 】 Dexter 【 Browse 】 Built before key import basedata.csv file

    2. File code selection : edit

    3. The variable name is basedata.csv Values of variables in the file

    4. Ignore the first line selection :True

  

  11.4  add to HTTP request , Parameterize all request parameters ${xxx}, Fill in the parameter names in sequence

  

  11.5 Set the number of cycles in the thread group to 6, Running results :basedata.csv Only 4 Data , Successful cycle 6 Time , The first 1、2 Duplicate data

 

   a key : Learning materials of course, learning is inseparable from materials , Of course, here is also prepared for you 600G Learning materials

Required first Focus on Then private my keyword 【000】 Get it for free Note that the keywords are :000

doubt : Why pay attention first ?    return : Because if you don't pay attention, you can't see the private letter

Project practice

app project , Bank Project , Medical Project , Online retailers , Finance

Large scale e-commerce projects

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

python automated testing ++ A complete set of templates + Performance testing

It's said that the iron juice who has paid attention to me for three consecutive years has been promoted, raised and made a fortune !!!!

原网站

版权声明
本文为[Test Architect Bei fan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070659055046.html