3

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

However, getting a page from my server takes a while, and I get 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.

Here's my code:

@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

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

5
  • Wait, the timeout error is in the main browser window, not coming from the watir script? that means the browser thinks it took too long, which is not a factor of the Watir code. That must be one wimpy server or one insane rails app, that or it's trying to get to something that it needs for the page that is not not available (some third party item from an external site?) Dec 8, 2011 at 1:01
  • 1
    What I am trying to get is a page from my own application, running in my local machine. Don't know why it's taking so long Dec 11, 2011 at 23:13
  • how does it react when you run the browser manually? If everything is on one system you might want to do a little work with perfmon or a similar tool to see if something is using up all the cpu resources or memory or something? Dec 12, 2011 at 7:30
  • I am trying to make it a background process and see. Thanks. Dec 13, 2011 at 4:36
  • same problem here, can't run manualy Watir?
    – Matrix
    Aug 4, 2018 at 23:08

2 Answers 2

4

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 }

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

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

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

I moved this process to run in the background using delayed_job gem, and it works fine!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.