I. Installation and deployment

1. MAC side: Download the JMeter installation package, unpack it and use it directly without setting environment variables (because JDK is installed on MAC by default)

2, Windows: download jMeter installation package, need to configure JDK environment variables, as follows:

Configure JDK environment variables

Right-click computer Properties -> Advanced System Settings -> System Properties -> Advanced -> Environment Variables -> Add the following system variables:

Variable name: JAVA_HOME

Variable value: [D: Program Files\Java\jdk1.8.0_92]

Variable name: [path]

Variable value: [;%JAVA_HOME%\bin;]

Variable name: [CLASSPATH]

Variable value: [. %JAVA_HOME% lib\dt.jar;%JAVA_HOME% lib\tools.jar;] 【. Can’t miss 】

I am using Jmeter-5.4.1, and the problems I encountered during the installation and deployment on Windows were very quick at startup and the application would not work

Solution: JMETER_HOME is configured in the environment variable. Delete this configuration and the program starts successfully

Second, script recording

Note: The HTTP proxy service is used for recording

Step 1: Set up JMeter and add a thread group and an HTTP proxy server under a test plan, as shown below:

You need to fill in the following: 1. Port (either default or custom)

2, HTTPS Domains (specify the domain name of the content to be recorded without http:// or https://)

3. Select the target controller (select the target thread group)

Step 2: Set up a browser (for example, Google Chrome on the MAC) and click Settings – Advanced – to open your computer’s proxy Settings

As shown in the figure above, check secure Web Proxy (HTTPS) on the left, enter “localhost” in the right input box, and then click “OK” to display the following page and click “Apply”

Step 3: Click on the green start button of the HTTP proxy service in JMeter and click OK in the following pop-up box

And then you go to the browser, and you can’t record, and you go to step 4

Step 4: Import certificates, open the Google browser, set — – safety management certificate, in the key string to access the page, select system, then click the upper left corner of the file, select import project, import the jmeter – bin the certificate path (ApacheJMeterTemporaryRootCA. CRT), after the success of the certificate of import, Right-click the certificate to open the Display Profile and use this certificate to select Always Trust. (Note that the validity period of the certificate is 7 days. Import the certificate again after the expiration.)

After the above configuration, you can record normally.

Third, associated

No matter in interface test or performance test, it is often the transmission of the next interface that uses the value of the response data of the previous interface. At this time, the value of the response data needs to be extracted. Here we introduce two methods: regular expression extraction and Jason extraction

1. Regular expression extraction

Click Add – Post-processor – Regular Expression Extractor under the request

1) Name: Can be set at will

2) Note: It can be set arbitrarily

例 句 : Leave it alone and use the default selection to APPly to the assertion scope of the returned content.

Main sample and sub-samples: The matching range includes the current parent sampler and overwrites the child sampler

Main sample only: The matching range is the current parent sampler

Sub-samples only: Matches only child samplers

JMeter Variable: Matches the values of JMeter variables

4) Field to check: the range of response packets to be checked (the most commonly used is the first one, which is basically left untouched)

Body: indicates the body of the response packet

Body(unescaped) : The Body of a response that has replaced all HTML escape characters, however, is not recommended because HTML escape characters are escaped without context

Body as a Document: Extracts text from different types of files. Note that this option may affect performance

If you are using Jmeter (Chinese version), you will see that this item is a message header.

Request Headers: Indicates the Request Headers

URL: request URL

Response Code: indicates the Response status Code, such as 200 or 404

Response Message: Indicates the Response Message

5) Reference name: variable name when referenced elsewhere, can be customized, reference method: ${reference name}

6) Regular expressions: Data extractors, () parentheses are the values you want to get. Token “: Extracted boundary content. And in parentheses. Plus? Is a regular expression used to match the data to be obtained

7) Template: Multiple templates can be set for matching, 111 refers to the first template, 222 refers to the second template, and so on, 000 refers to full text matching

8) Matching numbers: All the results of the regular expression matching data can be regarded as an array, and the matching number can be regarded as the number of elements in the array. Minus 1 is all, 0 is random, 1 is the first, 2 is the second, and so on. Usually you just fill in 0

9) Default value: the default value when the match fails. I don’t have to write it. To use this parameter for subsequent logical judgment, simply write it as ERROR.

The following are common regular expression operators

2. JSON extractor

Click Add – Post-processor – JSON Extractor under the request

1) Name: Can be set at will

2) Note: It can be set arbitrarily

例 句 : Leave it alone and use the default selection to APPly to the assertion scope of the returned content.

Main sample and sub-samples: The matching range includes the current parent sampler and overwrites the child sampler

Main sample only: The matching range is the current parent sampler

Sub-samples only: Matches only child samplers

JMeter Variable: Matches the values of JMeter variables

4) Names of created variables: Custom variables that receive values, separated by semicolons

5) JSON Path expression: JSON Path expression, also separated by semicolons ($indicates the root element, and then goes down the list of attributes until the desired element is found)

6) Match No.(0 for Random) : 0 indicates Random; N takes the matching value; -1 matches all. If only the first matching value is obtained, enter 1

Compute concatenation var(suffix_ALL): If many results are found, the plug-in concatenates them using the ‘, ‘delimiter and stores them in a var named _ALL

Default Values: The Default value. If no value can be matched, take this value and write error.

3, the Debug PostProcessor

The above two are extraction methods, but how to see if there is extraction, need to use the debug post-handler

On the thread, click add – PostProcessor – Debug PostProcessor

The Settings are basically unchanged, just use the default Settings

Out Debug PostProcessor: All requests are the previous requests to the Debug PostProcessor, and the Debug PostProcessor can obtain all test plans, user-defined variables, parameterized variables, and variable data generated by the request before the current request. The variables generated by the pre – and post-processor definitions in the request cannot be retrieved.

Inner Debug PostProcessor: The current request is the previous request of the current thread. It can obtain all test plans, user-defined variables, parameterized variables, variable data generated by the request, and variable data generated by the current request.

With this can see whether the extracted data has been extracted, convenient to find the problem

4. Parameterization

Click Add – Configure Component – CSV Data Set Config in the thread

1) File name: path of a new CSV file. In version 4.0, you can click the Browse button on the right to select the file, and the absolute path of the file will be automatically added. In addition, when the CSV file is in the bin or script directory of JMeter, you only need to specify the name of the file (note that CSV files are strictly formatted with no Spaces or blank lines).

2) File code: UTF-8

3) Variable name: the name of each column in the CSV file (if there are multiple columns, separate the column names with commas); The name order must correspond to the content, and the variable name is required because it is referenced elsewhere

4) Ignore the first line: if the first line of the CSV file is the name, not the content, select ‘True’, if the first line is the content, not the name, select ‘False’

5) Delimiter: the default is English comma, other can also, but the CSV file must be corresponding to this

6) Whether quotation marks are allowed: default is’ False ‘

7) Loop again on end of file: default ‘True’

8) Stop thread at end of file: default is’ False ‘

9) Thread sharing mode: Depending on the situation, I use the current thread group

Set the number of threads to complete the execution of the data in the CSV file, generally how many lines, how many threads can be set

Logical controller

1. The while controller

The While Controller runs until the Condition is false

The possible values of Condition are as follows:

(1) is null (no value is entered) — the loop will not exit until some sample execution fails

(2) LAST — The loop will not exit until the LAST sample request fails

(3) Other — exit the loop if the conditional value is equal to the string “false”(equivalent to entering false in the input box)

Writing conditional values is usually used in conjunction with function assistants, as shown below

Perform the operations shown in figure 1-3 to get 4. Just copy the expression shown in 4 and place it in condition

2. If controller

Conditional writing is also used in conjunction with function assistants, as above

Six, Beanshell

Beanshell postprocessor is mainly used in the process of pressure measurement

1. What is BeanShell?

BeanShell is a scripting language that fully conforms to the Java syntax specification and has some syntax and methods of its own.

BeanShell is a loosely typed scripting language;

BeanShell is written in Java, a small, free, downloadable, embedded Java source code interpreter with object scripting features;

BeanShell can execute standard Java statements and expressions, as well as some of its own scripting commands and syntax.

2. BeanShell commonly uses built-in variables

(1) vars.get(” a “) to get the value of variable A from Jmeter

(2) vars. Put (“b”, “c”), data is stored in jmeter variable B from variable C

(3) log.info(“message”); Print log

(4) System.out.println(“Hello, World”); Print to Jmeter’s console

(5) the prev. GetResponseDataAsString () : get the sample in front of the response information

(6) prev.getresponsecode () : Obtain the previous sample response code

(7) prev.setStopThread(true)

3, use,

Seven, assertions

There are a lot of assertions, often used is response assertion, mainly to judge whether the request is successful, generally used in combination with the view result tree, response data in line with the set matching rules, the view result tree request is green words, conversely, the request is red, convenient to check which request did not pass

8. Set the number of threads

Set the number of threads, ramp-up time (s), and cycle times

Number of threads: number of concurrent threads

Ramp-up time (seconds) : Determines how long to start all threads. If the number of threads is set to 10 and the ramp-up period is set to 100 seconds, JMeter takes 100 seconds to get all 10 threads up and running. Each thread starts 10 seconds (100/10) after the previous one. If the number of threads is set to 10 and the ramp-up period is 0 seconds, then 10 requests are made simultaneously.

Number of cycles: custom Settings or always

For example, if we set the number of threads to 100 and the ramp-up time to 10 seconds, we would use a synchronization timer if we wanted every 50 users to log in at the same time:

Number of emulated user groups: the number of threads released to the collection point can be set to 50

If the timeout period is set to 0, the thread will wait for the number of threads to reach the set value before releasing. If the number of threads is less than the number set in the collection point, it will be waiting forever.

If the set time is greater than 0, then if the value set in the mock user group has not been reached after the set maximum wait time is exceeded, the thread group will no longer wait and the thread that has arrived will be released.

Nine, reports,

General performance testing uses aggregate reports to collect data

1. Name and comment: custom

2. File name: The execution result log is stored in this file. What can be set on the configuration button to display log content

3, list

Label: The name of the request, which is the name of the Httprequest Sampler we are testing

Samples: The total number of requests sent to the server. If 10 users are simulated and each user loops 10 times, the total number of requests is: 10*10 =100;

Average: indicates the Average response time of a single Request by default

Median: Response time of 50% of users’ requests

90% percentile (90%Line) : Response time for 90% of requests

95% percentile (95%Line) : Response time for 95% of requests

99% percentile (99%Line) : Response time for 99% of requests

Minimum (Min) : indicates the minimum response time

Max: indicates the maximum response time

Exceptions (Error%) : Error rate = number of incorrect requests/total requests

Throughput: By default, Throughput is the number of requests processed per second

Received KB/ SEC: indicates the amount of data Received from the server per second.

Sent KB/ SEC: Number of requests Sent from the client per second.

Ten. Problems encountered in pressure measurement

1. After the team is assigned, the state of the list does not change, or is not assigned, because the list is not allocated until the state becomes unassigned

Solution: add a waiting time before accessing the assignment team interface to ensure that the status of the task changes to unassigned or add a loop controller on the assignment team interface and set the loop twice

2, get the audio, do is to get the first two audio, but in concurrent, two people get at the same time, someone will not get

Solution: Each person gets two at random

3, written in beanshell script to receive audio, has been an ERROR (the 2021-06-17 15:28:33, 619 ERROR O.A.J.U.B eanShellInterpreter: ERROR invoking BSH method: Eval In file: inline evaluation of: ‘ ‘//String STR =””; //for(i=1; i<3; I++){// String audioid = vars.get(“aud… “” non-operative “=” at line 21, column 22″)

Error:List result = new ArrayList();

Reference book: JMeter Actual Combat of Full-stack Performance Test