超时::使用 Watir 的 Rails 应用程序中的错误 [英] Timeout::Error in Rails application using Watir

查看:41
本文介绍了超时::使用 Watir 的 Rails 应用程序中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Watir 浏览页面并截取应用程序中某些页面的屏幕截图.

I am using Watir to browse pages and take screenshots of some pages in my application.

但是,从我的服务器获取页面需要一段时间,并且出现 Timeout::Error.

However, getting a page from my server takes a while, and I get Timeout::Error.

为了解决这个问题,我在我的 Watir 浏览器实例中使用了一个等待,检查是否存在一个 id 为内容"的 div,并让它等待直到它存在.但是,这需要一些时间,并且页面会在 Watir 浏览器中加载.但加载后,我在主浏览器窗口中收到 Timeout::Error.

To fix this, I used a wait in my Watir browser instance, to check to see if a div with id 'content' exists, and to make it wait until it exists. However, it takes some time, and the page is loaded in the Watir browser. But after it is loaded, I get the Timeout::Error in my main browser window.

这是我的代码:

@pages = Pages.all
browser = Watir::Browser.new
@pages.each do |page|
  page_url = app_root_url + 'pages/' + page.id.to_s
  browser.goto page_url
  Watir::Waiter::wait_until { browser.div(:id, 'content').exists? }
  file_save_path = pages_screenshot_path.to_s + page.id.to_s + '.png'
  browser.driver.save_screenshot(file_save_path)
end
browser.close

每个页面都包含一个 ID 为content"的 div.不过,我猜还没有等到.

Each page contains a div with id 'content'. Still, it's not waiting I guess.

推荐答案

Watir::Waiter.wait_until 的默认等待时间为 60 秒(每半秒检查一次,直到 60).您可以指定更高的值,如下所示:

The default wait time for Watir::Waiter.wait_until is 60 seconds (checking every half second until 60). You can specify a higher value like so:

Watir::Waiter.wait_until(120) { code code code }

您可以在此处找到更多详细信息:http://wiki.openqa.org/display/WTR/How+to+wait+with+Watir

You can find more specifics here: http://wiki.openqa.org/display/WTR/How+to+wait+with+Watir

对于 watir-webdriver,你可以使用 Watir::Wait.methods:

For watir-webdriver, you can use Watir::Wait.methods:

Watir::Wait.until(120) { code code code }

这篇关于超时::使用 Watir 的 Rails 应用程序中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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