
To test mobile applications that work with remote servers, QA-engineer has to keep on hand a lot of different test accounts, logs, requests and responses. The reality is that it is not always possible to agree on providing the necessary test data on time. Most often, server developers will be strangers to you on the other side of Skype. In such situations, you have to substitute the server response with your own hands before sending it to the application.
To edit the server output and play complex test scripts in QA Redmadrobot, we use
Charles .
How it works?
Charles is a tool for monitoring HTTP / HTTPS traffic. The program works as a proxy server between the mobile application (in our case) and the server of this application. Charles records and saves all requests that pass through the phone connected to it and allows you to edit them.
Installation instructions for Charles on Mac OS X and connect the phone.1.
Download and install .
2. When you first start, Charles will carefully offer to automatically configure the network settings - we agree.
3. Go to Proxy> Proxy Settings and set port 8888 if it is not already registered.
4. On the phone, go to the Wi-Fi settings and assign the IP address of your Mac and port 8888 to the proxy server.
The phone must be connected to the same Wi-Fi network as your Mac.
')

Is done. The next time the client connects, Charles will ask for permission to connect your phone. After that, Charles starts displaying all HTTP requests and responses that pass through your phone.
To monitor
HTTPS traffic, you need to go through additional steps:
5. Go to the phone browser and go to
www.charlesproxy.com/getssl to install the SSL certificate that will be used when connecting. Install.
6. In the list of hosts, select the desired host with HTTPS and tick Enable SSL Proxying.

Is done. Now the client Charles displays HTTPS traffic on the selected host.
Important
If your application uses SSL pinning, then Charles will not be able to intercept requests and responses.
Traffic monitoring
For a visual demonstration of working with API, we use the Habrahabr for Android application. On the iPhone, there is protection from programs like Charles, but on Android it is not.

Charles builds all the queries in the order they are sent to the server. Requests and replies can be viewed in both formatted and “raw” form. In QA Redmadrobot during testing, the phone is always connected to Charles. Thus, it remains possible to view the history of requests and track tricky bugs.

Data substitution
As you can see, I do not have much karma. Charles will help to pretend that it is a little more than it actually is.

The issue of the account looks like this (only JSON-string, without headers):
{ "data": { "id": 946584, "login": "yaryabu", "time_registered": "2015-02-27T15:22:52+03:00", "score": 6, "fullname": null, "sex": 0, "rating": 0, "rating_position": 0, "geo": { "country": null, "region": null, "city": null }, "counters": { "posts": 1, "comments": 3, "followed": 0, "followers": 0 }, "badges": [{ "alias": "habred", "title": "", "plural": "", "description": " \u003E0." }], "avatar": "http:\/\/habrahabr.ru\/i\/avatars\/stub-user-middle.gif", "is_readonly": false }, "server_time": "2015-10-16T20:38:02+03:00" }
The log has a score field:
"score": 6
Apparently, just what I need.
Rewrite settings
To replace the server data, open Tools> Rewrite.
The list on the left displays sets of requests that you can make to your taste. After creating the set is setting the location. Here we write the request URL with query parameters (optional).
The next step is to create a substitution rule. Unfortunately, Charles does not know how to replace information by key. You need to manually prescribe the key and value, and then write what we go to see.
The rule creation window will look like this:

The replacement screen itself will look something like this:

The following response to a request for information about yourself will have edited data, score = 5000:
{ "data": { "id": 946584, "login": "yaryabu", "time_registered": "2015-02-27T15:22:52+03:00", "score": 5000, "fullname": null, "sex": 0, "rating": 0, "rating_position": 0, "geo": { "country": null, "region": null, "city": null }, "counters": { "posts": 1, "comments": 3, "followed": 0, "followers": 0 }, "badges": [{ "alias": "habred", "title": "", "plural": "", "description": " \u003E0." }], "avatar": "http:\/\/habrahabr.ru\/i\/avatars\/stub-user-middle.gif", "is_readonly": false }, "server_time": "2015-10-16T20:58:05+03:00" }
The next transition to the profile screen in the Habr application, we will see the fruit of our labors.

I want to remind once again that the information on the server remains the same. The data changes during the journey to the MP and these changes
do not affect the actual profile
data in any way.
In the same way it is possible to substitute not only answers, but also requests. To do this, on the Rewrite rule screen, you need to tick the Request field, not the Response field.
Breakpoints
When changing queries using Rewrite settings in Charles, it is impossible to edit the Cyrillic alphabet. When changing any information to Cyrillic, your logs will consist of a set of question marks.
Fortunately, this flaw can be circumvented with another Charles function - breakpoints. The idea is similar, but only the answers stop right before being transferred to the MP, and you can edit them with your own hands in real time.
Open Breakpoints settings and write the request URL.

The next time you respond to this request, Charles will intercept all of the issue and allow us to work with it. It should be borne in mind that the MP can throw out a timeout error, and the current request will go nowhere.

Replace my login with something written in Cyrillic.

That's all. The application displays the information we need and there are no problems with the Cyrillic alphabet.

The most important thing
The licensed version of Charles costs
$ 50 per person . Charles allows you to use yourself for free, but with restrictions. The functionality of the tool is not blocked, but when using the trial version, windows will sometimes appear asking you to wait 5-10 seconds before resuming work and think again about how cool it would be to buy a license. Also, the program will automatically end every 30 minutes and the entire query history will be lost.
Results
Charles is an indispensable tool in the arsenal of Redmadrobot QA engineers. With it, you can create any necessary test data, both real and impossible (if you believe the API-specifications). Such capabilities expand the testing of the black box and allow you to observe all the main interactions of your MP and its servers. Testing at this level allows you to find more complex defects and significantly improves the overall quality of the application.