Mobile testing is harder compared to web or backend testing. There are different reason for that. That might be device diversity, network issues and sometime data which is a common problem in testing or something other than those. Today I am going to talk about how to fake your request by rewriting http request with Charles proxy.
Charles is a great tool to intercept network calls made by your mobile device. It works with both Android and IOS if the certificate is installed and the device that runs Charles and mobile device are in the same wireless network.
Here’s the first article that we wrote about it
Let’s Capture the Data
In case you followed the instructions in the first article, you should be able to capture network traffic.
Let’s make a call to an endpoint and see what we got from the app.
Let’s Fake the Data
Press cmd+alt+R to open Rewrite Settings.
First you need to check the Enable Rewrite checkbox on left hand side. Then click Add button.
Secondly, you need to enter the details of the endpoint that you are going to fake on the top box. Click Add and enter the details of the endpoint.
Next step is to modify the response payload. This is done by the bottom box on Rewrite Screen.
I choose Body in Type, I choose Response in Where. By doing so, I say Charles to fake the Response Body. Then you need to specify the new response payload you want to get. You can use regex to change some part of the value or you can replace the whole response.
If everything goes well, when my application makes a request to this endpoint, i will receive the provided static response instead of a real response.
Trigger the Endpoint by App
Now, i trigger the app to call this endpoint and as you can see now i have a different response payload.
Now, you application will render a different screen because there are different values.
Why do we need to rewrite or fake the data?
Let’s says you want to test your application against incorrect data types. You have find the right table and columns then make a change on the record etc. Now all you need to do is changing the attribute in the payload with the new data type and check how your application behaves. By doing so, you don’t need to modify any record in the database. You just virtualized your test data.
Canberk Akduygu is a Test Lead working on Test Automation and Performance Testing in Amsterdam at Qardio.