I assume that the majority of QA engineers have experience using the Charles application or similar tools to capture network traffic on real devices. There are numerous online guides available for this purpose. However, when it comes to using Charles with an emulator, I noticed a lack of recent articles addressing this specific scenario. Although the process is relatively simple, I’ve decided to create this guide to assist those who may be seeking guidance in this area.
To get started, open the Android Emulator and install your app. You can do this by dragging and dropping your APK file into the emulator window. Just keep in mind, that for sniffing traffic, you’ll need a custom version provided by developers that works with Charles.
In the emulator: Settings -> Network & Internet -> Internet -> Tap on the available Wi-Fi connection (in my case it’s “AndroidWifi”). Connect to this network.
Open the settings for this Wi-Fi network by clicking on the gear icon. Click on the pencil icon (top right corner). Proxy -> Manual. You’ll need to fill in the ‘Proxy hostname’ and ‘Proxy port’ fields. The Proxy Port should be set to 8888. To find out the Proxy Host Name on a Mac, you can check it here: System settings -> Wi-Fi -> Details (next to your Wi-Fi network). Or in Charles: Help -> Local IP Address. So now we can fill in the ‘Proxy hostname’.
After that, you need to install the certificate, following the same process as on a real device: open the browser, enter 'chls.pro/ssl' – the certificate download will happen automatically. You can find it in the notification shade.
All we have left to do is install the certificate.
Here's how: Go to your Android settings, search for 'CA,' choose 'CA certificate,' and install the certificate while approving any prompts.
Done! Now you can launch the app and monitor the traffic.
For iOS simulators, it's easier. You only need to follow these three steps:
Launch a simulator.
Open Charles, then go to Help -> SSL Proxying -> Install Charles Root Certificate in iOS Simulators.
You will see this success screen:
Open the simulator, then navigate to Settings -> General -> About -> Certificate Trust Settings. Enable the Charles Proxy CA.
That’s all! Now you can see the traffic of the app. 😎