Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jimmyeisenhauer
Created September 16, 2014 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmyeisenhauer/a61f52ef2836c8309e2c to your computer and use it in GitHub Desktop.
Save jimmyeisenhauer/a61f52ef2836c8309e2c to your computer and use it in GitHub Desktop.
def create_button
@driver.find_element(:link, 'Create')
end
def create_button_click
@wait = Selenium::WebDriver::Wait.new(timeout: 8)
puts 'DEBUG: Clicking Create Button'
create_button.click
puts 'DEBUG: Waiting for View This Challenge'
@wait.until { @driver.find_element(:link, 'view this challenge') }
puts 'DEBUG: Found view challenge link'
rescue
puts 'DEBUG: Rescue: Clicking Create Button'
create_button.click
@wait.until { @driver.find_element(:link, 'view this challenge') }
puts 'DEBUG: Found view challenge link'
end
@tourdedave
Copy link

The problem (as I understand it):

The wait doesn't observe 8 seconds. Instead, it waits for 60 seconds.

Here are my thoughts/questions on this:

  1. Is the @wait shown here the only one in your test code? (e.g., is the wait getting overwritten by a same named instance variable somewhere else in your test code?)
  2. What is the error message you are seeing? If it's 60 seconds, then it's likely the Net::HTTP timeout, which means that the exception from the explicit wait isn't being observed
  3. What is the purpose of the rescue statement? You're just repeating the same actions over again, which shouldn't be necessary with an explicit wait. This has the highest probability of causing the behavior you're seeing. You're rescuing without specifying an exception, so anything will get rescued, including a timeout exception from an explicit wait. I would remove this and test to see what happens.

@jimmyeisenhauer
Copy link
Author

Yeah there is something weird going on with my waits. I had the same problem with wait not set as a instance var as well. I moved to a instance var to aid in some trouble shooting.

The implicit wait i moved to 30 seconds and I still see the explicit one at 60 seconds, which is prob http like you stated.
@driver.manage.timeouts.implicit_wait = 30

I added
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120 # seconds

as a work around it just takes a while :-)

The rescue is there to attempt the click again if the first one fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment