我在这里张贴这个,尽管我在calabash github上发布了这个问题,因为已经有3个星期了,而且我没有听到任何支持。如果你看到我做错了,或者你遇到了同样的问题,请告诉我。目前我在ruby 1.9.3上运行Calabash-Android v 0.5.8。我已经在旧版本的Calabash-Android中对此进行了测试,但仍存在同样的问题。
我一直在努力研究提高我设置的测试的性能,我从一开始就从calabash发现的一个问题是应用程序似乎在 app_life_cycle_hooks.rb中重复调用< / strong>文件。每当我的测试运行时,就会生成测试服务器并启动应用程序,然后生成另一个测试服务器并重新启动应用程序。如果失败,则会截取两个屏幕截图而不是一个。以“-v”模式运行测试会显示这些调用两次(由下面的星号表示):
2015-03-24 12:00:38 - Found tools directory at '/Developer/android/sdk/build-tools/17.0.0'
2015-03-24 12:00:38 - Trying to find launchable activity
2015-03-24 12:00:38 - Found tools directory at '/Developer/android/sdk/build-tools/17.0.0'
2015-03-24 12:00:38 - Found launchable activity 'com.XXXX.YYYY.MainActivity'
2015-03-24 12:00:38 - Found tools directory at '/Developer/android/sdk/build-tools/17.0.0'
****2015-03-24 12:00:38 - Starting test server using:
2015-03-24 12:00:38 - "/Developer/android/sdk/platform-tools/adb" -s a35e9829 shell am instrument -e target_package com.XXXX.YYYY -e main_activity com.XXXX.YYYY.MainActivity -e test_server_port 7102 -e class sh.calaba.instrumentationbackend.InstrumentationBackend com.XXXX.YYYY.test/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner
2015-03-24 12:00:38 - Checking if instrumentation backend is ready
2015-03-24 12:00:38 - Is app running? true
2015-03-24 12:00:38 - Instrumentation backend not yet ready
2015-03-24 12:00:41 - Checking if instrumentation backend is ready
2015-03-24 12:00:41 - Is app running? true
2015-03-24 12:00:41 - Instrumentation backend is ready!
2015-03-24 12:00:41 - Checking client-server version match...
2015-03-24 12:00:41 - Action: version - Params:
2015-03-24 12:00:42 - Result:'{"bonusInformation":[],"message":"0.5.8","success":true}'
2015-03-24 12:00:42 - Client and server versions match (client: 0.5.8, server: 0.5.8). Proceeding...
2015-03-24 12:00:42 - connected_devices: ["a35e9829"]
2015-03-24 12:00:42 - "/Developer/android/sdk/platform-tools/adb" -s a35e9829 forward tcp:34779 tcp:7102
2015-03-24 12:00:42 -
2015-03-24 12:00:42 - Action: set_activity_orientation - Params: portrait
2015-03-24 12:00:43 - Result:'{"bonusInformation":[],"message":"","success":true}'
2015-03-24 12:00:43 - Found tools directory at '/Developer/android/sdk/build-tools/17.0.0'
2015-03-24 12:00:43 - Trying to find launchable activity
2015-03-24 12:00:43 - Found tools directory at '/Developer/android/sdk/build-tools/17.0.0'
2015-03-24 12:00:43 - Found launchable activity 'com.XXXX.YYYY.MainActivity'
2015-03-24 12:00:43 - Found tools directory at '/Developer/android/sdk/build-tools/17.0.0'
**2015-03-24 12:00:43 - Starting test server using:
2015-03-24 12:00:43 - "/Developer/android/sdk/platform-tools/adb" -s a35e9829 shell am instrument -e target_package com.XXXX.YYYY -e main_activity com.XXXX.YYYY.MainActivity -e test_server_port 7102 -e class sh.calaba.instrumentationbackend.InstrumentationBackend com.XXXX.YYYY.test/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner
2015-03-24 12:00:44 - Checking if instrumentation backend is ready
2015-03-24 12:00:44 - Is app running? true
2015-03-24 12:00:44 - Instrumentation backend not yet ready
下面你会找到我正在使用的 app_life_cycle_hooks 文件,没有重复通话的可能性,或者是什么,它是通过 calabash-android gen 创建的。我为屏幕添加了一个帮助器,它将在测试开始时将Android设备旋转到正确的方向,而不是在当前处于什么方向,但是这不应该影响产生多个服务器,因为代码可以被撕掉并且结果相同还是表明。引擎盖下的东西似乎多次访问我的* apps_life_cycle_hooks **文件。
#require 'calabash-android/management/adb'
require 'calabash-android/operations'
require_relative '../helpers/screen'
Before do |scenario|
if (scenario.source_tag_names.include?('@reset'))
clear_app_data
end
start_test_server_in_background
$screen = Screen.new
$screen.rotate_to_proper_position()
end
After do |scenario|
if scenario.failed?
print "Test failed: #{scenario.name}\n"
if scenario.exception.message =="HTTPClient::KeepAliveDisconnected" || scenario.exception.message =="EOFError"
puts "*********HTTP error!! attempting to restart test server!*************"
reinstall_test_server
start_test_server_in_background
end
if scenario.failed?
screenshot_embed
end
end
shutdown_test_server
end
**编辑:同时添加屏幕文件
require 'calabash-android/operations'
class Screen
include Calabash::Android::Operations
def size
return @size
end
def device
return @device
end
def get_screen_size()
window = query('*')[0]["class"]
dm = query(window,:getResources,:getDisplayMetrics)[0]
x = (dm["widthPixels"]/dm["xdpi"])**2
y = (dm["heightPixels"]/dm["ydpi"])**2
inches = Math.sqrt(x+y)
@size= inches.round(1)
end
def check_device()
screenSize = get_screen_size()
if(screenSize >=6.5 )
@device = "tablet"
else
@device = "phone"
end
end
def rotate_to_proper_position
device = check_device()
if(device.eql? "phone")
perform_action('set_activity_orientation', 'portrait')
else
perform_action('set_activity_orientation', 'landscape')
end
end
end
编辑2 我正在粘贴一个功能的完整日志,其中测试服务器无故启动两次
Using the android profile...
@areachart
Feature: AreaChart Visualization
Background: # features/areachart.feature:4
2015-04-02 10:59:25 - connected_devices: ["192.168.56.101:5555"]
2015-04-02 10:59:25 - "/Developer/android/sdk/platform-tools/adb" -s 192.168.56.101:5555 forward tcp:34777 tcp:7102
4/2/15 10:59
2015-04-02 10:59:25 - Found tools directory at '/Developer/android/sdk/build-tools/17.0.0'
2015-04-02 10:59:25 - Trying to find launchable activity
2015-04-02 10:59:25 - Found tools directory at '/Developer/android/sdk/build-tools/17.0.0'
2015-04-02 10:59:25 - Found launchable activity 'com.XXXX.YYYY.MainActivity'
2015-04-02 10:59:25 - Found tools directory at '/Developer/android/sdk/build-tools/17.0.0'
2015-04-02 10:59:25 - Starting test server using:
2015-04-02 10:59:25 - "/Developer/android/sdk/platform-tools/adb" -s 192.168.56.101:5555 shell am instrument -e target_package com.XXXX.YYYY -e main_activity com.XXXX.YYYY.MainActivity -e test_server_port 7102 -e class sh.calaba.instrumentationbackend.InstrumentationBackend com.XXXX.YYYY.test/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner
2015-04-02 10:59:25 - Checking if instrumentation backend is ready
2015-04-02 10:59:25 - Is app running? true
2015-04-02 10:59:25 - Instrumentation backend not yet ready
2015-04-02 10:59:28 - Checking if instrumentation backend is ready
2015-04-02 10:59:28 - Is app running? true
2015-04-02 10:59:28 - Instrumentation backend is ready!
2015-04-02 10:59:28 - Checking client-server version match...
2015-04-02 10:59:28 - Action: version - Params:
2015-04-02 10:59:28 - Result:'{"bonusInformation":[],"message":"0.5.8","success":true}'
2015-04-02 10:59:28 - Client and server versions match (client: 0.5.8, server: 0.5.8). Proceeding...
2015-04-02 10:59:28 - Found tools directory at '/Developer/android/sdk/build-tools/17.0.0'
2015-04-02 10:59:28 - Trying to find launchable activity
2015-04-02 10:59:28 - Found tools directory at '/Developer/android/sdk/build-tools/17.0.0'
2015-04-02 10:59:28 - Found launchable activity 'com.XXXX.YYYY.MainActivity'
2015-04-02 10:59:28 - Found tools directory at '/Developer/android/sdk/build-tools/17.0.0'
2015-04-02 10:59:28 - Starting test server using:
2015-04-02 10:59:28 - "/Developer/android/sdk/platform-tools/adb" -s 192.168.56.101:5555 shell am instrument -e target_package com.XXXX.YYYY -e main_activity com.XXXX.YYYY.MainActivity -e test_server_port 7102 -e class sh.calaba.instrumentationbackend.InstrumentationBackend com.XXXX.YYYY.test/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner
2015-04-02 10:59:28 - Checking if instrumentation backend is ready
2015-04-02 10:59:28 - Is app running? true
2015-04-02 10:59:28 - Instrumentation backend not yet ready
2015-04-02 10:59:31 - Checking if instrumentation backend is ready
2015-04-02 10:59:31 - Is app running? true
2015-04-02 10:59:31 - Instrumentation backend is ready!
2015-04-02 10:59:31 - Checking client-server version match...
2015-04-02 10:59:31 - Action: version - Params:
2015-04-02 10:59:31 - Result:'{"bonusInformation":[],"message":"0.5.8","success":true}'
2015-04-02 10:59:31 - Client and server versions match (client: 0.5.8, server: 0.5.8). Proceeding...
2015-04-02 10:59:32 - connected_devices: ["192.168.56.101:5555"]
2015-04-02 10:59:32 - "/Developer/android/sdk/platform-tools/adb" -s 192.168.56.101:5555 forward tcp:34777 tcp:7102
4/2/15 10:59
Given I am on the passcode screen # features/step_definitions/passcode_steps.rb:1
And The passcode I enter for passcode screen is 1111 # features/step_definitions/passcode_steps.rb:18
2015-04-02 10:59:33 - connected_devices: ["192.168.56.101:5555"]
2015-04-02 10:59:33 - "/Developer/android/sdk/platform-tools/adb" -s 192.168.56.101:5555 forward tcp:34777 tcp:7102
4/2/15 10:59
2015-04-02 10:59:34 - connected_devices: ["192.168.56.101:5555"]
2015-04-02 10:59:34 - "/Developer/android/sdk/platform-tools/adb" -s 192.168.56.101:5555 forward tcp:34777 tcp:7102
4/2/15 10:59
Then I am on the main screen # features/step_definitions/main_steps.rb:1
@AreaNoLegend
Scenario: No Legend # features/areachart.feature:22
2015-04-02 10:59:35 - Action: clear_text - Params:
2015-04-02 10:59:35 - Result:'{"bonusInformation":[],"message":"","success":true}'
touch failed! re-trying touching AreaChartSingle_NoLegend
When I search for and tap dashboard "AreaChartSingle_NoLegend" # features/step_definitions/main_steps.rb:52
2015-04-02 10:59:36 - connected_devices: ["192.168.56.101:5555"]
2015-04-02 10:59:36 - "/Developer/android/sdk/platform-tools/adb" -s 192.168.56.101:5555 forward tcp:34777 tcp:7102
4/2/15 10:59
Then I am on the dashboard screen # features/step_definitions/dashboard_steps.rb:1
Then the legend is not visible # features/step_definitions/commonchart_steps.rb:411
2015-04-02 10:59:37 - It looks like your app is no longer running.
It could be because of a crash or because your test script shut it down.
2015-04-02 10:59:37 - It looks like your app is no longer running.
It could be because of a crash or because your test script shut it down.
2015-04-02 10:59:37 - Server not responding. Moving on.
1 scenario (1 passed)
6 steps (6 passed)
0m12.774s