The best in the entire network, Jmeter interface automated testing implementation steps from 0 to 1 (detailed arrangement)


Preface

1. Tool download

Download and install JDK 1.8;
download and install Apache tomcat;
download and install JMeter tool;

I have written about tool installation before, so I won’t go into too much detail here.

2. Software installation and setting environment variables

JDK:
The installation directory is in C:\Program Files\Java, and its environment variable is set to:
JAVA_HOME value is: C:\Program Files\Java\jdk1.7.0_21;
CLASSPATH value is: .;%JAVA_HOME%\lib;
Path value For: %JAVA_HOME%\bin;

J meter:

Step 1: Unzip the file to the c drive. Unzip this article to the C:\jmeter directory.

Step 2: Select "My Computer" (right-click)/Advanced/Environment Variables on the desktop, click "New" in the "System Variables" column, enter: JMETER_HOME in the variable name, enter: C:\JMeter in the variable value , click OK.

Step 3: Modify the CLASSPATH variable again and add the following value to the variable value:

%JMETER_HOME%\lib\ext\ApacheJMeter_core.jar;%JMETER_HOME%\lib\jorphan.jar;%JMETER_HOME%\lib\logkit-1.2.jar; 

Then confirm.

Step 4: Check whether the Jmeter installation is OK.
Enter the bin folder C:\jmeter\apache-jmeter\bin in the Jmeter directory, click jmeter.bat, and check the page display. If the Jmeter operation page can be displayed, the installation is successful.

3. Jmeter interface automation steps

1) Add a thread group: Right-click on "Test Plan"->Add->Thread (User)->Thread Group

Insert image description here

Insert image description here

The number of threads is generally the same as the number of data items in the csv file.

2) Create a new user-defined variable in the test plan-add-configuration component-user-defined variable. You can define the domain name and port of the project in it, so you don’t have to fill them in for each interface later.

Insert image description here

Insert image description here

3) Create a new http default request value and go to Test Plan – Add – Configuration Component – ​​http Default Request Value.

Insert image description here

Insert image description here

Insert image description here

IP and port can be used in the defined variables

4) Add a result tree, go to test plan – add – listener – view the result tree.

Insert image description here

5) Create an http request under the thread group, and go to the thread group – add – sampler – http request. You need to fill in the request method, interface path, and encoding. Fill in the input parameters in the message body data. The specific value can be the data in the csv file.

Insert image description here

Insert image description here

6) Add http information header management, go to thread group – add – configuration element – ​​http information header management. The content inside is defined by the interface document. Fill in whatever values ​​are needed for the headers. However, if the request data is in json format, content-type must be filled in.

Insert image description here

7) Add csv data file settings in thread group – add – configuration element – ​​csv data

Insert image description here

Insert image description here

File name: the path to the csv file, file encoding: if there is Chinese in the file, choose utf-8, variable name: one-to-one correspondence with each column in the file.

8) Add assertion, in thread group-add-assert-json assertion.

Insert image description here

Use the interface extracted by json expression to return the value in the result;
for the expected value, use variables to get the expected value in the csv file, and then make assertions.

4. Solving interface dependencies

For example, other interfaces rely on the login token
1) Create a new setup thread group, and go to test plan – add – thread (user) – setup thread group.

Insert image description here

2) Create a new http request, in the setup thread group – add – sampler – http request

Insert image description here

The data in the message body can be defined in user-defined variables and can be accessed directly by taking the variable value.

3) Create a new json extractor and obtain the token. In http request – add – post processor – json extractor

Insert image description here

Variable value naming;
json expression, extract token from the information returned by the login interface

4) Create a new Beanshell post-processor to make token a global variable. In http request-add-post-processor-Beanshell post-processor

Insert image description here

The expression in the figure is; set token as a global variable and name it Token

5) Other interfaces that need to rely on tokens can be set in the http information header management and can be accessed.

Insert image description here

The following is the most comprehensive software testing engineer learning knowledge architecture system diagram in 2023 that I compiled.

1. Python programming from entry to proficiency

Please add image description

2. Practical implementation of interface automation projects

Please add image description

3. Web automation project actual combat

Please add image description

4. Practical implementation of App automation project

Please add image description

5. Resumes of first-tier manufacturers

Please add image description

6. Test and develop DevOps system

Please add image description

7. Commonly used automated testing tools

Please add image description

8. JMeter performance test

Please add image description

9. Summary (little surprise at the end)

Don't be discouraged by setbacks, don't give up by failure. Every effort is a step towards success, and every effort will gather into a brilliant future. Keep your faith and move forward bravely, and you will surely create your own great miracle!

The road to success is often full of hardships, but as long as you ignite your inner passion and pursue your dreams relentlessly, you will eventually reach the pinnacle of success. Believe in yourself and move forward!

Life is like a flower, struggle is to bloom your own beauty. No matter how difficult the road ahead is, keep moving forward, persist in your dreams, and be perseverant, and you will shine with your own brilliant light! Believe in yourself and fight bravely!

Guess you like

Origin blog.csdn.net/m0_70102063/article/details/133383134