我尽量避免使用 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 行并未通过测试
如果我尝试确定第二个按钮的属性,尽管导航 View Controller 尚未完成来自第一个 View 的推送动画,但它立即可用,仍然启用且未隐藏:
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
预先感谢您的帮助,
迈克尔
最佳答案
wait_for_elements_exist() 有效。您需要找出它错误触发的位置。正如 Lasse 所说,有时您需要使用 least 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
这里我加了一些advance wait functions on calabash 。检查您是否可以在那里找到解决方案。
关于ios - Calabash iOS - wait_for_element_exists 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29100191/