- Changing the return data of the interface is a very practical method for troubleshooting or debugging functions.
- By modifying the interface data, the speed of development and testing can be greatly accelerated. Other packet capture tools have similar functions.
- In Charles, the local mapping (Map local) is used to achieve the purpose of modifying the data returned by the interface.
Article directory
1. Principle
- The article before the column introduced the principle of Charles packet capture
[ Packet capture tool Charles (2) - mobile APP capture (set mobile phone agent, install certificate) ]
- Local mapping means that after Charles captures the client's interface request, it returns the content of the local file to the client, just like a normal server response.
- The client will also receive the modified response content.
2. Operation steps
(1), Add interface mapping
1. Single interface
- Select the target interface, right-click, and find "Map local"
2. Batch add
- Or under the "Tool" menu, find "Map local"
- After opening the local mapping settings, check "Enable Map Local", click "Add" to add interface mapping
(2), set the matching mapping interface
- After opening the interface mapping dialog box, you can see that the upper part is the interface URL information that matches the mapping.
- Charles will match specific URLs based on protocol, host, port, path, and query parameters.
- These settings support wildcards. For example, if the query parameter is configured as "*", all query parameters under this path will be matched.
(3), local file settings
- After setting the interface that matches the mapping, the next step is to set the mapped local file
- You can create a new file locally and return it as an interface response.
- It is also possible to directly save the response of the interface to be mapped and set it as a local mapping file.
(Note that the files saved directly in this way have no file suffix. After saving, modify the file suffix according to the data type of the original interface response.)
- Set to a local mapping file
(Note: If the requested file cannot be found locally, the request will return the server interface data normally.)
(4), example steps
- Take the interface of Charles official website as an example: through local mapping, modify the text in the red box in the figure below
- First, save the result returned by the interface.
(Note: save directly)
- Open the file and find the copy you want to modify
- Modify the content of the copy
- Set up local mappings.
(Note, because the original interface response is in html format, so the suffix of the local file is changed to .html here)
- After the setting is complete, request the website interface again. You can see in the header of the interface response that the interface response has been mapped to the corresponding local file.
- Check the website, and you can also see that the copywriting just now has been modified.
3. Note: Remember to turn off when not in use!
- Sometimes I encountered situations where the data did not match the actual expectations. After checking for a long time, the result was that I forgot to turn off the interface mapping [wry smile]
- You can find "Map local" under the "Tool" menu
- Uncheck "Enable Map Local" and save.
Appendix: Interface Functional Testing Series Tutorial Contents
Packet capture tool Charles (1) - download, install and set up
packet capture tool Charles (2) - mobile APP packet capture (set up mobile phone proxy, install certificate)
packet capture tool Charles (3) - tutorial interface introduction, basic functions ( Weak network, editing, retransmission)
Packet capture tool Charles (4) - Introduction to common functions (save, import and export, filter, sort)
Packet capture tool Charles (5) - Use local mapping to modify interface response content (Map local)
Packet capture Tool Charles (6) - use remote mapping to redirect interface requests (Map remote)
General Catalog-Zero-Basic Getting Started Interface Functional Testing Tutorial
———————————————————————————————————————————————————
Charles installation package has been uploaded to I run a blog with the same name as the public account [Software Testing Essential Skills].
The public will also upload test-related materials from time to time, and they can go to collect them if necessary.
If necessary, click on the QR code at the bottom of the article to get it~