Created
October 10, 2011 15:36
-
-
Save jimevans/1275630 to your computer and use it in GitHub Desktop.
This file contains 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
require 'rubygems' | |
require 'selenium-webdriver' | |
def wait_for_new_handle(original_handles, driver) | |
handles = nil | |
wait = Selenium::WebDriver::Wait.new(:timeout => 10) | |
wait.until do | |
handles = driver.window_handles | |
handles.size == original_handles.size + 1 | |
end | |
handles | |
end | |
def wait_for_window_close(original_handles, driver) | |
handles = nil | |
wait = Selenium::WebDriver::Wait.new(:timeout => 10) | |
wait.until do | |
handles = driver.window_handles | |
handles.size == original_handles.size - 1 | |
end | |
handles | |
end | |
def open_modal(driver) | |
original_handles = driver.window_handles | |
driver.find_element(:id => 'launch_modal_button').click | |
handles = wait_for_new_handle(original_handles, driver) | |
modal = (handles - original_handles).first | |
driver.switch_to.window modal | |
end | |
#gets | |
driver = Selenium::WebDriver.for :ie | |
driver.get "http://localhost:2310/common/modal.html" | |
original_handle = driver.window_handle | |
open_modal driver | |
original_handles = driver.window_handles | |
driver.find_element(:id => 'close_window').click | |
wait_for_window_close original_handles, driver | |
driver.switch_to.window original_handle | |
driver.quit | |
driver = Selenium::WebDriver.for :ie | |
driver.get "http://localhost:2310/common/modal.html" | |
original_handle = driver.window_handle | |
open_modal driver | |
modal_handle = driver.window_handle | |
open_modal driver | |
driver.find_element(:id => 'close_window2').click | |
driver.switch_to.window modal_handle | |
driver.find_element(:id => 'close_window').click | |
driver.switch_to.window original_handle | |
driver.quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment