1 Introduction
During interface testing, there may be situations where there is no documentation or incomplete documentation. You can use Badboy and Fiddler to perform interface testing.
in,
- Badboy: Record and export into jmeter script.
- shortcoming:
- Sometimes recording is slow, especially when there are pop-ups,
- When converting Badboy into a jmeter script, there may be omissions or conversion errors.
- shortcoming:
- Fiddler: Fiddler does not have the disadvantage of Badboy's slow recording, and can be corrected and improved based on the information recorded by Fiddler.
An example is used to illustrate the following steps:
- Login to Blog Park
- release news
2 Badboy recording
Step1: Log in to the blog park
Step1.1 Enter http://www.cnblogs.com in the badboy address bar and press Enter to start recording.
Step1.2 Click the login link to enter the login page, as shown in Figure 1:
Figure 1 Login page
Step1.3 Enter the username and password and click to log in. The result is as shown in Figure 2:
Figure 2 Login request
Step 2: Publish information
Before publishing information, switch to the publishing page (flash memory), this step is not recorded.
Step2.1 Enter the publishing information "Hello!" and click the "Publish" button
Figure 3 Release request
When the recording ends, click File->Export to JMeter...
3 Jmeter opens the Badboy script
Open Jmeter and open the script you just saved. As shown in Figure 4, you can find the http request you just recorded. Some of these requests can be ignored.
Figure 4 Script recorded by Jmeter using badboy
Let’s first look at the information header, as shown in Figure 5:
- Http Cookie Manager: Adding this manager will allow Jmeter to save login information without modification or deletion.
- User Defined Variables: If there are no custom variables, they can be deleted
- Http Header Manager: This manager records the header data. Badboy only records three of them. We refer to Fiddler's capture information to supplement and improve it.
Figure 5 Http header management
4 Use Fiddler to capture requests and supplement and improve the script
As shown in Figure 6, in the http information header captured by Fiddler, there are two items badboy did not record:
- X-Requested-With: XMLHttpRequest
- Content-Type: application/json; charset=utf-8
Add them to Jmeter's Http Cookie Manager
Figure 6 http information header
Since the Content-Type is json, as shown in Figure 7, the parameter body sent by http should be placed in the Body Data of Jmeter, as shown in Figure 8, instead of Parameters (the release information request is also modified in this way).
Figure 7 Cotenttype is Json
Figure 8 Json type parameters are placed in Body Data
5 Problems encountered during testing
5.1 Blog Park login name and password encryption
From the login request in Figure 2, we find that both the username and password are encrypted. Through IE's F12 debugging function, we can discover the encryption process. The test revealed that the encryption result is different each time it is called, but the same encryption result can be used multiple times.
1 2 |
|
5.2 Chinese problem in Jmeter request message body
If Content-Type: application/json; charset=utf-8 is not added to the Jmeter information header, the response result of the login request will fail.
5.3 Chinese problem in Jmeter response text
The Chinese in the Jmeter response data displays garbled characters. Modify apache-jmeter-3.0\bin\jmeter.properties and add the encoding setting to:
1 |
|
Essential tutorial for advanced Python interface automation testing (the most detailed on the entire network in 2023)