I am trying to use Charles proxy tool to mock JSON response and test Android applications. I am able to put break point and modify response, but not able to rerun the saved response later point of time.
My requirement save the response that displayed in charles proxy and call/parse it from jUnit test cases. Is that possible?
The Edit tool builds on the Repeat tool by allowing you to change the contents of the request before repeating it. When editing you can edit different parts of the request including the URL, headers, query string or form contents.
The Breakpoints tool lets you intercept requests and responses before they are passed through Charles. You can examine and edit the request or response and then decide whether to allow it to proceed or to block it. Each breakpoint matches a URL using location matching patterns, see below.
STEPS TO RE-RUN THE SAVED RESPONSE:
1) Right click and save response in any of your system folder.
2) Right click the service that you want to hit with saved data.
3) Scroll down, you will be seeing an option for Map remote and map Local
4) Select Map Local, Edit mapping dialogue box appears.
5) Choose the local file you saved. Done
Now each time you hit the same, the locally saved response will be called. Once your testing is completed, please do right click and select map local to remove it.
https://medium.com/@vsujananth https://youtu.be/HKfVAXMjw_8
There are 3 diifferent ways to modify response body in Charles Proxy:
1) And this is my favorite - use Tools -> Rewrite. Here you can set a set of rules for the network call, such as you desire. Do it by choose single ot multiple URL (or part of it) under the "location" section. Under "Rules", add a new rule and choose "URL" for type and your desired URL response under "values" section. You can choose a URL that contains the desired response or either create a mock one (by using tools such as "mocky.io").
2) You can use "Map Remote" and do the same - choose the network you would like to modify with the URL that contains the response you desire.
3) "Map Local" is good in case you like to modify the response body frequently - choose the network you would like to modify with a local file (in your case .json file). You can modify it between requests and save it.
I prefer the "Rewrite" option since: (1) it can contains multiple URLs to modify with multiple "desired" URLs and you just need to activate/deactivate by your current needs. (2) "Map Remote" has bugs in some Charles versions where you import external rules and your previous rules are totally overriden. (3) On "Rewrite" you can modify many things regarding the call, such as modifying substring in the response body (by choosing "Body" as the rule type), adding/modifying/removing query parameters or modifying the response status code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With