This is a study note for the Hogwarts Test House Distinguished Student course.
As a test engineer, packet capture is the most common problem analysis method. Charles is the most commonly used proxy tool and is very Windows – and Mac-friendly. There are several other reasons why it is so popular:
- The agent function
- HTTP/HTTPS, Socks5
- The speed limit to simulate
- Breakpoint debugging
- forwarding
- Mapping: Make a request sent to site A return the content of Site B
- Override: Automatically tamper with the request and content
- Tools: Assemble request, replay request, reread request
Every point of the Charles agent tool is worth studying carefully.
Mock(Map Remote)
As a test engineer, you may need all kinds of “fantastic” data. When the interface returns data that does not meet your needs, what to do? What if you want to test H5 in the real world, but the new version is not online yet?
In the testing process, for some objects that are not easy to construct or obtain, we need to “do it yourself, make a living”; Intercept requests, tamper with requests, forward requests — Mock to help you think and get what you want; There are many ways to Mock, and here’s how to do it with the Charles tool. Here is an example of visiting baidu’s home page and forwarding the request to TesterHome’s home page.
Note: Charles has been installed by default and the trust certificate has been set for the following operations, and the proxy can be successful.
1) In charles-Tools, select Map Remote
2) Select Enable Map Remout and click Add
3) Set the path and protocol mapped From Map From and Map To (HTTP or HTTPS is not supported by default). When finished, click OK
4) At this time, we entered www.baidu.com in the browser for access, and found that the actual access was TesterHome, which can also be seen from the captured package
Mapped from remote URL: www.baidu.com/
Rewriting traffic with Breakpoints
Breakpoints allow you to intercept and pause a specified HTTP or HTTPS request before it reaches the client. After the pause, you can modify the original data, such as the return value, and then send the request to the client.
Sometimes we inspection on interface, may be related to field length, number, corresponding to different values of different color or logo image display, etc., if pure depending on the backend to construct complex data may not be so convenient, also may have a lot of dirty data, and the purpose of our test just to verify the front-end display, So use Charles’ rewrite functionality to mock data;
1) Right-click on the request to block and select “Breakpoints”
2) Select Enable Breakpoints from Proxy->Breakpoint Settings, and then double-click the request to pop up the Edit Breakpoint box. Select Response and OK.
3) When we visit the home page of TesterHome at this time, we will find that the request is blocked and the site has been loading and waiting for response.
4) Select Edit Response, change the “Community” field in the original title bar to “Charles Community “, and click Execute.
5) Check the home page of TesterHome and find that the original title field has been successfully modified
Rewriting traffic with the Rewrite tool
Breakpoint intercepts changes quickly, but if you want to intercept changes in the same way every time, you need to manually trigger them, which is inconvenient and inefficient. So you can use the Rewrite feature in Tools to implement tampering rules that pre-define interface data so that changes are automatically intercepted every time they are accessed
1) Select Rewrite in Tools and set the URL to intercept
2) Select Add a rewrite rule to replace “TTF list” with “11111 list” in the return value
3) Revisit the TesterHome home page
The Rewrite function mentioned above can be modified not only in Response but also in Request, but also in Response.
In the above examples, the Web side is used to demonstrate, and the mobile side is the same as this principle. It should be noted that Android6.0 and above does not support proxy packet capture by default, so you need to let the developer add two configuration items in the App.
(Article from Hogwarts Testing Institute)
Welfare benefits:
Front-line Internet famous enterprises test development position internal promotion channel
Test development internal communication circle, expand your test network
For free: Interface testing + Performance testing + Automated testing + Test development + Test cases + resume template + test documentation