Watirimplicit_wait 似乎不起作用 [英] Watir implicit_wait doesn't seem to work

查看:23
本文介绍了Watirimplicit_wait 似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在使用 watir-webdriver (0.6.2) 和 firefox 来运行验收测试.我们的测试需要很长时间才能运行,并且经常因超时错误而失败.我们想减少超时时间,让他们更快地失败.

We are currently using watir-webdriver (0.6.2) with firefox to run acceptance tests. Our tests take a long time to run, and often fail with timeout errors. We wanted to decrease the timeout time, for them to fail faster.

我们尝试过:

browser = Watir::Browser.new("firefox")
browser.driver.manage.timeouts.implicit_wait=3 

但是,我们仍然遇到 30 秒超时.

However, we are still experiencing 30s timeouts.

我们找不到有关此问题的任何文档或问题.有谁知道如何正确配置 Watir 等待超时?

We couldn't find any documentation or question regarding this issue. Does anyone know how to configure Watir waiting timeouts properly?

推荐答案

这完全取决于您所说的超时"是什么意思.AFAIK 在谈论 Watir-Webdriver 时,通常会讨论三种不同的超时定义:

It depends exactly what you mean by 'timeout'. AFAIK there are three different definitions of timeout commonly discussed when talking about Watir-Webdriver:

  1. 浏览器等待页面加载多长时间?
  2. Watir-Webdriver 明确在考虑元素不存在"或不可见"之前等待多长时间,当通过.when_present"函数被告知要等待时
  3. Watir-Webdriver 隐式在考虑元素不存在"或不可见"之前等待对象出现多长时间(当不通过显式调用等待时,请参阅#2)
  1. How long does the browser wait for a page to load?
  2. How long does Watir-Webdriver explicitly wait before considering an element 'not present' or 'not visible' when told to wait via the '.when_present' function
  3. How long does Watir-Webdriver implicitly wait for an object to appear before considering an element 'not present' or 'not visible' (when not waiting via explicitly call see #2)

#1:页面加载

Justin Ko 是对的,如果您的目标是修改页面加载超时,您可以按照描述设置页面加载超时,尽管看起来规范的方法是在创建浏览器并将其传递给浏览器之前设置客户端超时关于创作:

#1: Page load

Justin Ko is right that you can set page load timeout as described if your goal is to modify that, though it looks like the canonical way to do that is to set the client timeout before creating the browser and passing it to the browser on creation:

client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 180 # seconds – default is 60

b = Watir::Browser.new :firefox, :http_client => client

- Alistair Scott,如何更改 Watir-Webdriver 中的页面加载超时"

但我认为@p0deje 说您正在经历显式超时是正确的,尽管在没有看到您的代码的情况下无法确定.在下面,我经历了显式声明覆盖了隐式声明(我不确定这是否是故意的):

But I think @p0deje is right in saying you are experiencing explicit timeouts, though it's not possible to say for sure without seeing your code. In the below I experienced the explicit declaration overriding the implicit (I am unsure if that's intentional):

b = Watir::Browser.new :firefox
b.driver.manage.timeouts.implicit_wait = 3 
puts Time.now #=> 2013-11-14 16:24:12 +0000
begin
  browser.link(:id => 'someIdThatIsNotThere').when_present.click
rescue => e
  puts e #=> timed out after 30 seconds, waiting for {:id=>"someIdThatIsNotThere", :tag_name=>"a"} to become present
end
puts Time.now #=> 2013-11-14 16:24:43 +0000

由于 'when_present',Watir-Webdriver 默认会在失败前等待 30 秒.或者,您可以说when_present(10)"来更改默认值并等待 10 秒.(Watir-Webdriver > Watir::Wait#when_present.)我想不出有什么方法可以在全球范围内做到这一点.除非你发现这样的事情——如果你发现了请告诉我——它必须在每次调用时完成.:( 编辑:回答者 Justin Ko 给了我关于如何做我上面描述的事情的答案.编辑 2:@jarib 将此添加到 Watir,根据链接答案中的 @justinko:更新:此猴子补丁已合并到 watir-webdriver 中,因此在 watir-webdriver v0.6.5 中不再需要.您将能够使用以下方法设置超时:Watir.default_timeout = 90"

Watir-Webdriver will wait 30 seconds before failure by default thanks to 'when_present'. Alternatively you can say 'when_present(10)' to alter the default and wait 10 seconds. (Watir-Webdriver > Watir::Wait#when_present.) I can not divine any way to do this globally. Unless you find such a thing - and please tell me if you do - it must be done on each call. :( Edit: Fellow answerer Justin Ko gave me the answer as to how to do what I described above. Edit 2: @jarib added this to Watir, per @justinko in the linked answer: "Update: This monkey patch has been merged into watir-webdriver and so will no longer be needed in watir-webdriver v0.6.5. You will be able to set the timeout using: Watir.default_timeout = 90"

您提供的代码设置了 Watir-Webdriver 等待任何元素出现的时间,而无需您明确说明:

The code you provided sets the time Watir-Webdriver will wait for any element to be come present without you explicitly saying so:

b = Watir::Browser.new :firefox
b.driver.manage.timeouts.implicit_wait = 3 
puts Time.now #=> 2013-11-14 16:28:33 +0000
begin
  browser.link(:id => 'someIdThatIsNotThere').when_present.click
rescue => e
  puts e #=> unable to locate element, using {:id=>"someIdThatIsNotThere", :tag_name=>"a"}
end
puts Time.now #=> 2013-11-14 16:28:39 +0000

这篇关于Watirimplicit_wait 似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆