Jmeter (twenty-seven) - From entry to proficiency - Jmeter Http protocol recording script (detailed tutorial)

1 Introduction

The recording function of LoadRunner makes performance test script writing an easy task for people who do not understand code. However, because LoadRunner is expensive and bulky, it is rarely used by ordinary enterprises unless it is necessary. As the king of performance testing, Jmeter also provides a recording function. In addition to the HTTP proxy method provided by Jmeter, the recording principle is to parse network data packets and package them into Http Request, Http Response and other objects according to the HTTP protocol. These objects are things that we can clearly and conveniently recognize.

2.Jmeter configures the agent for recording

2.1 Browser configuration proxy

1. Open the browser (Brother Hong takes IE11 as an example) and follow the upper right corner

 -[Internet Options]-[Connection]-[LAN Settings] Enter the page as shown in the figure:

 If you want to learn automated testing, I recommend a set of videos to you. This video can be said to be the number one automated testing tutorial on the entire network played by Bilibili. The number of people online at the same time has reached 1,000, and there are also notes that can be collected and communicated with various channels. Master technical communication: 798478386   

[Updated] A complete collection of the most detailed practical tutorials on Python interface automation testing taught by Bilibili (the latest practical version)_bilibili_bilibili [Updated] A complete collection of the most detailed practical tutorials on Python interface automated testing taught by Bilibili (practical version) The latest version) has a total of 200 videos, including: 1. Why interface automation should be done for interface automation, 2. Overall view of request for interface automation, 3. Interface practice for interface automation, etc. For more exciting videos from UP master, please follow the UP account . https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337.search-card.all.click 

2. In the "Proxy Server", follow the picture above to set up. You can change "localhost" to 127.0.0.1 and 8080 to the port you want to set. The main thing is not to conflict with other ports. If so, please change it to another port. Ports, generally 4-digit ports have less chance of conflict; after configuring, click the "OK" button.

2.2 Configure the proxy in Jmeter

 1. First add a thread group in JMeter, as shown in the figure below:

 2. Add an HTTP proxy server node, as shown in the figure below:

 

 

3. Set up the proxy server. The port number setting is the port we set in the browser, as shown in the figure below:

4. Target controller: Decide which directory we will record the script in in the future (the test plan is a directory tree, and this directory is a node in the tree). You can add a node under [Test Plan]-[Thread Group], then specify the script to be placed on this node, add a [Simple Controller] node to the thread group, and then select it in the "Target Controller". As shown below: 

5. Grouping: When recording a script, many nodes will be added. We can group these nodes into groups to facilitate our viewing and management. For http requests we can think of each URL as a group, which can be better understood here. Grouping has the following options, as shown in the figure below:

Option parameter description:

(1) Do not group samples: list all recorded http requests.

(2) Add separation between groups: Add a simple controller named after the dividing line.

(3) Put a new controller in each group: the requests generated by each URL are placed under a controller.

(4) Only store the first sample of each group: We know that a URL may generate more than one HTTP request. A picture or a style will be an HTTP request. Many HTTP requests will be generated during recording, but there are When testing, we need to consider caching. In fact, some pictures do not need to be downloaded every time, and we do not care about the load generated by these pictures. In addition, most of the Internet uses CDN and other libraries to store these pictures, CSS and other static resources. So in theory we can ignore it in the script, but we have to choose whether to ignore it based on the actual situation. Therefore, if ignored, we can select this option and only record HTTP requests that generate dynamic data.

(5) Put each request into a new transaction controller: Brother Hong explained in vernacular that each URL request is put into a transaction, no matter how many HTTP requests it has, as long as it is generated by this URL request.

Other interface parameter descriptions:

(1) Record HTTP information header: Record the Header header information as well.

(2) Add assertions: As we all know, this is to add checkpoints, add empty checkpoints during recording, and then fill in the assertion (check) rules ourselves.

(3) Regex matching "Checkpoint uses regular expressions to match content.

(4) Http Sampler settings: The same as the "http request" setting method.

 

2.3 Start recording

1. After all configurations are completed, press [Start] in [HTTP Proxy Controller]. Then browse the Web page (the function you want to test) in your browser and record these HTTP requests. The "Start" button in the recording state is gray and cannot be clicked, but the "Start" button in the non-recording state can be clicked.

2. During recording, every js, png, swf and dynamic request (the server needs to dynamically obtain data) will be recorded. So we choose "only store the first sample of each group", but this usually prefers dynamic requests to be missed, so HTTP proxy recording is not very efficient, so we change a tool (Badboy) to record, even If we have the ability, we can directly write the script by hand (Brother Hong recommends this method).

Note:
Nowadays, more and more systems or website front-end architectures use dynamic loading (Ajax+JS+JSON) to process. For this kind of application, we cannot complete the task even if we use JMeter or LoadRunner to record. Children who don’t believe it can record the official website of Qunar.

3. After clicking Start, you will be prompted: Jmeter imports the https security certificate, starts Jmeter's HTTP proxy server, and a security certificate file will be generated in the bin directory of the Jmeter installation path: ApacheJMeterTemporaryRootCA.crt. As shown below:

4. In the Jmeter menu option -> SSL Manager, import the security certificate file ApacheJMeterTemporaryRootCA.crt in the bin directory of jmeter.

5. Click SSL Manager to view the imported certificate, as shown below:

 

6. In the bin directory of JMeter, find the certificate, double-click to open the certificate, and import the certificate into the browser, as shown in the following figure:

7. After the proxy server is restarted, the interface shown below will open, Recorder: Trnsactions Control. At this point, start recording the script, enter the URL you want to visit in the browser, and perform related operations. Here we take Du Niang as an example, record an interview with Du Niang, and then query: Beijing-Hong Ge’s script.

The purpose of this pop-up box is to conveniently and quickly fill in the transaction name that needs to be written when recording; you do not need to open the jmeter interface to modify the transaction name every time, you can ignore it.

8. After entering the Du Niang URL in the browser, enter Du Niang, enter: Beijing-Hongge in the input box, and click Query. Check whether a request has been made to the recording controller under the Jmeter thread group. If a request is generated, the script recording is successful. As shown below:

 

9. After the recording is successful, the information sent will also be recorded in the request, such as server name, port number, path, and request parameters, etc., as shown in the following figure:

 10. Select "Recording Controller", right-click to add "Observation Results Tree", run the script, and debug the recorded script. Here is the script to verify the successful recording login, as shown in the following figure:

 11. Streamline the script and delete requests other than visiting Du Niang and querying Beijing-Hongge. As shown in the figure below, you can see the script response after running in the result tree. You can see <Baidu Click> in the response body, which means the access is successful. You can see the query results of Beijing-Hongge, the code query is successful, and the recording is completed. . Close the Jmeter proxy server. As shown below:

 The result of the query request is as shown below: 

 

3. Summary

 1. Some students may encounter the problem of normal access to Jmeter before recording, but cannot access it after setting the proxy.

According to Hongge's analysis, there are several possibilities. One is that the agent process of the tool itself is not started, the other is that the port is occupied, and the other is a certificate issue.

The most likely problem is the certificate. HTTP requests may be fine, but https requests may involve certificates. Just install the certificate in the bin directory (you can ask Du Niang for the specific certificate installation method, but it is also simple and similar to the fool-like installation software. The next step is enough). In fact, there shouldn't be any big problem if you follow Brother Hong's steps.

Guess you like

Origin blog.csdn.net/Faith_Lzt/article/details/132540095