1

即使我也将其作为问题发布在葫芦 github 上,我仍将其发布在这里,因为已经 3 周了,我还没有收到任何来自支持的消息。如果您发现我做错了什么,或者您遇到过同样的问题,请告诉我。目前我在 ruby​​ 1.9.3 上运行 Calabash-Android v 0.5.8。我已经在旧版本的 Calabash-Android 中对此进行了测试,但仍然存在同样的问题。

我一直在尝试研究如何提高我设置的测试的性能,我从一开始就从葫芦中发现的一个问题是该应用程序似乎重复了app_life_cycle_hooks.rb文件中的调用。每当我的测试运行时,都会生成一个测试服务器并启动应用程序,然后生成另一个测试服务器并且它们会重新启动应用程序。失败时,会截取两张屏幕截图,而不是一张。在“-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
4

0 回答 0