Charles: an indispensable tool in the arsenal of QA-engineer

  • Tutorial

To test mobile applications that work with remote servers, the QA engineer has to keep at hand many different test accounts, logs, requests and answers. The reality is that it is not always possible to agree on the provision of 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 do it yourself to replace the server response before transferring it to the application.

To edit server output and play complex test cases 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 go through the phone connected to it and allows you to edit them.

Charles installation instructions for Mac OS X and connecting your phone.
1. Download and install .
2. At the first start, Charles carefully suggests that you 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 enter the IP address of your Mac and port 8888 in the proxy server. The
phone must be connected to the same Wi-Fi network as your Mac.



Done. The next time you connect, the Charles client will ask for permission to connect your phone. After that, all HTTP requests and responses that pass through your phone begin to be displayed in Charles.

To monitor HTTPS traffic, you need to go through additional steps:
5. Go to the phone’s browser and go towww.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 check Enable SSL Proxying.


Done. Now the Charles client displays HTTPS traffic for the selected host.

Important
If your application uses SSL pinning, Charles will not be able to intercept requests and responses.



Traffic monitoring


For a visual demonstration of working with the API, we use the Habrahabr application for Android. On iPhone, there is protection against programs like Charles, but on Android it is not.



Charles arranges all the requests in the order they are sent to the server. Requests and responses can be viewed both in a formatted and in a raw form. In QA Redmadrobot, the phone is always connected to Charles during testing. Thus, it remains possible to look at the history of requests and track tricky bugs.



Data spoofing


As you can see, I don’t have much karma. Charles will help to pretend that it is a little more than it actually is.



The output for the account looks like this (only a 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"
}


There is a score field in the log:
"score": 6
Apparently, just what I need.

Rewrite settings

To replace server data, open Tools> Rewrite.
The list on the left shows sets of queries that you can make to your taste. After the creation of the set, the location is set. Here we prescribe the request URL with query parameters (optional).

The next step is to create a spoofing rule. Unfortunately, Charles is not able to substitute information on a key. We need to manually register the key and value, and then write what we want to see.

The window for creating the rule will look like this:



The spoofing screen itself will look something like this:



The next response, when asked for information about itself, will have the 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"
}


At 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 trip to the MP and these changes do not affect the real profile data in any way .

In the same way, you can replace not only answers, but also requests. To do this, on the Rewrite rule screen, you need to check the Request field, not the Response.

Breakpoints

When replacing queries using Rewrite settings in Charles, it is not possible to edit the Cyrillic alphabet. If you change any information to Cyrillic, your logs will consist of many question marks.

Fortunately, this flaw can be circumvented with another Charles function, breakpoints. The idea is similar, but only the answers stop right before the transfer to the MP, and they can be edited with your own hands in real time.

Open Breakpoints settings and set the request URL.


In the next response to this request, Charles will intercept all the results and allow us to work with it. It should be borne in mind that the MP can throw an error by timeout, and the current request will go nowhere.


We’ll 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 will cost $ 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, sometimes windows will 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, every 30 minutes the program will automatically end and the entire history of requests will be lost.

Summary


Charles is an indispensable tool in the arsenal of QA engineers at Redmadrobot. Using it, you can create any necessary test data, both real and impossible (according to the API specifications). Such capabilities expand the boundaries of black box testing 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.

Also popular now: