Module: DmcKanye::DriverHelpers
- Included in:
- Capybara::Poltergeist::Driver
- Defined in:
- lib/dmc_kanye/driver_helpers.rb
Instance Method Summary collapse
- #open_ajax_requests? ⇒ Boolean
- #page_loaded? ⇒ Boolean
- #wait_for_in_progress_ajax_to_finish ⇒ Object
- #wait_for_page_to_finish_loading ⇒ Object
- #wait_for_page_to_settle ⇒ Object
-
#wait_to_appear(method, selector) ⇒ Object
If the browser is waiting for ajax or loading a page, Kanye is smart enough to deal with this.
Instance Method Details
#open_ajax_requests? ⇒ Boolean
32 33 34 35 36 |
# File 'lib/dmc_kanye/driver_helpers.rb', line 32 def open_ajax_requests? !evaluate_script("(typeof jQuery === 'undefined') ? 0 : jQuery.active").zero? rescue Capybara::NotSupportedByDriverError false end |
#page_loaded? ⇒ Boolean
38 39 40 41 42 |
# File 'lib/dmc_kanye/driver_helpers.rb', line 38 def page_loaded? evaluate_script("document.readyState") == "complete" rescue Capybara::NotSupportedByDriverError true end |
#wait_for_in_progress_ajax_to_finish ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/dmc_kanye/driver_helpers.rb', line 53 def wait_for_in_progress_ajax_to_finish seconds = 0 while open_ajax_requests? seconds += 0.05 raise TimeoutException if seconds > timeout sleep 0.05 end end |
#wait_for_page_to_finish_loading ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/dmc_kanye/driver_helpers.rb', line 44 def wait_for_page_to_finish_loading seconds = 0 while !page_loaded? seconds += 0.02 raise TimeoutException if seconds > timeout sleep 0.02 end end |
#wait_for_page_to_settle ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/dmc_kanye/driver_helpers.rb', line 62 def wait_for_page_to_settle if !page_loaded? wait_for_page_to_finish_loading wait_for_page_to_settle end if open_ajax_requests? wait_for_in_progress_ajax_to_finish wait_for_page_to_settle end end |
#wait_to_appear(method, selector) ⇒ Object
If the browser is waiting for ajax or loading a page, Kanye is smart enough to deal with this. However, if the browser is busy doing something else for a significant period of time (such as long-running JavaScript), Kanye is not smart enough to know that there is something that needs finishing.
So basically, in the very rare cases that Kanye cannot detect that something needs to be waited for, you can explicitly wait for a DOM element to appear, for example:
wait_to_appear(:css, '.ui-autocomplete.ui-menu')
This will wait up to the poltergeist timeout value (which is probably 30 seconds) for this DOM element to appear before moving on. If the DOM element does not appear, an error is thrown.
23 24 25 26 27 28 29 30 |
# File 'lib/dmc_kanye/driver_helpers.rb', line 23 def wait_to_appear(method, selector) seconds = 0 while find(method, selector).nil? seconds += 0.2 raise TimeoutException if seconds > timeout sleep 0.2 end end |