Reputation: 559
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!
Upvotes: 0
Views: 1746
Reputation: 1
I have implemented this the following way - ignore the ipad and iphone steps if they don't apply to you.
Then(/^I deactivate app for (\d+) seconds$/) do |arg1|
if $device == "ipad" || $device == "iphone"
send_uia_command(:command => "target.deactivateAppForDuration(5)")
elsif $device == "androidtablet" || $device == "androidphone"
system("#{default_device.adb_command} shell input keyevent KEYCODE_HOME")
sleep(5)
system("#{default_device.adb_command} shell am start -n com.somepackagename/com.somepackagename.SomeActivityName")
sleep(2)
end
end
Upvotes: 0
Reputation: 4281
Technically not supported... below this I have my workaround that seems to work.
http://www.rubydoc.info/gems/calabash-android/0.5.8/Calabash/Android/Operations:app_to_background
Not implemented yet
def app_to_background(secs)
ni
end
In my feature file:
@automated @high @test
Scenario Outline: Login with keep me signed in background and relaunch
Given I am on the Login page
When I check keep me signed in
When I log into Overview page with "<acct>"
When I background the app
When I relaunch the app
Then I am on the Overview page
My step definitions to background and relaunch:
When /I background the app/ do
`adb shell input keyevent KEYCODE_HOME`
sleep(5)
end
When /I relaunch the app/ do
attempts = 0
begin
attempts = attempts + 1
start_test_server_in_background
rescue RuntimeError => e
retry if attempts < 3
end
sleep(5)
end
start_test_server_in_background (above) takes me right back into the app and not the Login screen. You notice in my steps that I have When I check keep me signed in
. I don't know how reliable this all is but it works for the application that I am testing.
Upvotes: 2
Reputation: 9315
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.
Upvotes: 1