mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Add maximize window
This commit is contained in:
parent
c157ef4e61
commit
397be95d09
10 changed files with 53 additions and 10 deletions
|
@ -25,7 +25,9 @@ before_install:
|
|||
- sudo apt-get update
|
||||
- sudo apt-get install google-chrome-stable --force-yes
|
||||
- sudo chmod 1777 /dev/shm
|
||||
- sudo apt-get install fluxbox -y --force-yes
|
||||
before_script:
|
||||
- sh -e /etc/init.d/xvfb start
|
||||
- export DISPLAY=:99.0
|
||||
- sh -e /etc/init.d/xvfb start
|
||||
- fluxbox > /dev/null 2>&1 &
|
||||
script: "bundle exec rake travis"
|
||||
|
|
|
@ -63,6 +63,10 @@ class Capybara::Driver::Base
|
|||
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#resize_window_to'
|
||||
end
|
||||
|
||||
def maximize_current_window
|
||||
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#maximize_current_window'
|
||||
end
|
||||
|
||||
def close_current_window
|
||||
raise Capybara::NotSupportedByDriverError, 'Capybara::Driver::Base#close_window'
|
||||
end
|
||||
|
|
|
@ -139,6 +139,10 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
browser.manage.window.resize_to(width, height)
|
||||
end
|
||||
|
||||
def maximize_current_window
|
||||
browser.manage.window.maximize
|
||||
end
|
||||
|
||||
def close_current_window
|
||||
browser.close
|
||||
end
|
||||
|
|
|
@ -417,7 +417,7 @@ module Capybara
|
|||
# 3. Switches back (this step will be invoked even if exception will happen at second step)
|
||||
#
|
||||
# @overload within_window(window) { do_something }
|
||||
# @param [Capybara::Window] instance of Capybara::Window class
|
||||
# @param window [Capybara::Window] instance of `Capybara::Window` class
|
||||
# that will be switched to
|
||||
# @raise [driver#no_such_window_error] if unexistent (e.g. closed) window was passed
|
||||
# @overload within_window(proc_or_lambda) { do_something }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Capybara::SpecHelper.spec '#become_closed', requires: [:windows] do
|
||||
Capybara::SpecHelper.spec '#become_closed', requires: [:windows, :js] do
|
||||
before(:each) do
|
||||
@window = @session.current_window
|
||||
@session.visit('/with_windows')
|
||||
|
@ -48,7 +48,7 @@ Capybara::SpecHelper.spec '#become_closed', requires: [:windows] 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(); }, 700);')
|
||||
@session.execute_script('setTimeout(function(){ window.close(); }, 800);')
|
||||
end
|
||||
Capybara.using_wait_time 0.4 do
|
||||
expect do
|
||||
|
|
|
@ -18,7 +18,7 @@ Capybara::SpecHelper.spec '#open_new_window', requires: [:windows] do
|
|||
expect(@session.current_url).to eq('about:blank')
|
||||
end
|
||||
|
||||
it 'should open window with changable content' do
|
||||
it 'should open window with changeable content' do
|
||||
window = @session.open_new_window
|
||||
@session.within_window window do
|
||||
@session.visit '/with_html'
|
||||
|
|
|
@ -47,7 +47,7 @@ Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do
|
|||
end
|
||||
|
||||
it 'should find window if default_wait_time is more than timeout' do
|
||||
Capybara.using_wait_time 1 do
|
||||
Capybara.using_wait_time 1.2 do
|
||||
window = @session.window_opened_by do
|
||||
@session.find(:css, '#openWindowWithTimeout').click
|
||||
end
|
||||
|
|
|
@ -81,7 +81,7 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|||
end
|
||||
|
||||
describe '#size' do
|
||||
it 'should return size of whole window' do
|
||||
it 'should return size of whole window', requires: [:js] do
|
||||
expect(@session.current_window.size).to eq @session.evaluate_script("[window.outerWidth, window.outerHeight];")
|
||||
end
|
||||
|
||||
|
@ -96,7 +96,7 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|||
end
|
||||
|
||||
describe '#resize_to' do
|
||||
it 'should be able to resize window' do
|
||||
it 'should be able to resize window', requires: [:js] do
|
||||
width, height = @session.evaluate_script("[window.outerWidth, window.outerHeight];")
|
||||
@session.current_window.resize_to(width-10, height-10)
|
||||
expect(@session.evaluate_script("[window.outerWidth, window.outerHeight];")).to eq([width-10, height-10])
|
||||
|
@ -111,4 +111,25 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|||
end.to raise_error(Capybara::WindowError, "Resizing not current window is not possible.")
|
||||
end
|
||||
end
|
||||
|
||||
describe '#maximize' do
|
||||
it 'should be able to maximize window', requires: [:js] do
|
||||
screen_width, screen_height = @session.evaluate_script("[window.screen.availWidth, window.screen.availHeight];")
|
||||
window = @session.current_window
|
||||
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.6 # Selenium returns when window isn't yet fully resized
|
||||
expect(@session.evaluate_script("[window.outerWidth, window.outerHeight];")).to eq([screen_width, screen_height])
|
||||
end
|
||||
|
||||
it 'should raise error if invoked not for current window' do
|
||||
@other_window = @session.window_opened_by do
|
||||
@session.find(:css, '#openWindow').click
|
||||
end
|
||||
expect do
|
||||
@other_window.maximize
|
||||
end.to raise_error(Capybara::WindowError, "Maximizing not current window is not possible.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,7 +21,7 @@ Capybara::SpecHelper.spec '#windows', requires: [:windows] do
|
|||
@session.within_window(window) { @session.title }
|
||||
end
|
||||
expect(titles).to match_array([
|
||||
'With Windows', 'Title of the first popup', 'Title of popup two'
|
||||
'With Windows', 'Title of the first popup', 'Title of popup two'
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,7 +45,8 @@ module Capybara
|
|||
|
||||
##
|
||||
# Close window. Available only for current window.
|
||||
# After calling this method future invocations of other Capybara methods should raise `session.driver.no_such_window_error` until another window will be switched to.
|
||||
# After calling this method future invocations of other Capybara methods should raise
|
||||
# `session.driver.no_such_window_error` until another window will be switched to.
|
||||
# @raise [Capybara::WindowError] if invoked not for current window
|
||||
#
|
||||
def close
|
||||
|
@ -74,6 +75,17 @@ module Capybara
|
|||
@driver.resize_current_window_to(width, height)
|
||||
end
|
||||
|
||||
##
|
||||
# Maximize window. Available only for current window.
|
||||
# If a particular driver (e.g. headless driver) doesn't have concept of maximizing it
|
||||
# may not support this method.
|
||||
# @raise [Capybara::WindowError] if invoked not for current window
|
||||
#
|
||||
def maximize
|
||||
raise_unless_current('Maximizing')
|
||||
@driver.maximize_current_window
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
other.kind_of?(self.class) && @session == other.session && @handle == other.handle
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue