📱 Capture Your Mobile Application’s Network Logs from Automation – Part 1

🤔 Why Are Network Logs a Game-Changer for Mobile Test Automation?

Ever been in this situation?

✅ Your automated mobile tests run fine locally.
✅ They pass on your machine.
✅ But once they run on CI/CD, they mysteriously fail. 😱

Now you’re left scratching your head wondering:

  • Did the app fail? 🤷

  • Did the API return an error? 🧐

  • Did some background service just die silently? 💀

Let’s face it—debugging test failures without proper network logs is like finding a needle in a haystack.

But what if you could see every request and response your app sends and receives in real time? 🎯

Welcome to MITM Proxy—the ultimate debugging tool that lets you capture and analyze your app’s network traffic like a pro! 🚀

This guide will help automation engineers, testers, and even curious college students set up MITM Proxy to monitor, capture, and debug mobile network traffic while running automation tests.

So, grab your coffee ☕, because we’re about to make debugging 100x easier!


🎯 What Will We Cover?

This is a 3-part series to help you integrate MITM Proxy into your mobile automation framework:

Part 1 (This Article) – Set up MITM Proxy with an Android/iOS device.
Part 2 – Capture and save real-time network logs for deeper analysis.
Part 3 – Add automation-specific network logs to your HTML test reports.

By the end of this series, you’ll be a debugging ninja. 🥷🔥


🔍 What is MITM Proxy? And Why Should You Care?

💡 MITM Proxy stands for Man-in-the-Middle Proxy, a powerful tool that allows you to:

Intercept all network traffic from your mobile app.
Inspect HTTP & HTTPS requests in real time.
Modify API responses for testing different scenarios.
Replay previous API calls without re-running the entire test.

Why Are We Using MITM Proxy Instead of Other Tools?

FeatureMITM ProxyCharles ProxyFiddlerWireshark
Intercepts Requests in Real-Time
Works for Mobile Apps (Android/iOS)
Modify API Responses Dynamically
Command-Line Friendly (Great for CI/CD)
Lightweight & Open Source❌ (Paid)❌ (Paid)

MITM Proxy is like Wireshark, but built for automation engineers! 🛠

🛠 Setting Up MITM Proxy with an Android/iOS Device

Step 1: Install MITM Proxy

If you’re on Mac, install it using Homebrew

brew install mitmproxy

For Windows/Linux, check the official installation guide.


Step 2: Start the MITM Proxy** Server**

Now, let’s fire up MITM Proxy so it can start listening for network requests:

mitmdump --listen-port 8090

This starts the proxy on port 8090 and captures ALL traffic.

To capture traffic only for a specific domain, run:

mitmdump --listen-port 8090 "example.com"

You can also use mitmproxy instead of mitmdump if you prefer an interactive UI.

Step 3: Configure Proxy Settings on Your Mobile Device

Your phone needs to route all network traffic through MITM Proxy.

🔎 Find Your Private IP Address

We need the IP address of the machine running MITM Proxy.

  • Mac/Linux:

      ifconfig | grep -i mask
    

    Look for an IP that starts with 192.168.x.x.

  • Windows:
    Open CMD and type:

      ipconfig
    

    Find your IPv4 Address under your active network connection.


📱 Configure Proxy in Mobile Network Settings

For Real Devices:

1️⃣ Connect your phone to the same WiFi network as your laptop/PC.
2️⃣ Open WiFi Settings → Tap on your current network. (Connect your device to the same network as the device running proxy server)
3️⃣ Find "Proxy Settings" and set:

  • Proxy Type: Manual

  • Proxy Host: Your private IP (from previous step)

  • Proxy Port: 8090
    4️⃣ Save and exit.

Connect your device to the same network as the proxy device

  • Open Network Settings -> Goto Wifi

  • Open Network Details

  • Edit connection and configure proxy settings, make sure to put the correct private IP Address and port

  • For Emulators:

    If you’re using an emulator, start it with:

      emulator -avd <EMULATOR_NAME> -http-proxy http://<YOUR_PRIVATE_IP>:8090
    

    🚀 Now your device/emulator is sending network traffic through MITM Proxy!


    Step 5: Intercept HTTPS Traffic (Important for Most Apps!)

    🚨 By default, MITM Proxy only captures HTTP traffic. But most modern apps use HTTPS.

    To capture secure API requests, we need to install the MITM CA Certificate.

    📥 Install the MITM CA Certificate

    For Android:

    1️⃣ Open your mobile browser and go to mitm.it. 2️⃣ Download the MITM CA Certificate.

3️⃣ Install it via mitm.it:

Settings → Security → Encryption & Credentials → Install a Certificate → CA Certificate

4️⃣ Select VPN and Apps → Tap OK.

For iOS:

1️⃣ Visit mitm.it in Safari.
2️⃣ Download the CA Certificate.
3️⃣ Go to Settings → General → Profile → Install Certificate.
4️⃣ Enable Full Trust under Settings → General → About → Certificate Trust Settings.

Step 6: Make Your App Respect the Certificate (For Debugging Only!)

Android apps ignore user-installed certificates by default. If you're debugging, update network_security_config.xml:

<network-security-config xmlns:tools="http://schemas.android.com/tools">
    <debug-overrides>
        <trust-anchors>
            <certificates src="system" />
            <certificates src="user" />
        </trust-anchors>
    </debug-overrides>
</network-security-config>

🚨 Warning: NEVER do this in a production app!


🎯 What’s Next?

MITM Proxy is set up!
Your device is connected!
You can now capture mobile API traffic! 🎉

👉 In Part 2, we’ll:
Save intercepted requests to a log file.
Filter traffic based on API endpoints.
Use captured logs for debugging and automation reports.

Stay tuned! 🚀

💬 Questions? Thoughts? Drop a comment!

🔜 Coming up in Part 2: Saving logs & integrating with Appium! 🎯

0
Subscribe to my newsletter

Read articles from Himanshu Nikhare directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Himanshu Nikhare
Himanshu Nikhare

I am a Senior Software Engineer at BigBasket with over three years of experience in software development. Specializing in QA automation, CI/CD, and mobile automation, I am passionate about creating efficient workflows and sharing knowledge through blogs and articles. I actively contribute to the tech community through my work, open-source projects, and insightful content. Feel free to connect with me on GitHub or LinkedIn to explore my projects and contributions.