简体   繁体   English

使用Ruby的Android Emulator Shell脚本

[英]Android Emulator Shell Scripting with Ruby

We are developing a ruby script that executes a bunch of shell commands to launch the emulator and run some calabash tests. 我们正在开发一个ruby脚本,它执行一堆shell命令来启动模拟器并运行一些calabash测试。

PID = fork do
    Signal.trap('HUP') { puts 'PROCESS ENDED'; exit }
    exec 'emulator -avd TestDevice1'
end

fork do
    sleep(55)
    exec 'adb shell input keyevent 82'
end

fork do
    sleep(60)
    exec 'calabash-android run ~/MyApp/MyApp.apk'
    Process.Kill('HUP', PID)
end

We are currently using sleep commands so that the calabash tests don't run until the emulator is fully ready. 我们当前正在使用sleep命令,因此在模拟器完全就绪之前,calabash测试不会运行。 This is not ideal. 这不太理想。 Is there an Android command to check if the device is ready? 是否有Android命令来检查设备是否准备好了? By that I mean Android has booted up and the lock screen is displayed. 我的意思是Android已经启动并显示锁定屏幕。

The most reliable way I have found to detect if the emulator is ready for use, and for Calabash to start the installation process, is to detect when the bootanim has stopped. 我发现检测仿真器是否可以使用以及Calabash启动安装过程的最可靠方法是检测bootanim何时停止。

You can check whether the emulator has finished booting manually with using ADB in a terminal: 您可以使用终端中的ADB检查模拟器是否已完成手动引导:

adb shell getprop init.svc.bootanim

I have the following in a Rake command as part of a Calabash test suite which does the trick: 作为Calabash测试套件的一部分,我在Rake命令中有以下内容可以解决这个问题:

booting = ''

while booting != 'stopped'
  booting = `adb shell getprop init.svc.bootanim`.strip
  puts 'Waiting for emulator to boot'
  sleep 2
end

Hope it works for you! 希望这对你有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM