Jmeter-http interface test script

The main steps in jMeter’s HTTP interface testing (1. Add thread group 2. Add an HTTP request. 3. Add the URL, path, request mode, and parameter 4 to the HTTP request. Add view result tree 5. Call interface, check return value)

Add headers for interfaces in the following ways:Copy the code

Jmeter does HTTP interface test add cookie:

3. The jmeter – webservice script

General steps for conducting webservice tests

1. Create an existing SOAP item on soapUI, import the WSDL address, and obtain the request message, SOAPAction, and request URL.

Open JMeter and create a new thread group

3. Create a SOAP/XML-RPC Request

Add the URL, SOAPAction, and request message to soapRequest.

4. Jmeter – parameterized

Parameterization is used when calling an interface input parameter. Sometimes parameters are required to change frequently, and if it becomes tedious to change each time, you need to change the frequently changing values into a pre-edited document or function so that different values can be used when calling.

Jmeter can be parameterized in three ways:

1) User-defined variables (this is for the convenience of managing parameters, can only have one value, such as IP address does not change often).

Add a user-defined variable to the thread group, and write key and value. Key is the name of the parameter, which is the value you took in the script, and value is the specific value. When taking parameterized values, use ${name}, where name is the name of the variable you are taking.

Get parameterized values in the script

2) Function generator (function generator can generate data according to certain rules, such as generating some random numbers).

Function assistant, you can generate some parameters in accordance with the rules, such as random number to take the current time, the most commonly used is these two.

A random number, __Random, can take a random value within a range that you specify

The date format is yyyY-MM-DD HH: MM :ss. The date format is yyyY-MM-DD HH: MM :ss. The date format is yyyY-MM-DD HH: MM :ss

Take a unique ID, __UUID, which generates a random UUID each time, which is unique.

Function assistants can be used to generate parameters according to rules.

3) Read from the file (file reading is to write some data in advance, and then read from the file, so that, for example, login interface, account and password are registered in advance)

There are three steps to reading from the file:

1. Read the file

2. Take the parameter in the file content and give it a name

3. Use values (to read from a file, add a CSV Data Set Config to the thread group, which does the previous two steps).

5. Jmeter assertion

The purpose of an assertion is to check whether the return result is correct. If it is correct, the return value of the request is correct. If it is not, the return value of the request is different from what we expected.

6. Jmeter

The association function is to save and pass in the value for later use because the result returned by the previous server is needed for later operations.

Associations in Jmeter are typically done through regular expression extractors (or if you have a special JAR package)

${name} is the name of the variable you set at the time of the association.

7. Jmeter operates mysql

Steps to operate the database:

  1. Import the JDBC JAR package. Because JMeter cannot connect to mysql directly, you need to import the jar package from a third party to connect to mysql.

Create database connection configuration, mysql URL, port number, account, password

3, write SQL, execute SQL

4. View the results

Jmeter imports the JDBCJAR package

Configure mysql connection

(1) Add a JDBC Connection Configuration

Mysql > select * from pool where id = 1

(3) the database url: JDBC: mysql: / / 192.168.1.116:3307 / bugfree? allowMultiQueries=true

(4) database driver: this is to specify what type of database connection, mysql, Oracle, SqlServer, etc.

(5) Account password

Jmeter execute SQL

Viewing SQL results

8. Run the JMeter pressure test in Linux

When we do the test, sometimes we have to run for a long time. The test server used by the company is usually Linux, so we can run it under Linux. Linux does not have a graphical interface like Windows. To run Jmeter in Linux, run the jmeter.sh shell script in the bin directory of Jmeter.

Jmeter. sh -n -t a.jmx -l res.jtl

-n means no graphical interface, -t means test script, a.jmx is our jmeter script, -l means test result res. JTL is the test result file, to view the result, import the res. JTL in the view result tree view to view the test result

9. Jmeter adds load machines

During the pressure measurement, there may be a large amount of concurrency, and one machine can no longer start so many concurrent processes. At this time, we need to use multiple machines to send pressure together, so we need to add presses. How to add presses? Then add the IP of the press on the machine as the control machine.

Jmeter bin directory has a jmeter-server, start it, Windows as a press, run jmeter-sever. Bat, Linux as a press, run jmeter-server.

The jmeter configuration file is in the bin directory jmeter.properties. When adding the press, go to the remote_hosts configuration file and add the IP. Then restart JMeter to see the remote press

Jmeter add press:

1. Start the jmeter-server (jmeter-server. bat Windows) (Jmeter-server

2. Modify the jmeter configuration file on the host and locate remot_hosts. Then add IP load machine to good remot_hosts = 127.0.0.1, 192.168.1.2 instead: 1099192168 1.3: the default jmeter server port number is 1099-1099, if the load on the port number changed, then you have to change here

3, when starting to select remote all run PS: if there is a parameterized file, then in the same position of the load machine must also have a parameterized file.