【问题标题】:Calabash not touching buttons properly after background葫芦在背景后没有正确触摸按钮
【发布时间】: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 秒等待,但没有帮助。
  • 也许看看这个帖子:github.com/calabash/calabash-ios/issues/836
  • 您介意发布您的 Gemfile 内容吗?
  • @ChristopherFuentes 我看到了 836 问题,实际上在这个线程中提到了它。这是我认为功能刚刚损坏的主要原因之一。我希望我以后的解决方法可以解决这些问题问题,但到目前为止还没有运气。

标签: ruby cucumber xcode7 calabash calabash-ios


【解决方案1】:

问题 #836 已于 11 月修复。 2013 年的 Google 论坛帖子和问题 #556 是 2014 年的。任何晚于几个月前的事情都应该受到怀疑。

不要调用uia_send_app_to_background,该 API 已损坏(由 Apple)。通常坚持使用非 UIA API(除非绝对必要,否则不要调用 uia_* 方法)。

将 Calabash 更新到最新发布的版本(截至今天为 0.18.1)并再次尝试您的测试。

$ be calabash-ios console
> start_test_server_in_background

# Can touch before background
> touch("view marked:'my view'")

> send_app_to_background(1)

# Can touch after resuming from background
> touch("view marked:'my view'")

以下解决方案将不起作用。如果您打开另一个应用程序,您的应用程序将进入后台。但是,如果您使用 simctl 打开应用程序,仪器将不再与应用程序建立连接,并且手势将失败。

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

【讨论】:

  • 啊,好吧..这就是我所期待的。从本质上讲,后台功能并没有完全发挥作用,因为您必须在将应用程序置于后台后重新安装应用程序,因为在大多数情况下,您希望在应用程序后台运行后执行手势,而不仅仅是验证元素是否存在。谢谢你的帮助,jmoody!
  • 没有。这是不正确的。后台已实现。
  • 哦,好吧,后台已实现.. 但是如果您调用 relaunch 或 start_test_server_in_background (我需要这样做,因为我需要手势才能工作),这与重新安装和打开应用程序?因此,当您将应用程序置于后台和前台运行时,其行为与真实设备不同
  • 我们沟通不畅。您能否尝试在此 repo 中重现:github.com/calabash/ios-smoke-test-app/tree/master/CalSmokeApp 背景应该可以工作,从后台返回后手势应该可以工作。我不明白你的设置。
  • 我刚刚进行了测试,看看我们是否可以在从后台恢复后执行手势。我们可以。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-31
  • 2019-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多