There are various tools used in testing to work with HTTP/HTTPS. Quite often, it is necessary to analyze, modify, or intercept traffic, or to edit requests. Among the most popular tools developed for such tasks are sniffers: Wireshark, Fiddler, tcpdump, Charles, etc.
Using Charles in testing
- 09.01.2024
- Posted by: Admin
Charles is an HTTP proxy, also known as an HTTP monitor or reverse proxy server, which allows a tester to view entire HTTP and SSL/HTTPS traffic between a computer and the Internet. The tool can be used to find the source of the problem, sort the different types of errors that occur, and duplicate different test scenarios.
The main advantage of using Charles is its compatibility with most web and mobile browsers. Since Charles automatically configures itself with most browsers, it does not require the user to change their browser settings every time they use it.
Installation and setup
For the Windows operating system and associated browsers, Charles can automatically configure proxy settings to ensure that OS applications use only Charles.
To start, download Charles at https://www.charlesproxy.com/ and install the certificate on PC Help > SSL Proxying > Install Charles Root Certificate. The certificate must be imported to the «Trusted Root Certification Authorities» storage. At this point, installation and configuration are completed.
Setting up Charles on the desktop
Installing the certificate
For Mac OS X and related browsers (e.g. Safari), the first time Charles is installed, users will be asked to provide permission. After that, the tool will automatically configure and reconfigure the proxy settings.
For Mozilla Firefox, the user has to download the Firefox add-on, after which Charles will automatically configure the proxy settings.
For all browsers, Charles's settings can be configured in the proxy menu.
Installation and configuration
First, you need to set up a proxy on your device. The computer from which Charles is running and the device must be in the same local network. You can view the IP address of the network to which your computer is connected in Charles > Help > Local IP Address.
Select Wi-Fi in the device settings.
View the available Wi-Fi network
Select the network settings to ensure that the PC and device are on the same local network.
Setting up the network
Click on the «Configure Proxy» button and select the «Manual» setting. Enter the IP of the network connected to the PC in the «Server» field. Enter «8888» as the default port address.
Set up a proxy on the device
If the device is connected through Charles, you will see the following message on the PC:
Request for a connection to the PC
After clicking the «Allow» button, all HTTP traffic will be routed through Charles.
By default, PC traffic will also be routed through Charles. If you want only the traffic of connected devices to be displayed in the sniffer, uncheck the box in the Charles proxy settings > Proxy > Proxy Settings > Windows > Enable Windows proxy on launch.
Setting up the HTTP traffic
Testing caching
Caching allows a web browser to use a local copy of a response without requesting it from the website. Caching is a very important part of the Internet as often the same resources are reused on multiple pages, and having to reload each resource for each page significantly slows down the browsing experience. However, caching might also mean a resource is not loaded with the latest version, which is a problem during web application development, so checking for updates is important.
To configure the tool, go to Tools > No Caching.
Testing caching with Charles
The «No Cache» tool prevents caching using HTTP headers that control response caching. The If-Modified-Since and If-None-Match headers are deleted from requests, the Pragma: no-cache and Cache-control: no-cache are added. The Expires, Last-Modified, and ETag headers are deleted from responses and the Expires: 0 and Cache-Control: no-cache headers are added.
Data substitution
This check allows changing the response from the server. There are 3 ways to replace data:
Breakpoint is the request stopping point. Stopped requests can be edited in real-time. To configure, open Proxy > Breakpoints Settings > Enable Breakpoints > Add and add a link to the request URL.
Setting up Breakpoints
Rewrite allows the creation of rules that modify requests and responses when they pass through Charles. Rules such as adding or changing the header, and searching for and replacing text in the response body. To configure it, open Tools > Rewrite > Enable Rewrite > Add, and enter the current and desired values in the Values fields of the relevant blocks.
Setting up Rewrite
Map Local allows users to use local files as part of a remote website. It is possible to develop your files locally and test them as though they are available online. Settings: Tools > Map Local > Enable Map Local > Add, then select the protocol and enter the Host and Path.
Setting up Map Local
Cookies blocking
The tool allows blocking the process of receiving and sending cookies. It is used to test websites as though cookies are disabled in the browser. Keep in mind that web spiders (e.g. Google) often do not support cookies, so the tool can also be used to simulate a spider browsing a website.
To configure it, go to Tools > Block Cookies > Enable Block Cookies.
Setting up blocking cookies
Load testing
Charles has basic load-testing features. The Repeat Advanced function allows repeating the same request any number of times. After setting it up, a separate session will be opened with details of each request.
Go to Tools > Advanced Repeat and specify the number of repetitions and the parallel queries' simultaneity.
Setting up the Repeat Advanced function
Throttling
Charles Proxy helps test the service for poor connection by artificially limiting the bandwidth in the settings. This function is useful for testing desktop applications because, on mobile devices, the connection quality can be controlled through the developer panel. To configure it, go to Proxy > Throttling Settings.
Setting up throttling
Other functionality
We have described in detail the main testing functions with Charles. But there are some other equally important features:
- Sessions. It is automatically opened after Charles is launched. Sessions can be saved, cleared, and reopened.
- Recording. Requests and responses are recorded for the current session to be reviewed and analyzed later. The recorded requests depend on the configuration of Charles, usually including all HTTP and HTTPS traffic from the browser and possibly other programs on the computer.
- Requests & Responses. There are two different ways to view the session window: structure view and sequence view. It allows viewing the HTTP request and response headers, as well as the request and response bodies in the form of plain text or binary code.
- Focus. Using the focus function, users can separate the important hosts from the ones they don't need.
- Chart. The chart tab of the request shows the request and all related requests on a timeline. The timeline shows when the request started, when the response started, and when it ended.
- Import.
- Export. Use the Export option on the File menu to export data from a session to Charles.
- SSL Certificates. Charles створює власні сертифікати для сайтів, які він підписує за допомогою кореневого сертифіката Charles, який унікально генерується для вашої інсталяції Charles.
- Web Interface. Charles has a web interface that allows controlling it from a browser or with the help of an external program by using the web interface as a web service.
- Protocol Buffers. Protocol buffers are an extensible mechanism from Google that does not depend on language, or platform, and is used for serialization of structured data. The structure of the data is defined once, and then specially generated source code can be used to easily write and read structured data in a variety of data streams using different languages - Java, C++ or Python.
- Command-line Options. Charles supports several command-line options:
- <path>
- -config <path>
- -headless
- -throttling (starting from version 3.8.3).
Using the Charles tools, you can test caching, intercept and modify data, block cookies, check connection speed, and test load at a basic level. These tools are enough for full-scale proxy testing.
The free version of Charles is available for 30 days, allowing you to evaluate the app before deciding to purchase it.