Search code examples
androidcalabashcalabash-android

Calabash - Send app to background and come back (Android)


I'm testing my android app with Calabash and everything is fine except for a small detail. I override onPause() and onResume() method to perform certain actions and I would like to test them. The problem is I'm not sure about how to do it with calabash.

I read we can send the app to the background executing

system("adb shell input keyevent KEYCODE_HOME")

Ref: (Calabash -Android: Can we simulate Home button on Android devices for Calabash-Android?)

That is ok for test onPause() method but I also need to test onResume()and for that I need to come back into the app. Is that possible?

Thank you!


Solution

  • I'll admit I have no experience with Calabash, but since it seems you have access to adb, you could use the "am" command within adb to launch an activity:

    adb shell am start -n com.somepackagename/com.somepackagename.SomeActivityName
    

    Just enter your app's package and activity class name here and it will emulate you starting the app from the launcher.

    Note however that depending on the launch mode (singleTop etc) of your activity this could however either result in a new instance of your activity being launched, or the one running in the background being resumed.