Skip to content

Commit

Permalink
rb - remove unnecessary and time consuming browser resets in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Nov 29, 2015
1 parent 8fc56df commit 6aff8c7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def reset_driver!
GlobalTestEnv.reset_driver!
end

def ensure_single_window
GlobalTestEnv.ensure_single_window
end

def url_for(filename)
GlobalTestEnv.url_for filename
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def reset_driver!
@driver_instance = new_driver_instance
end

def ensure_single_window
@driver_instance.window_handles[1..-1].each do |handle|
@driver_instance.switch_to.window(handle)
@driver_instance.close
end
@driver_instance.switch_to.window @driver_instance.window_handles.first
end

def quit_driver
if @driver_instance
@driver_instance.quit
Expand Down Expand Up @@ -82,6 +90,10 @@ def remote_server
)
end

def remote_server?
!@remote_server.nil?
end

def remote_server_jar
@remote_server_jar ||= root.join("build/java/server/test/org/openqa/selenium/server-with-tests-standalone.jar").to_s
end
Expand Down
86 changes: 47 additions & 39 deletions rb/spec/integration/selenium/webdriver/target_locator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
not_compliant_on :driver => :remote, :browser => :marionette do
describe "Selenium::WebDriver::TargetLocator" do
after do
reset_driver!
ensure_single_window
end

let(:wait) { Selenium::WebDriver::Wait.new }
Expand Down Expand Up @@ -128,60 +128,68 @@

# Marionette BUG: Automatically switches browsing context to new window when it opens.
not_compliant_on :driver => :marionette do
it "should close current window when more than two windows exist" do
driver.navigate.to url_for("xhtmlTest.html")
driver.find_element(:link, "Create a new anonymous window").click
driver.find_element(:link, "Open new window").click
context "with more than two windows" do
before(:each) do
compliant_on :browser => :chrome do
reset_driver!
end
end

wait.until { driver.window_handles.size == 3 }
it "should close current window when more than two windows exist" do
driver.navigate.to url_for("xhtmlTest.html")
driver.find_element(:link, "Create a new anonymous window").click
driver.find_element(:link, "Open new window").click

driver.switch_to.window(driver.window_handle) {driver.close}
expect(driver.window_handles.size).to eq 2
end
wait.until { driver.window_handles.size == 3 }

it "should close another window when more than two windows exist" do
driver.navigate.to url_for("xhtmlTest.html")
driver.find_element(:link, "Create a new anonymous window").click
driver.find_element(:link, "Open new window").click
driver.switch_to.window(driver.window_handle) {driver.close}
expect(driver.window_handles.size).to eq 2
end

wait.until { driver.window_handles.size == 3 }
it "should close another window when more than two windows exist" do
driver.navigate.to url_for("xhtmlTest.html")
driver.find_element(:link, "Create a new anonymous window").click
wait.until { driver.window_handles.size == 2 }
driver.find_element(:link, "Open new window").click
wait.until { driver.window_handles.size == 3 }

window_to_close = driver.window_handles.last
window_to_close = driver.window_handles.last

driver.switch_to.window(window_to_close) { driver.close }
expect(driver.window_handles.size).to eq 2
end
driver.switch_to.window(window_to_close) { driver.close }
expect(driver.window_handles.size).to eq 2
end

it "should iterate over open windows when current window is not closed" do
driver.navigate.to url_for("xhtmlTest.html")
driver.find_element(:link, "Create a new anonymous window").click
driver.find_element(:link, "Open new window").click
it "should iterate over open windows when current window is not closed" do
driver.navigate.to url_for("xhtmlTest.html")
driver.find_element(:link, "Create a new anonymous window").click
driver.find_element(:link, "Open new window").click

wait.until { driver.window_handles.size == 3 }

wait.until { driver.window_handles.size == 3 }
matching_window = driver.window_handles.find do |wh|
driver.switch_to.window(wh) { driver.title == "We Arrive Here" }
end

matching_window = driver.window_handles.find do |wh|
driver.switch_to.window(wh) { driver.title == "We Arrive Here" }
driver.switch_to.window(matching_window)
expect(driver.title).to eq("We Arrive Here")
end

driver.switch_to.window(matching_window)
expect(driver.title).to eq("We Arrive Here")
end
it "should iterate over open windows when current window is closed" do
driver.navigate.to url_for("xhtmlTest.html")
driver.find_element(:link, "Create a new anonymous window").click
driver.find_element(:link, "Open new window").click

it "should iterate over open windows when current window is closed" do
driver.navigate.to url_for("xhtmlTest.html")
driver.find_element(:link, "Create a new anonymous window").click
driver.find_element(:link, "Open new window").click
wait.until { driver.window_handles.size == 3 }

wait.until { driver.window_handles.size == 3 }
driver.close

driver.close
matching_window = driver.window_handles.find do |wh|
driver.switch_to.window(wh) { driver.title == "We Arrive Here" }
end

matching_window = driver.window_handles.find do |wh|
driver.switch_to.window(wh) { driver.title == "We Arrive Here" }
driver.switch_to.window(matching_window)
expect(driver.title).to eq("We Arrive Here")
end

driver.switch_to.window(matching_window)
expect(driver.title).to eq("We Arrive Here")
end
end

Expand Down

0 comments on commit 6aff8c7

Please sign in to comment.