1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Fix bug with scopes when within_window is invoked inside within

Also fix intermittent spec failures
This commit is contained in:
Andrey Botalov 2014-05-28 22:34:31 +03:00
parent 5096e90d6a
commit 573668cad2
8 changed files with 43 additions and 14 deletions

View file

@ -25,11 +25,12 @@ before_install:
- sudo apt-get update
- sudo apt-get install google-chrome-stable --force-yes
- sudo chmod 1777 /dev/shm
- sudo apt-get install awesome -y; mkdir -p ~/.config/awesome
- echo "require('awful'); tags = {}; tags[1] = awful.tag({'name'})" > ~/.config/awesome/rc.lua
- sudo apt-get install awesome -y
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 1
- mkdir -p ~/.config/awesome
- echo "require('awful'); tags = {}; tags[1] = awful.tag({'name'})" > ~/.config/awesome/rc.lua
- "awesome &"
script: "bundle exec rake travis"

View file

@ -147,6 +147,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
within_given_window(handle) do
browser.manage.window.maximize
end
sleep 0.1 # work around for https://code.google.com/p/selenium/issues/detail?id=7405
end
def close_window(handle)
@ -165,7 +166,6 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
def switch_to_window(handle)
browser.switch_to.window handle
sleep 0.05 # https://code.google.com/p/chromedriver/issues/detail?id=769
end
# @api private

View file

@ -437,12 +437,12 @@ module Capybara
def within_window(window_or_handle)
if window_or_handle.instance_of?(Capybara::Window)
original = current_window
begin
switch_to_window(window_or_handle) unless original == window_or_handle
scopes << nil
begin
yield
ensure
@scopes = [nil]
@scopes.pop
switch_to_window(original) unless original == window_or_handle
end
elsif window_or_handle.is_a?(Proc)
@ -452,7 +452,7 @@ module Capybara
begin
yield
ensure
@scopes = [nil]
@scopes.pop
switch_to_window(original)
end
else
@ -464,7 +464,7 @@ module Capybara
scopes << nil
driver.within_window(window_or_handle) { yield }
ensure
@scopes = [nil]
@scopes.pop
end
end
end

View file

@ -6,10 +6,10 @@ Capybara::SpecHelper.spec '#become_closed', requires: [:windows, :js] do
@session.find(:css, '#openWindow').click
end
end
after(:each) do
(@session.windows - [@window]).each do |w|
@session.switch_to_window w
w.close
@session.document.synchronize(3, errors: [Capybara::CapybaraError]) do
raise Capybara::CapybaraError if @session.windows.size != 1
end
@session.switch_to_window(@window)
end
@ -48,7 +48,7 @@ Capybara::SpecHelper.spec '#become_closed', requires: [:windows, :js] do
it 'should raise error if value of default_wait_time is less than timeout' do
@session.within_window @other_window do
@session.execute_script('setTimeout(function(){ window.close(); }, 800);')
@session.execute_script('setTimeout(function(){ window.close(); }, 900);')
end
Capybara.using_wait_time 0.4 do
expect do

View file

@ -23,6 +23,9 @@ Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
end
end.to raise_error(Capybara::WindowError, zero_windows_message)
end
@session.document.synchronize(2, errors: [Capybara::CapybaraError]) do
raise Capybara::CapybaraError if @session.windows.size != 2
end
end
it 'should find window if value of :wait is more than timeout' do
@ -44,6 +47,9 @@ Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
end
end.to raise_error(Capybara::WindowError, zero_windows_message)
end
@session.document.synchronize(2, errors: [Capybara::CapybaraError]) do
raise Capybara::CapybaraError if @session.windows.size != 2
end
end
it 'should find window if default_wait_time is more than timeout' do
@ -62,6 +68,9 @@ Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
@session.find(:css, '#openTwoWindows').click
end
end.to raise_error(Capybara::WindowError, two_windows_message)
@session.document.synchronize(2, errors: [Capybara::CapybaraError]) do
raise Capybara::CapybaraError if @session.windows.size != 3
end
end
it 'should raise error when no windows were opened by block' do

View file

@ -126,7 +126,6 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
window.resize_to(screen_width-100, screen_height-100)
expect(@session.evaluate_script("[window.outerWidth, window.outerHeight];")).to eq([screen_width-100, screen_height-100])
window.maximize
sleep 0.1
expect(@session.evaluate_script("[window.outerWidth, window.outerHeight];")).to eq([screen_width, screen_height])
end

View file

@ -3,6 +3,10 @@ Capybara::SpecHelper.spec '#windows', requires: [:windows] do
@window = @session.current_window
@session.visit('/with_windows')
@session.find(:css, '#openTwoWindows').click
@session.document.synchronize(3, errors: [Capybara::CapybaraError]) do
raise Capybara::CapybaraError if @session.windows.size != 3
end
end
after(:each) do
(@session.windows - [@window]).each do |w|

View file

@ -3,6 +3,10 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
@window = @session.current_window
@session.visit('/with_windows')
@session.find(:css, '#openTwoWindows').click
@session.document.synchronize(3, errors: [Capybara::CapybaraError]) do
raise Capybara::CapybaraError if @session.windows.size != 3
end
end
after(:each) do
(@session.windows - [@window]).each do |w|
@ -52,6 +56,18 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
expect(@session.send(:scopes)).to eq([nil])
end
it "should leave correct scopes after execution in case of error" do
window = (@session.windows - [@window]).first
expect do
@session.within 'html' do
@session.within_window(window) {}
end
end.to raise_error(Capybara::ScopeError)
expect(@session.current_window).to eq(@window)
expect(@session).to have_css('#doesNotOpenWindows')
expect(@session.send(:scopes)).to eq([nil])
end
it 'should raise error if closed window was passed' do
other_window = (@session.windows - [@window]).first
@session.within_window other_window do
@ -118,7 +134,7 @@ Capybara::SpecHelper.spec '#within_window', requires: [:windows] do
it "should warn" do
expect(@session).to receive(:warn).with("DEPRECATION WARNING: Passing string argument "\
"to #within_window is deprecated. Pass window object or lambda. "\
"(called from #{__FILE__}:122)").and_call_original
"(called from #{__FILE__}:138)").and_call_original
@session.within_window('firstPopup') {}
end