0

我尽量避免使用 sleep() 命令,所以我想用更智能的函数替换它,比如 wait_for_element_exists() 但它们似乎在 iOS 下不起作用。例子:

touch("button marked:'button_in_the_first_view'")
wait_for_element_exists("button marked:'button_in_the_second_view'")
touch("button marked:'button_in_the_third_view'")

Calabash 不等待屏幕上显示第二个按钮,立即转到第 3 行,测试失败

如果我尝试确定第二个按钮的属性,它立即可用,仍然启用且未隐藏,尽管导航视图控制器尚未完成第一个视图的推送动画:

touch("button marked:'button_in_the_first_view'")
query("button marked:'button_in_the_second_view'").count # => 1
query("button marked:'button_in_the_second_view'", :isEnabled).first # => 1
query("button marked:'button_in_the_second_view'", :isHidden).first # => 0

在此先感谢您的帮助,

米哈乌

4

1 回答 1

1

wait_for_elements_exist() 有效。您需要找出错误触发的位置。正如 Lasse 所说,有时您需要使用最少的 sleep(0.3) 来匹配动画速度。wait_for_elements_exist 方法有一些选项,例如

    wait_for_elements_exist(elements_arr, 
    {
     :timeout => 10, #maximum number of seconds to wait
     :retry_frequency => 0.2, #wait this long before retrying the block
     :post_timeout => 0.1, #wait this long after the block returns true
     :timeout_message => "Timed out waiting...", #error message in case options[:timeout] is exceeded
     :screenshot_on_error => true # take a screenshot in case of error
    }
)

尝试使用这些选项、element_exists() 函数和一些 UI 查询来找出屏幕上实际发生的情况?两个按钮的状态是什么,下一秒会发生什么?

此外,您可以在像这样触摸它之前检查按钮状态。

Then /^I should see "([^\"]*)" button isEnabled$/ do |text|
    state = query("button marked:'#{text}'", :isEnabled)[0]
    state = state.to_i
    if state!=1
      screenshot_and_raise "Current state is not enabled for button: #{text}"
    end
    sleep(STEP_PAUSE)
end



Then /^I touch the "([^\"]*)" button after it appears$/ do |name|
      element = "button marked:'#{name}'"
      if element_does_not_exist(element)
        wait_for_elements_exist( [element], :timeout => 10)
        sleep(STEP_PAUSE)
        touch(element)
        sleep(0.3)
      elsif element_exists(element)
        touch(element)
        sleep(0.3)
      else
        screenshot_and_raise "'#{name}' Button isnt exsist."
      end
    end

在这里,我在 calabash 上添加了一些提前等待功能。检查您是否可以在那里找到解决方案。

于 2015-03-18T05:10:25.227 回答