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?
3 Answers
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

- 616
- 6
- 17

- 640
- 1
- 5
- 21
-
I've been looking into little proxy as well. Filtering Android logcat seems like an easier solution. Do you know if iOS has a logger that can be parsed for the HTTP traffic data as well? – Bruce Tu Mar 21 '16 at 17:49
-
you have two options for IOS iconsole https://github.com/nicklockwood/iConsole and idevicesyslogs http://www.libimobiledevice.org/. Also you could send me 1000$ to get a working code for your project. :) – vishal Apr 01 '16 at 19:45
-
1ah... I think I found a way. I am getting the logs from the driver via driver.manage().logs().get("logcat") for Android and driver.manage().logs().get("syslog") for iOS – Bruce Tu Apr 01 '16 at 20:41
-
are you using Appium? if not then what are you using? – vishal Apr 02 '16 at 02:06
-
yes, I am using Appium. I did something similar to this: http://stackoverflow.com/questions/28557828/appium-how-to-get-adb-logcat – Bruce Tu Apr 04 '16 at 14:50