4

Sometimes, WIFI is turned off with following command to run monkey test on Android. Is there any method to prevent the Android monkey to turn off WIFI?

adb -s foo shell monkey -p com.foo.bar --throttle 300 --kill-process-after-error --pct-syskeys 0 --pct-trackball 0 --pct-touch 90 --pct-motion 10 -v 5000
Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
sdet_liang
  • 41
  • 2
  • I know you asked a solution for monkey, but if you can't find one perhaps [AndroidViewClient/culebra](https://github.com/dtmilano/AndroidViewClient)'s **[concertina mode](http://dtmilano.blogspot.ca/2015/08/culebra-concertina-mode.html)** could help you: "culebra concertina mode that instead of sending pseudo-random events, analyzes the content of the screen and randomly selects a suitable event or action for the also randomly selected target, normally a View." – Diego Torres Milano Jan 19 '18 at 05:35

1 Answers1

1

To avoid system events in Monkey testing there is option --pct-syskeys which is responsible for system level events but I think --pct-syskeys 0 is not working.

There is work around for this, Screen Pinning your app. By doing this only your app will be tested and will not turn off Wi-Fi and you can perform your testing. Follow below steps:

  1. Go to Settings > Security and Location > Turn on Screen Pinning
  2. Launch your app and click on Overview button (right most button next to Home button) and pin your app
  3. Now run your monkey command from terminal and test your app

Note: If your are testing on Emulator. Once you are done with testing, to unpin your app you must have to restart your Emulator. Restart emulator is the only option to unpin your app on Emulator.

Above testing is done on Android 8 emulator.

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
  • 1
    Many thanks for the solution. Could we pin the app to screen by commands or some other automation methods? As the app will be uninstalled and installed before monkey test runs. – sdet_liang Jan 19 '18 at 08:21
  • @sdet_liang, yes we can do it programmatically inside the code. Check here the details: https://developer.android.com/about/versions/android-5.0.html#ScreenPinning You can add check in code if running test build then call the startLockTask() function. Details here: https://developer.android.com/reference/android/app/Activity.html#startLockTask() – Vikasdeep Singh Jan 19 '18 at 08:30
  • @sdet_liang did this solution help you? If yes then please upvote it so that if other will also face this issue they can refer to this answer. – Vikasdeep Singh Feb 27 '18 at 01:58