Skip to content

Commit

Permalink
Add Support for window maximize
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Jun 29, 2016
1 parent 6546819 commit ee376e6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Next release ###

#### Features ####
* Add Window#maximize support - defaults to 1366x768 can be overridden with :screen_size option in driver registration (Thomas Walpole)

#### Bug fixes ####

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ end
* `:js_errors` (Boolean) - When false, JavaScript errors do not get re-raised in Ruby.
* `:window_size` (Array) - The dimensions of the browser window in which to test, expressed
as a 2-element array, e.g. [1024, 768]. Default: [1024, 768]
* `:screen_size` (Array) - The dimensions the window size will be set to when Window#maximize is called. Expressed
as a 2-element array, e.g. [1600, 1200]. Default: [1366, 768]
* `:phantomjs_options` (Array) - Additional [command line options](http://phantomjs.org/api/command-line.html)
to be passed to PhantomJS, e.g. `['--load-images=no', '--ignore-ssl-errors=yes']`
* `:extensions` (Array) - An array of JS files to be preloaded into
Expand Down
8 changes: 8 additions & 0 deletions lib/capybara/poltergeist/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ def resize_window_to(handle, width, height)
end
end

def maximize_window(handle)
resize_window_to(handle, *screen_size)
end

def window_size(handle)
within_window(handle) do
evaluate_script('[window.innerWidth, window.innerHeight]')
Expand Down Expand Up @@ -380,6 +384,10 @@ def dismiss_modal(type, options = {})

private

def screen_size
options[:screen_size] || [1366,768]
end

def find_modal(options)
start_time = Time.now
timeout_sec = options[:wait] || begin Capybara.default_max_wait_time rescue Capybara.default_wait_time end
Expand Down
17 changes: 17 additions & 0 deletions spec/integration/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ def session_url(path)
).to eq([200, 400])
end

it 'defaults viewport maximization to 1366x768' do
@session.visit('/')
@session.current_window.maximize
expect(@session.current_window.size).to eq([1366, 768])
end

it 'allows custom maximization size' do
begin
@driver.options[:screen_size] = [1600, 1200]
@session.visit('/')
@session.current_window.maximize
expect(@session.current_window.size).to eq([1600, 1200])
ensure
@driver.options.delete(:screen_size)
end
end

it 'allows the page to be scrolled' do
@session.visit('/poltergeist/long_page')
@driver.resize(10, 10)
Expand Down

0 comments on commit ee376e6

Please sign in to comment.