Calabash Android: how to send app to the background (simulate device/hardware Home button)?

喜你入骨 提交于 2020-01-11 12:59:06

问题


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?


回答1:


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.




回答2:


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!



来源:https://stackoverflow.com/questions/22393894/calabash-android-how-to-send-app-to-the-background-simulate-device-hardware-ho

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!