Search code examples
androidshelltestingadbmonkey

Detecting out of package issue in Android Testing with ADB Shell


I create a set of random adb shell events as an Android test case. Then I run this test on an app to collect some data for my research. The only problem is that sometimes those random events do something (e.g., clicking on HOME, BACK,or CLOSE etc.) that the app goes to background. As a result, rest of the events, instead of working on the selected app, execute on outside apps (such as changes the settings of the phone).

Android Monkey does not have this problem as it can detect when the test goes out of the given package.

I am curious if I can do similar with adb shell. Any idea/help will be highly appreciated.


Solution

  • I actually got the answer. I need to just check the package name of the focused app. If it's not the expected one, then I am out of the package right now. Thanks to another SO post. Here is the shell command for that.

    adb shell dumpsys window windows | grep -E 'mFocusedApp'| cut -d / -f 1 | cut -d " " -f 7