Module: Autospec::PageHelperModule
- Defined in:
- lib/autospec/page_helper_module.rb
Instance Method Summary collapse
- #current_session ⇒ Object
-
#wait(opts = {}) ⇒ Object
Explicitly wait for a certain condition to be true: wait.until { driver.find_element(:css, ‘body.tmpl-srp’) } when timeout is not specified, default timeout 5 sec will be used when timeout is larger than 15, max timeout 15 sec will be used.
-
#wait_for_ajax(timeout = Capybara.default_wait_time) ⇒ Object
Wait on all AJAX requests to finish.
-
#wait_for_dom ⇒ Object
Wait on all DOM events to finish Note that #find(from Capybara::Node::Finders) continuously retry finding an element and timeout for #find is controlled by Capybara.default_wait_time.
Instance Method Details
#current_session ⇒ Object
4 5 6 |
# File 'lib/autospec/page_helper_module.rb', line 4 def current_session .current_session end |
#wait(opts = {}) ⇒ Object
Explicitly wait for a certain condition to be true:
wait.until { driver.find_element(:css, 'body.tmpl-srp') }
when timeout is not specified, default timeout 5 sec will be used when timeout is larger than 15, max timeout 15 sec will be used
33 34 35 36 37 38 39 40 |
# File 'lib/autospec/page_helper_module.rb', line 33 def wait(opts = {}) if !opts[:timeout].nil? && opts[:timeout] > 15 puts "WARNING: #{opts[:timeout]} sec timeout is NOT supported by wait method, max timeout 15 sec will be used instead" opts[:timeout] = 15 end Selenium::WebDriver::Wait.new(opts) end |
#wait_for_ajax(timeout = Capybara.default_wait_time) ⇒ Object
Wait on all AJAX requests to finish
23 24 25 26 27 |
# File 'lib/autospec/page_helper_module.rb', line 23 def wait_for_ajax(timeout = .default_wait_time) wait(timeout: timeout, msg: "Timeout after waiting #{timeout} for all ajax requests to finish") do current_session.evaluate_script 'jQuery.active == 0' end end |
#wait_for_dom ⇒ Object
Wait on all DOM events to finish Note that #find(from Capybara::Node::Finders) continuously retry finding an element and timeout for #find is controlled by Capybara.default_wait_time
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/autospec/page_helper_module.rb', line 11 def wait_for_dom uuid = SecureRandom.uuid current_session.find("body") current_session.evaluate_script " _.defer(function() {\n $('body').append(\"<div id='\#{uuid}'></div>\");\n });\n EOS\n current_session.find(\"div#\#{uuid}\")\nend\n" |