Using Monkey in a subactivity only (android debugging)

时光怂恿深爱的人放手 提交于 2019-12-04 08:06:07

I have also had a bit of problems with constraining the monkey with categories. I think it is not intended to work as you assume. How it works then? I have no clear idea, just experimenting with it. The documentation is quite poor.

For your problem you could consider the following approaches

  1. Put your subactivities under one subpackage and permit access to only that subpackage with the -p option
  2. Add some constraints to your code that prevents the navigation inside the app. For example set the onClickListeners to do nothing or disable back button for the activity under test when some specific condition is met.

P.S. You can use adb shell am start in order to start the desired subactivity. Again poor documentation, no example, but the action is the name of the action you have defined inside intent-filter for the activity in your AndroidManifest. Name is the Activity name, for example

adb shell am start -a my.package.app.ACTION1 -n my.package.app/.sub.MyActivity

I know it is bit late but here is more robust way - use code like this:

ActivityManager activityManager;
activityManager =  (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);

if(!activityManager.isUserAMonkey()) {
    //stuff you want to execute anywhere but monkey test
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!