我试图避免使用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
先谢谢你的帮助,
米哈尔
答案 0 :(得分:1)
wait_for_elements_exist()有效。您需要找出错误触发的位置。正如Lasse所说,有时你需要使用最少睡眠(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
我在这里添加了一些advance wait functions on calabash。检查一下你是否能找到解决方案。