0

Is there a way in Calabash Android where I can send my app to the background? In other words, simulate the device/hardware Home button?

Secondly, can the app be brought back into the foreground?

Noffica
  • 469
  • 8
  • 23

2 Answers2

3

This can be done in the following way:

Then /^I go home$/ do
  system "#{default_device.adb_command} shell input keyevent KEYCODE_HOME"
end


P.S. You can also add sleep <some_value_in_seconds> if necessary, after system "..." line.

  • I advice also to read http://krazyrobot.com/2014/02/calabash-android-enter-text-from-keyboard-using-adb/. You can use `keyboard_enter_keyevent` method from there. So it will be as `keyboard_enter_keyevent('KEYCODE_HOME')` – Dmitry Cheremushkin May 14 '14 at 08:14
1

As far as I know, that action does not currently exist. You can find (mostly) all of the available operations here https://github.com/calabash/calabash-android/tree/master/ruby-gem/lib/calabash-android. Most of the interesting options are in the operations.rb file. The performAction method would be the method most likely to help you as it has a 'go_back' and 'press_menu' feature, but currently no 'go_home' feature. When you're in a calabsh console, you can type performAction 'list_actions' to see all possible actions. I'm not sure if it's a reasonable workaround, but you could try something like this:

until (query "*").empty? do
  performAction 'go_back'
end

This will sipmly press the back button until you've arrived on the home screen. If you'd like to get back to your app, however, you'd need to re-run start_test_server_in_background as you will not be able to get any query information from the home screen. Anyways, good luck and I hope I could help out at least a little!

arc
  • 477
  • 2
  • 8
  • 14