Search code examples
javaandroidiosjunitappium

How do I monitor iOS simulator/Android emulator's HTTP traffic from Appium JUnit tests?


So I am writing JUnit tests for iOS/Android apps using Appium to drive the tests on an iOS simulator and Android emulator. The app sends and receives HTTP calls to a remote server. I would like to test that the app is sending the correct HTTP traffic from my JUnit tests. What are some ways that I can monitor the network traffic from within my code?


Solution

  • I had the same issue a few months back and tried two solutions for it.

    1) Use a proxy in your code. I tried a little proxy. I kind of liked it but it increased my overhead for maintaining little proxy code as well. It works if you have extremely advanced knowledge with proxies; you will be able to handle it. https://github.com/ganskef/LittleProxy-mitm

    2) I finally figured out it's best to use Android logcat. Whatever communication our phones do, everything gets logged in logcat. I just needed some commands to filter out the network requests that my App was making. I don't remember all of the commands but it's something like this. I know its not correct, but it will give you a headstart and I am 100% sure someone will correct this.

    adb logcat -d | grep com.xyz.abc