【发布时间】:2016-02-15 04:58:18
【问题描述】:
我的环境:Xcode:7.2.1 模拟器:iOS iPad Air 9.1 葫芦:0.17.1
目前,在我的应用程序后台运行后,我的 iOS 应用程序无法正确触摸按钮。以下是出现问题的一般黄瓜步骤:
When I send the app to the background for 2 seconds
And I skip logging in to MyApp
And I wait and wait
And I should see "Speed"
And I wait for 10 seconds
And I touch "Speed"
这是将应用程序发送到后台步骤的代码:
Given /^I send the app to the background for ([\d\.]+) second(?:s)?$/ do |num_seconds|
num_seconds = num_seconds.to_f
send_app_to_background(num_seconds)
end
基本上,只有在我将应用程序发送到后台后,触摸才会遇到障碍。如果我迈出这一步,葫芦会像预期的那样触摸按钮。我包括了它看到“速度”的步骤,只是为了确保 Calabash 可以实际看到按钮,因为它在该步骤以及等待步骤中变为绿色。但是在触摸“速度”时,葫芦进入了一个它一直试图触摸它的状态,但由于它没有,它会无限期地挂在那个步骤上。我怀疑这可能是 Calabash 或 UIAutomation 错误 (https://github.com/calabash/calabash-ios/issues/836),因为一切都按预期工作,直到或除非我将我的应用程序发送到后台,但我想 100% 确定,以防我做错了什么我没看到。
有没有人知道这个问题可能是什么?
更新:
根据https://groups.google.com/forum/#!topic/calabash-ios/NZAmTp6ckrk,将应用程序发送到后台仍未实现,当我检查 send_app_to_background 的代码时,它确实看起来像这样:
def send_app_to_background(secs)
raise 'Not implemented when running without instruments / UIA'
end
有没有人可以为他们的测试解决这个问题?在物理设备上运行它对我来说不是一个选项,它必须使用模拟器来完成。
更新:
在https://github.com/calabash/calabash-ios/issues/556 之后,我更改了将应用程序发送到后台代码以遵循解决方法:
Given /^I send the app to the background for ([\d\.]+) second(?:s)?$/ do |num_seconds|
num_seconds = num_seconds.to_f
uia_send_app_to_background(num_seconds)
end
而uia_send_app_to_background的实现是:
def uia_send_app_to_background(secs)
#uia_handle_command(:deactivate, secs)
#Temporary workaround: https://github.com/calabash/calabash-ios/issues/556
js_deactivate = %Q[var x = target.deactivateAppForDuration(#{secs}); var MAX_RETRY=5, retry_count = 0; while (!x && retry_count < MAX_RETRY) { x = target.deactivateAppForDuration(#{secs}); retry_count += 1}; x]
uia(js_deactivate)
end
但是,对我来说,这种解决方法似乎不起作用。该应用程序被推到后台,但永远不会回到前台。等待几分钟后,当我在 irb 中停止该步骤时,出现此错误:
When I send the app to the background for 2 seconds # features/step_definitions/common.rb:91
Could not parse response ''; the app has probably crashed (RuntimeError)
./features/step_definitions/common.rb:93:in `/^I send the app to the background for ([\d\.]+) second(?:s)?$/'
features/display_mapping_units_from_2630.feature:216:in `When I send the app to the background for 2 seconds'
更新
我尝试了这些解决方法步骤,但在后台处理后触摸仍然不起作用,我也在 8.4 模拟器上尝试过,它也不起作用,这让我更加怀疑这是需要的 Xcode 7+ 问题待解决:
When(/^I background the app$/) do
open_app_via_simctl("com.apple.mobilesafari")
sleep(2)
end
When(/^I launch the app$/) do
open_app_via_simctl("com.me.MyApp-cal")
sleep(2)
end
步骤:
And I background the app
And I wait
And I launch the app
And I wait
And I should see "Button1"
And I wait for 10 seconds
And I touch "Button1"
Calabash 成功看到 Button1,但是当它试图触摸 Button1 时,在 9.1 模拟器中,Calabash 无限期挂起,试图找到按钮,而在 8.4 模拟器中,我立即收到错误,Calabash 找不到视图“按钮 1”。
【问题讨论】:
-
多少秒后“我应该看到“速度”被触发?
-
4 秒.. 但我也尝试了 10 秒等待,但没有帮助。
-
您介意发布您的 Gemfile 内容吗?
-
@ChristopherFuentes 我看到了 836 问题,实际上在这个线程中提到了它。这是我认为功能刚刚损坏的主要原因之一。我希望我以后的解决方法可以解决这些问题问题,但到目前为止还没有运气。
标签: ruby cucumber xcode7 calabash calabash-ios