Lapis Lazuli:Browser.wait()

From Test Automation Wiki
Jump to: navigation, search

The wait module combines Watir's ability to wait for something to happen with the functionality of the find module. In particular, it exposes corresponding wait functions for all existing find functions, e.g. wait_all, multi_wait, etc.

The syntax for calling the wait functions is the same as for find functions, but a few more options may be passed.

If wait functions do not find the elements according to their parameters and selectors, they will produce an error using the world error module.

Wait Options

  • timeout - a timeout in seconds, defaults to 10.
  • condition - one of :while or :until, defaults to wait :until.
  • screenshot - a boolean flag determining whether a screenshot should be taken on failure.

Wait Selectors

Selectors for wait functions are identical to selectors for find functions, with one crucial difference: the default is to filter only by present elements (i.e. :filter_by defaults to :present?), as that is the most common usage when waiting for something on a web page.


#Wait for the exact text "Hello World" to be present within 5 seconds
browser.wait(:timeout => 5, :text => "Hello World")

#Wait for a part of text "hello world" to be present within 5 seconds
browser.wait(:timeout => 5, :text => /Hello World/i)

#Wait for as long as the element with id "foo" is present or the timeout is met
browser.wait(:timeout => 10, :id => "foo", :condition => :while)