Created
July 9, 2017 09:04
-
-
Save prashanth-sams/e35b9cb65907d2bc7faa0eed926ec50e to your computer and use it in GitHub Desktop.
generic selenium methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def wait_for_ajax(timeout = 60, message = nil) | |
| wait_for_jquery(timeout / 2, message) | |
| super(timeout / 2, message) | |
| end | |
| def wait_for_jquery(timeout = 30, message = nil) | |
| end_time = ::Time.now + timeout | |
| until ::Time.now > end_time | |
| begin | |
| return if @browser.execute_script('return jQuery ? 1 : 0;') == 1 | |
| puts 'jQuery not yet loaded, waiting half a second...' | |
| rescue Selenium::WebDriver::Error::UnknownError => jquery_error | |
| puts "jQuery not yet loaded, or failed when checking if it loaded: #{jquery_error}\nWaiting half a second..." | |
| end | |
| sleep 0.5 | |
| end | |
| message = 'Timed out waiting for jquery to load' unless message | |
| raise message | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment