简体   繁体   English

使用“存在”的watir-webdriver方法时发生超时错误

[英]Timeout error when using “exists” watir-webdriver method

As far as searching goes, i was unable to find an up-to-date list of supported browsers for watir. 就搜索而言,我无法找到支持watir的最新浏览器列表。

I've just upgraded firefox to version 18, and while at it, also update the watir-webdriver version to it's latest (by using gem update watir-webdriver ). 我刚刚将firefox升级到了版本18,与此同时,也将watir-webdriver版本更新到了最新版本(通过使用gem update watir-webdriver )。

So far i've encountered one issue, that i cant seem to find a solution for. 到目前为止,我遇到了一个问题,似乎无法找到解决方案。

When i try to check if an element exist, lets say by using $browser.a(:href, "#{$url}/admin/").exists? 当我尝试检查元素是否存在时,可以说使用$browser.a(:href, "#{$url}/admin/").exists? (The $url variable is defined to the main url of my testing server, so it's not the problem. Furthermore, even when i replace the variable with the actual address, i still encounter the same issue), I always get a timeout error when the element does not exists. $url变量已定义为测试服务器的主url,所以这不是问题。此外,即使将变量替换为实际地址,我仍然遇到相同的问题),当元素存在。

When the element does exists, i will get an instant response of true . 当元素确实存在时,我将立即得到true响应。 So the timeout issue only happens when the element does not exists. 所以,当元素没有超时问题只发生存在。

So my questions are: 所以我的问题是:

  1. Is there a way to make the .exists? 有没有办法使.exists? method work? 方法工作?
  2. Does anyone know any other issues like that with the latest version of Firefox(V. 18)? 有人知道最新版本的Firefox(V. 18)有其他问题吗?
  3. I would really appreciate if someone can point me to an updated list of watir supported browsers. 如果有人能指出我最新的watir支持的浏览器列表,我将不胜感激。 Preferably a list that is being updated on a regular basis. 优选地,列表是定期更新的。

PS, I did see that someone posted a question about the present? PS,我确实看到有人发布了关于present?的问题present? method, i have no idea of it's related, but nonetheless, i still have no solution. 方法,我不知道它的关系,但尽管如此,我仍然没有解决方案。 I'd hate to downgrade to a previous version of ff. 我不想降级到ff的早期版本。

Thanks a bunch to anyone who will be willing to help, 多谢所有愿意提供帮助的人,

Kind regards, Asaf. 亲切的问候,阿萨夫。

I had such problems here and there and the solution was to catch the exception and re-run the piece of code that triggered this exception. 我到处都有这样的问题,解决方案是捕获异常并重新运行触发该异常的代码。 Of course, I'm assuming your exception is triggered by some transient cause, possibly by a glitch in Watir. 当然,我假设您的异常是由某些暂时原因触发的,可能是由于Watir的故障引起的。

Briefly, you could do something like this: 简要地说,您可以执行以下操作:

begin
  $browser.a(:href, "#{$url}/admin/").exists?
rescue Timeout::Error
  puts("Caught a TIMEOUT ERROR!")
  sleep(1)
  # Retry the sode that generates the esception.
  retry
end

That's the simplest form. 那是最简单的形式。 You could also make sure not to lock up yourself in an infinite loop by doing something like: 您还可以通过执行以下操作来确保不将自己锁定在无限循环中:

retries_left = 3
begin
  $browser.a(:href, "#{$url}/admin/").exists?
rescue Timeout::Error
  puts("Caught a TIMEOUT ERROR!")

  # You may want to wait for a while before retrying.
  sleep(1)

  # Retry the code that generates the exception.
  retries_left -= 1
  retry if retries_left > 0

  # No more retries left - time to bail out! Re-raise the exception.
  raise
end

You could improve this a bit by abstracting this exception handling code into a test helper method that accepts blocks and use it in a much more cleaner way, without repeating yourself, like: 您可以通过将异常处理代码抽象到一个测试帮助器方法中来改善这一点,该方法可以接受块并以更简洁的方式使用它,而无需重复自己,例如:

handle_transient_exceptions {
  $browser.a(:href, "#{$url}/admin/").exists?
}

But that's not what you asked about. 但这不是您要的。 :) :)

Referring to your third question, I can say that watir-webdriver supports the latest Chrome, Firefox and IE9 pretty well. 关于您的第三个问题,我可以说watir-webdriver非常支持最新的Chrome,Firefox和IE9。 I'm working with these browsers currently and haven't spotted any blocking issues yet. 我目前正在使用这些浏览器,还没有发现任何阻塞问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM