Testing via Charles proxy

Charles Proxy is a cross-platform HTTP debugging proxy server application written in Java.

It acts as a middleman between the local computer and the internet. It enables the user to view HTTP, HTTPS and enabled TCP port traffic accessed via the local computer. 

It simply enables the user to view/ monitor network calls and helps understand the content of the network call. The tool can read web traffic of windows, Android and IOS.

eg: Let’s say you’re searching for something on Google, Charles acts as a mediator between you and Google and helps to monitor the server logs. 

These logs are very helpful when an application that needs a server is developed and tested.

How to Configure Charles : 

  1. Install the Charles tool on your computer from the website “https://www.charlesproxy.com/download/latest-release/“.
  2. Install the Charles certificate on the device where you’re going to perform testing. If it is your local computer, Open Charles tool > click on Help > click SSL Proxying > Install Charles certificate(Might get a warning that it is not a trusted agent). If testing is to be done on a website only, this all set up is required, further steps include setting it up for mobile testing.
  1. To install it on a mobile, simply visit “chls.pro/ssl” and it’ll ask if you want to install the certificate on your device.
  2. There’s a precondition for mobile devices that it’ll only capture calls if the local system and the device are on the same network (If using a mobile hotspot to connect to the internet then the hosting device will not capture calls)
  3. Now if all the above requirements are met, go to the wifi settings and tap on the connected wifi network. Find proxy which by default is set to “None”. Change it to “Manual” and input Proxy Host name(on android) / server (on IOS) and Proxy port.  >>To find proxy host name/ server and proxy port: On computer open Charles, click on help >> SSL proxying >> Install Charles root certificate on a mobile device or remote browser. It’ll open a pop-up containing information of host name/ server and port number.eg : Host/ server 192.168.43.46 // Post 8888 // it’ll look something like this.
  4. Once you input that and hit save, it might show a pop-up on your computer to establish a connection. Now the setup part has completed.

 How and why to use Charles proxy :

Record session: Click on start recording and Charles tool will start capturing traffic by itself of the connected device showing you all the services being called as you keep using the app.

With the press of every button, if there’s any web service being called, it’ll record that in the history table. By default, structure view will be selected but the user can switch with sequence view. In sequence view filter can be put as to which calls to record. Simply put in the URL of the API or keyword distinguishing your app being tested calls.

Structure view:  Containing all the device traffic

Sequence view: I’ve put a filter so it’ll show only the calls related to selected API.

Now against each API selected it shows the information such as status code, request data, response data and many others.

Here you can check what was sent via the API and what response are you getting when a certain action is performed.

Via this, you can also check if any handling needs to be done on a certain action or not.

Breakpoints: One can also put breakpoints onto certain API. Via breakpoint you are putting a condition that it is bound to fail. This can be used to test scenarios such as, what happens if an API fails, to check the validation if provided if API fails, to test the impact of that certain fail on other API etc.

To put breakpoint: right click on the API and scroll down to find the breakpoint.

Now if a certain API/ session is failing, one can simply save the session in a .chls extension and can directly be attached in a ticket on a bug tracking platform. The developer has to simply download that file and open it via Charles to check responses making it easy to understand. 

Throttling:  Network throttling is to simulate different network bandwidth conditions like 2G, 3G, 4G, and WIFI. It can also be used to simulate customized modem network speeds.

It is useful when you have to test any application that has network dependencies or it will be useful to test how your application is behaving in different network conditions. You can customize the speed and other network conditions by clicking the Proxy menu > Throttle settings.

Clear Button: As the name suggests it simply erases the previous sessions and lets you create a new session.

Repeat Button: This button is to repeat a specific request. Once you click on this button, the request in the editor will be sent again. This feature comes handy when you want to recreate a request without performing the action again.

Map Local: Let’s say you want to change something in the request and check how it’ll affect your application. One can simply copy the request data, save it in a .json extension. Now open Charles > Tools > Enable Map Local. Now it’ll open something like

Now click on add

Under Map From, In Host, Put the URL of the application/ website, it’ll automatically divide it into the host, port and all. 

Under Map To Select the location of that saved .json file(with the changes done to the request) and click OK.

Now next time you run that app, it’ll fetch request data from that local file you have saved in your system and will only reflect on your system for the time being. This is helpful in testing negative scenarios. 

Also, let’s say if the server is down, one can simply copy the requests and map it locally to test the application even when the server is not working. This is very helpful if let’s say in a company, servers get shut down on certain times but you need to test/ develop regardless. 

*Most importantly, it helps in distinguishing if its front-end issue or back-end issue saving time, confusion and effort while assigning issues to the concerned person.

Another benefit is that the tester can monitor the back end structure of the application. So why to use it shouldn’t even be a question now, since it provides so many easy to use features that help in testing. One can learn a lot about the structure of the application, order of the web services, HTTP requests and many more. Other commonly used tools providing network traffic capturing includes postman and Fiddler.

Note: Charles can be used for free or by purchasing its licence. For a free user, Charles will stop working after 30 min of usage so one has to restart it again. Also, there is some delay in the tool once you restart it. And also remember to change proxy to None from manual if not using Charles, as the internet will only work if Charles is on. If Charles is off, the internet stops working on the device.

Leave a Reply