How can I use Appium to capture network traffic during mobile app automation?

We had a similar requirement and ended up integrating mitmproxy with Appium. Basically, we routed all device traffic through a mitmproxy running on the test machine.

It acts as a programmable man-in-the-middle proxy, letting us capture and even assert API requests during the test.

We configured the device to trust the proxy certificate and set the proxy at the system level for Android and iOS simulators. It took a little setup but gave us full visibility without touching app code. Totally worth it.