CapyTime
CapyTime is a tool that allows you to use Capybara without having to worry about the timing issues.
Installation
Add this line to your application's Gemfile:
gem 'capy_time'
And then execute:
$ bundle
Or install it yourself as:
$ gem install capy_time
Usage
Add the lines: require 'capy_time' and World(CapyTime) to your env file. ENV variable: add ENV['STIME']='60' to your env file. <--sets default timeout amount as a string '60' will be converted by capy_time using to_i
Method : load_element(statement,*options)
Description : This takes the css for an element and then makes sure the element is loaded or fails after timeout is reached if method doesn't load
Options :
:text this allows you to select an element based on it's text
example: load_element('a', :text =>/welcome/)
:time this allows you to set an explicit timeout for just this call
example: load_element('a', :text =>/welcome/,:time =>60)
Method : load_true(statement,*options)
Description : This takes a statement that evaluates to a boolean and waits for it to evaluate to true or fails after timeout is reached if still false
Options:
:time this allows you to set an explicit timeout for just this call
example: load_true(all('div.result').length==0, :time =>60)
:refresh this allows you to tell the page to refresh before it attempts to evaluate the statement
example: load_true(all('div.result').length==0, :refresh =>true)
Method: should_have_content(statement,*options)
Description : This takes a string that is expected to be in the page (or a given parent) and waits for it to load or fails after timeout is reached and the content wasn't loaded within the parent
Options:
:time this allows you to set an explicit timeout for just this call
example: should_have_content('welcome', :time => 60)
:refresh this allows you to tell the page to refresh before it attempts to evaluate the statement
example: should_have_content('welcome', :refresh => true)
:parent this allows you to make sure that the content is inside a given element
example: should_have_content('welcome', :parent =>"div#welcomeMsg")
Method: should_have_css(statement,*options)
Description : This takes the css for an element and then makes sure the element is loaded within the parent element or fails after timeout is reached and the css wasn't loaded within the parent
Options:
:time this allows you to set an explicit timeout for just this call
example: should_have_css('p', :time => 60)
:refresh this allows you to tell the page to refresh before it attempts to evaluate the statement
example: should_have_css('p', :refresh => true)
:parent this allows you to make sure that the content is inside a given element NOTE:if not used it will default to page
example: should_have_css('p', :parent =>"div#welcomeMsg")
Method: should_open_tab(url,prevTabTotal,*options)
Description: This takes a partial or full url and waits for the browser to open the url in a new tab or fails if the timeout is reached and the url wasn't opened in a new tab
Options:
:time this allows you to set an explicit timeout for just this call
example: should_open_tab('rubygems.org',4,:time =>60)
:close this allows you to specify that after opening the tab it should close the tab and go back to the first tab
example: should_open_tab('rubygems.org',3,:close =>true)
Method: wait_for_page_change(prevUrl)
Description: This takes the url of a page before an action occurred and then makes sure that the url changes before continuing or fails if timeout is reached and url never changed
License
The gem is available as open source under the terms of the MIT License.