Calabash calabash-android 测试问题收集

超爱fitnesse · August 27, 2014 · Last by 026 replied at October 18, 2016 · 2097 hits
本帖已被设为精华帖!

各个OS下calabash-andriod运行环境需要安装的工具清单

英文和中文Win7(5个工具):

  1. ruby1.9.3
  2. JDK 7u65
  3. Android SDK
  4. Ant-1.9.4
  5. calabash-android

32位Ubuntu 14.04(2个工具):

  1. ruby1.9.3 ——现成的
  2. JDK 7u65 ——现成的, OpenJDK 1.7.0_65
  3. Android SDK Linux 32位
  4. Ant-1.9.4 —— 现成的
  5. calabash-android

64位Ubuntu 14.04(3个工具):

  1. ruby1.9.3 ——现成的
  2. JDK 7u65 ——现成的, OpenJDK 1.7.0_65
  3. Android SDK Linux 64位
  4. lib32z1 lib32ncurses5 lib32stdc++6 ——下面额外说明!
  5. Ant-1.9.4 —— 现成的
  6. calabash-android

说明:

sudo apt-get install lib32z1 lib32ncurses5 lib32stdc++6

Google提供的Android SDK Linux 64位居然是在32位环境下编译的,依赖32位库libz,libsdc++,而64位Ubuntu又把这些库去掉了,所以需要手工安装。

如果上天能够给我一个再来一次的机会,我会对那个女孩子说三个字:Ubuntu。如果非要在这份爱上加上一个期限,我希望是……32位……

中文Win7下的GBK问题

第一次在某手机上用calabash-android run测试某app,calabash要创建test server,打印如下提示:

No test server found for this combination of app and calabash version. Recreating test server.

随后,在中文Win7环境下,会报错:

D:/ruby-1.9.3-p545-i386-mingw32/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.1/lib/calabash-android/helpers.rb:105:in `scan': invalid byte sequence in GBK (ArgumentError)

解决方法:
设置cmd的编码为UTF-8

chcp 65001

再次运行calabash-android run,不再报GBK错误,能正确运行,但是运行结果中"登录"等中文打印为空白。

需要再次设置cmd的编码为GBK:

chcp 936

并运行calabash-android run,既不报GBK错误,也能正确运行,且运行结果中"登录"等中文能正确打印。

接下去,每次更换手机或者更换app(修改代码引起重编或者换一个app)都要重复上面的chcp 65001+chcp 936的步骤。

没办法,如果忍无可忍,建议更换Ubuntu 14.04 32位。

Manifest.xml中未设置网络权限:android.permission.INTERNET

http://my.oschina.net/fitnessefan/blog/305350 中的示例待测应用AndroidDemoProject的Manifest.xml设置了一个唯一的权限:

<uses-permission android:name="android.permission.INTERNET" />

试着把这一行去掉,然后在Eclipse中Run AndroidDemoProject,一切正常。

但是用calabash-android运行,看到错误:

在此输入图片描述

d:\calabash-android-demoapp-master\calabash>calabash-android run ../bin/AndroidD
emoProject.apk
Feature: Demo feature

Scenario: I can start my app # features\my_first
.feature:3
1930 KB/s (544883 bytes in 0.275s)
1673 KB/s (37700 bytes in 0.022s)
Starting: Intent { act=android.intent.action.MAIN cmp=sh.calaba.demoproject.test
/sh.calaba.instrumentationbackend.WakeUp }
App did not start (RuntimeError)
D:/ruby-1.9.3-p545-i386-mingw32/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.
1/lib/calabash-android/operations.rb:532:in `block in start_test_server_in_backg
round'
D:/ruby-1.9.3-p545-i386-mingw32/lib/ruby/gems/1.9.1/gems/retriable-1.3.3.1/lib
/retriable/retriable.rb:31:in `perform'
D:/ruby-1.9.3-p545-i386-mingw32/lib/ruby/gems/1.9.1/gems/retriable-1.3.3.1/lib
/retriable/retriable.rb:53:in `retriable'
D:/ruby-1.9.3-p545-i386-mingw32/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.
1/lib/calabash-android/operations.rb:531:in `start_test_server_in_background'
D:/ruby-1.9.3-p545-i386-mingw32/lib/ruby/gems/1.9.1/gems/calabash-android-0.5.
1/lib/calabash-android/operations.rb:110:in `start_test_server_in_background'
d:/calabash-android-demoapp-master/calabash/features/support/app_life_cycle_ho
oks.rb:15:in `Before'
* I wait for "Hello World, AndroidDemoProject" to appear # calabash-android-
0.5.1/lib/calabash-android/steps/progress_steps.rb:22

Failing Scenarios:
cucumber features\my_first.feature:3 # Scenario: I can start my app

1 scenario (1 failed)
1 step (1 skipped)
0m17.625s

到ADT的LogCat中查看:

在此输入图片描述

可以看到权限不够的提示。我猜是安装在手机的test-server要通过socket发送待测Apk的状态回电脑,但是没有访问socket权限,崩了。

使用发布签名生成的apk,无法用calabash-android测试

在ADT中Export Andriod Application > Create new keystore,生成AndroidDemoProject-release.apk后,

使用calabash-android测试该apk,报如下信息:

d:\calabash-android-demoapp-master\calabash>calabash-android run ../bin/AndroidD
emoProject-release.apk
No test server found for this combination of app and calabash version. Recreatin
g test server.
d:/calabash-android-demoapp-master/bin/AndroidDemoProject-release.apk is not sig
ned with any of the available keystores.
Tried the following keystores:
C:/Users/asus/.android/debug.keystore

You can resign the app with C:/Users/asus/.android/debug.keystore by running:
calabash-android resign d:/calabash-android-demoapp-master/bin/AndroidDemoPr
oject-release.apk

Notice that resigning an app might break some functionality.
Getting a copy of the certificate used when the app was build will in general be
more reliable.

结论是:只有debug签名的apk才能用calabash-android测试
你可以:
1、拿到源代码,在Eclipse中运行一次,就自动编译出来了。
2、或者拿到别人已经编译好的debug签名的apk。

calabash运行时每次重新安装app

  • 每次calabash运行时,会先从手机上卸载该apk,然后重新安装,随后启动
  • 每次calabash运行一个featue文件时,会先从手机上卸载该apk,然后重新安装,随后启动
  • 每次calabash运行一个featue文件中的Scenario时,会先从手机上退出该apk,然后启动

所以,每个featue文件的第一个Scenario,需要做初装apk后的操作,比如:

  • 取消新版本升级
  • 登录
  • 设置使用习惯等等

featue文件的第二个Scenario开始,就可以测试第二次打开以后的功能了。

共收到 8 条回复 时间 点赞

期待总结的更详细更深入

楼主的最后一句话是什么意思呢?意思是说没有源码的情况下,使用debug的签名就能测试,还是说,没有源码就不能使用calabash-android来测试apk呢?

#2楼 @doufuli010
更正一下:
结论是:只有debug签名的apk才能用calabash-android测试
你可以:
1、拿到源代码,在Eclipse中运行一次,就自动编译出来了。
2、或者拿到别人已经编译好的debug签名的apk。

#1楼 @monkey
我现在只有三板斧,但也要跑出来唬人,哈哈!

6Floor has been deleted

"所以,每个featue文件的第一个Scenario,需要做初装apk后的操作,比如:
◾取消新版本升级"
怎么取消新版升级啊?能说的详细点吗?

請問calabash-android resign出現下面這種問題要怎麼解決?
是我哪裡有問題嗎?
C:\calabash-android\all file>calabash-android resign *.apk
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/calabash-android-0.7.2/lib/calabash-andro
id/java_keystore.rb:16:in initialize': undefined methodscan' for nil:NilClass
(NoMethodError)
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/calabash-android-0.7.2/lib/c
alabash-android/java_keystore.rb:116:in new'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/calabash-android-0.7.2/lib/c
alabash-android/java_keystore.rb:116:in
keystore_from_settings'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/calabash-android-0.7.2/lib/c
alabash-android/java_keystore.rb:95:in get_keystores'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/calabash-android-0.7.2/lib/c
alabash-android/helpers.rb:157:in
sign_apk'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/calabash-android-0.7.2/lib/c
alabash-android/helpers.rb:118:in block in resign_apk'
from C:/Ruby22-x64/lib/ruby/2.2.0/tmpdir.rb:88:in
mktmpdir'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/calabash-android-0.7.2/lib/c
alabash-android/helpers.rb:112:in resign_apk'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/calabash-android-0.7.2/bin/c
alabash-android:127:in
'
from C:/Ruby22-x64/bin/calabash-android:23:in load'
from C:/Ruby22-x64/bin/calabash-android:23:in

'

刚才提示找不到Android sdk。。。也是醉了,我环境中有sdk。。。

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up