calabash-android在travis [英] calabash-android within travis

查看:359
本文介绍了calabash-android在travis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要在travis中运行calabash-android。 calabash-android工作正常在我的机器没有任何问题。我有以下travis.yml:

I am trying to get calabash-android running within travis. calabash-android works fine within my machine without any problems. I have the following travis.yml:

    language: android
jdk: oraclejdk8
before_cache:
  - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
cache:
  directories:
    - $HOME/.gradle/caches/
    - $HOME/.gradle/wrapper/
    - $HOME/.gradle/daemon
    - $HOME/.gradle/native
env:
  global:
    # wait up to 10 minutes for adb to connect to emulator
    - ADB_INSTALL_TIMEOUT=20
    - SLAVE_AAPT_TIMEOUT=40

android:
  components:
    - platform-tools
    - tools
    - build-tools-23.0.3
    - android-23
    - extra-android-support
    - extra-android-m2repository
    - extra-google-m2repository
    - sys-img-armeabi-v7a-android-23

before_install:
  # install ruby 2.0.0
  - rvm install 2.0.0
  # install calabash-android
  - gem install calabash-android

before_script:
  - echo no | android create avd --force --name test --target android-23 --abi armeabi-v7a
  - emulator -avd test -no-skin -no-audio -no-window -no-boot-anim &
  - android-wait-for-emulator
  - adb shell settings put global window_animation_scale 0 &
  - adb shell settings put global transition_animation_scale 0 &
  - adb shell settings put global animator_duration_scale 0 &
  - adb shell input keyevent 82 & #for unlocking as "powerkey"
  - sleep 3 # give screen some time to become unlocked
  - ./gradlew clean assembleDebug -PdisablePreDex --continue --stacktrace

script:
  - calabash-android resign /home/travis/build/app/build/outputs/apk/app-debug.apk
  - calabash-android run /home/travis/build/app/build/outputs/apk/app-debug.apk

它适用于功能的第一个场景,然后一次开始第二个场景,它显示此错误:

It works with the 1st scenario of the feature and then once it starts 2nd scenario, it shows this error:

App did not start (RuntimeError)
 ./features/support/app_life_cycle_hooks.rb:5:in `Before'

或建议?

推荐答案

删除 -no-boot-anim 选项, android-wait-for-emulator 脚本取决于启动动画来检测仿真器何时准备就绪。

Delete -no-boot-anim option, android-wait-for-emulator script depends on boot animation to detect when the emulator is ready.

我推荐的一个很好的解释:当模拟器准备好时检测

This is a great explanation I recommend: Detecting when emulator is ready to be used


第二步是等待模拟器完全启动,因此可以将
用于运行一些代码。这是最棘手的部分。
特别是对于API级别11+(在
编写时为11-14)的模拟器。

The second step is to wait for emulator to fully boot, so it can be used to run some code. This turned out to be the most tricky part. Especially for emulators with API Level 11+ (11-14 at the time of writing).

首先,模拟器应连接到adb将被列为离线。
在此状态下,模拟器不接受任何shell命令。在这种状态下,没有
。这部分通常很稳定,I
没有看到仿真器启动时,但从未连接到
adb的情况。当然,如果发生一些错误,它将不会连接到adb。因此,
超时应在此处用于检测异常延迟或挂起。

First, emulator should connect to adb and will be listed as "offline". In this state emulator does not accept any shell commands. And nothing can be done in this state. This part is usually very stable and I haven’t seen the case when emulator was started but never connected to adb. Of course if some error occurs, it won’t connect to adb. So timeout should be used here to detect abnormal delays or hangs.

下一状态设备进入称为设备状态。这是当设备
正在引导时。一旦它启动,设备就进入在线状态。
这是当系统开始引导并且模拟器的正常操作
进入时。

Next state device goes to called "device" state. This is when device is booting. As soon as it had booted, device goes to "online" state. This is when system starts booting and normal operation of emulator goes in.

从设备进入设备状态时,adb shell可以使用
在设备上执行不同的命令,并查询一些有用的
关于其状态的信息。

From the moment device goes to "device" state, adb shell can be used to execute different commands on device and query some useful information about its state.

我发现了几个属性跟踪以便
可靠地检测设备是否就绪。第一个属性称为
dev.bootcompleted。设备完成启动后,此属性
将设置为1.

I’ve found several properties that should be tracked in order to reliably detect when device is ready. The first property is called dev.bootcompleted. As soon as device completes booting this property will be set to 1.

dev.bootcompleted为1后,下一个属性为sys.boot_completed
应该被跟踪。一旦系统完成
引导(通常是在发送BOOT_COMPLETED广播时),它将被设置为1。此
属性仅在API Level 9或更高版本的模拟器上设置。在8和
下面这个属性从来不使用(并且不应该跟踪)。

After dev.bootcompleted is 1, next property called sys.boot_completed should be tracked. It will be set to 1 as soon as system completed booting (this is usually when BOOT_COMPLETED broadcast is sent). This property is only set on emulators with API Level 9 or higher. On 8 and lower this property is never used (and shouldn’t be tracked).

但是模拟器还没有准备好,即使当sys.boot_completed是将
设置为1.您会注意到启动动画仍然会运行一些
(有效的)时间段。然后才会出现UI。但是
幸运的是有一种方法来检测这个事件。为此,我们需要
跟踪init.svc.bootanim属性的值。此属性保持引导动画服务的状态
,只要UI出现,它就会停止。
换句话说,一旦init.svc.bootanim的值停止,它的
就会认为仿真器正在运行并可以使用

But emulator is still not ready, even when sys.boot_completed is set to 1. You’ll notice that boot animation will still run for some (significant) period of time. And only then UI will appear. But luckily there is a way to detect this event too. For this we need to track value of init.svc.bootanim property. This property keeps state of boot animation service, that will be stopped as soon as UI appears. In other words, as soon as init.svc.bootanim has value stopped, its safe to assume that emulator is running and ready to be used.

使用 -no-boot-anim 的值为 stopped 在您的模拟器完全启动之前:

Using -no-boot-anim the value is stopped before your emulator is fully-booted:

# Originally written by Ralf Kistner <ralf@embarkmobile.com>, but placed in the public domain

set +e

bootanim=""
failcounter=0
timeout_in_sec=360

until [[ "$bootanim" =~ "stopped" ]]; do
  bootanim=`adb -e shell getprop init.svc.bootanim 2>&1 &`
  if [[ "$bootanim" =~ "device not found" || "$bootanim" =~ "device offline"
    || "$bootanim" =~ "running" ]]; then
    let "failcounter += 1"
    echo "Waiting for emulator to start"
    if [[ $failcounter -gt timeout_in_sec ]]; then
      echo "Timeout ($timeout_in_sec seconds) reached; failed to start emulator"
      exit 1
    fi
  fi
  sleep 1
done

echo "Emulator is ready"






现在我怀疑由于第一个方案的工作(我从来没有使用calabash-android),但我看到它不依赖于模拟器准备:


Now I was doubting due to the first scenario works (I never used calabash-android) but I see that it doesn't depend on the emulator being ready:

< a href =http://stackoverflow.com/questions/27109585/calabash-android-what-does-resign-do> calabash-android - 辞职是什么?


如果您需要签署应用程序以匹配您的密钥库,则使用辞职。
从GitHub docs
复制 https:// github .com / calabash / calabash-android / wiki / Running-Calabash-Android

而不是辞职,您也可以考虑复制您的调试
keystore到您的文件夹。

Instead of resigning you could also consider copying your debug keystore to your folder.

apk calabash android运行必须使用与
测试服务器相同的密钥库进行签名。

The apk calabash android runs must be signed with the same keystore as the test-server.

使用命令: calabash-android resign< apk> 可以辞职。

使用calabash-android构建测试服务器将构建
test-server并使用与
测试的应用程序相同的密钥签名。

Building the test-server using calabash-android build will build the test-server and sign it with the same key as the application you are testing.

第二种情况:

运行测试


运行测试: calabash-android运行< apk>

Calabash-android将在执行应用程序时与您的应用程序
一起安装。我们将这个工具称为test
server。 测试服务器有特殊权限,允许它
在测试期间与您的应用程序非常密切的交互。每次你测试一个
新的二进制或使用升级版本的calabash一个新的测试服务器
将被构建。测试服务器是一个文档,它将在设备上运行
以及您的应用程序来执行测试。

Calabash-android will install an instrumentation along with your app when executing the app. We call this instrumentation for "test server". The "test server" has special permission that allows it to interact very closely with your app during test. Everytime you test a new binary or use an upgraded version of calabash a new test server will be build. The test server is an intrumentation that will run along with your app on the device to execute the test.

这种情况下的其他问题,但修复了此处的相同问题删除 -no-boot-anim

Perhaps exist other issues in this case but fixed the same issue here deleting -no-boot-anim.

这篇关于calabash-android在travis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆