Packet capture tool Charles (5) - use local mapping to modify interface response content (Map local)

  • 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.

1. Principle

2. Operation steps

(1), Add interface mapping

1. Single interface

  • Select the target interface, right-click, and find "Map local"
    insert image description here

2. Batch add

  • Or under the "Tool" menu, find "Map local"
    insert image description here
  • After opening the local mapping settings, check "Enable Map Local", click "Add" to add interface mapping
    insert image description here

(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.
    insert image description here

(3), local file settings

  • After setting the interface that matches the mapping, the next step is to set the mapped local file
    insert image description here
  • 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.)
    insert image description here
  • Set to a local mapping file
    insert image description here
    (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
    insert image description here
  • First, save the result returned by the interface.
    (Note: save directly)
    insert image description here
  • Open the file and find the copy you want to modify
    insert image description here
  • Modify the content of the copy
    insert image description here
  • 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)
    insert image description 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.
    insert image description here
  • Check the website, and you can also see that the copywriting just now has been modified.
    insert image description here

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
    insert image description here
  • Uncheck "Enable Map Local" and save.
    insert image description here

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.
insert image description here
If necessary, click on the QR code at the bottom of the article to get it~insert image description here

Guess you like

Origin blog.csdn.net/weixin_40883833/article/details/129868080