Module: Gamera::Visitable
Constant Summary collapse
- CAPYBARA_DEFAULT_MAX_WAIT_TIME =
Define CAPYBARA_DEFAULT_MAX_WAIT_TIME differently, depending on the version of Capybara.
if Gem::Version.new(Capybara::VERSION) >= Gem::Version.new('2.5.0') Capybara.default_max_wait_time else Capybara.default_wait_time end
Instance Method Summary collapse
-
#displayed?(wait_time_seconds = CAPYBARA_DEFAULT_MAX_WAIT_TIME) ⇒ Boolean
Check to see if we eventually land on the right page.
-
#url ⇒ Object
A reminder to implement a url method when using this module.
-
#visit(fail_on_redirect: true) ⇒ Object
Open the page url in the browser specified in your Capybara configuration.
-
#with_refreshes(retries, allowed_errors = [RSpec::Expectations::ExpectationNotMetError]) ⇒ Object
A method to wait for slow loading data on a page.
Instance Method Details
#displayed?(wait_time_seconds = CAPYBARA_DEFAULT_MAX_WAIT_TIME) ⇒ Boolean
Check to see if we eventually land on the right page
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gamera/modules/visitable.rb', line 30 def displayed?(wait_time_seconds = CAPYBARA_DEFAULT_MAX_WAIT_TIME) raise Gamera::NoUrlMatcherForPage if url_matcher.nil? start_time = Time.now loop do return true if page.current_url.chomp('/') =~ url_matcher break unless Time.now - start_time <= wait_time_seconds sleep(0.05) end false end |
#url ⇒ Object
A reminder to implement a url method when using this module.
59 60 61 |
# File 'lib/gamera/modules/visitable.rb', line 59 def url raise NotImplementedError, 'To use the Visitable module, you must implement a url method' end |
#visit(fail_on_redirect: true) ⇒ Object
Open the page url in the browser specified in your Capybara configuration
18 19 20 21 22 23 |
# File 'lib/gamera/modules/visitable.rb', line 18 def visit(fail_on_redirect: true) super(url) if fail_on_redirect raise Gamera::WrongPageVisited, "Expected URL '#{url}', got '#{page.current_url}'" unless displayed? end end |
#with_refreshes(retries, allowed_errors = [RSpec::Expectations::ExpectationNotMetError]) ⇒ Object
A method to wait for slow loading data on a page. Useful, for example, when waiting on a page that shows the count of records loaded via a slow web or import.
48 49 50 51 52 53 54 55 56 |
# File 'lib/gamera/modules/visitable.rb', line 48 def with_refreshes(retries, allowed_errors = [RSpec::Expectations::ExpectationNotMetError]) retries_left ||= retries visit yield(retries_left) rescue *allowed_errors => e retries_left -= 1 retry if retries_left >= 0 raise e end |