calabash-android跨进程实现
一、添加依赖UiAutomator2 api
由于calabash-android的底层框架使用的是Robotium,它是基于Instrumentation的测试框架,所以calabash-android的局限性就在于不可跨进程,calabash-android要实现跨进程,理论上只需要其使用UiAutomator2的api即可
使用android studio打开calabash/calabash-android/sever,在build.gradle中添加依赖:
androidTestImplementation'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
添加并同步完成后会报错:minSdkVersion至少为18,将代码20行改为18再次同步即可

二、实例化的UiDevice对象
以设备休眠为例,我们先写一个设备休眠的方法

三、calabash-android中添加对应的action
路径:/calabash/calabash-android/ruby-gem/lib/calabash-android/steps/
Then /^ui sleep device$/ do
perform_action('ui_sleep')
end
添加的step记得在calasbh_steps.rb注册
路径:/calabash-android/ruby-gem/lib/calabash-android/calabash_steps.rb

四、使用-w标志启动检测
在calabash-android中修改lib / calabash-android / operations.rb以在使用ADB命令启动检测时添加'-w'标志。
路径:/calabash-android/ruby-gem/lib/calabash-android/operations.rb
请参阅这里来了解怎么执行这个操作
(其中-号为删除该行代码,+号为添加该行代码)
五、在测试项目中将“start_test_server_in_background”改为“start_test_server_in_background(with_uiautomator: true) ”

运行结果:

至此,calabash-android实现跨进程自动化测试