From ee376e6432d26b41f6103d7d011144862d8f413f Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Mon, 27 Jun 2016 15:06:59 -0700 Subject: [PATCH] Add Support for window maximize --- CHANGELOG.md | 1 + README.md | 2 ++ lib/capybara/poltergeist/driver.rb | 8 ++++++++ spec/integration/driver_spec.rb | 17 +++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f475efdd..abeed246 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 #### diff --git a/README.md b/README.md index adf3ea40..02a5f3cd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/capybara/poltergeist/driver.rb b/lib/capybara/poltergeist/driver.rb index 447999f2..be95ac35 100644 --- a/lib/capybara/poltergeist/driver.rb +++ b/lib/capybara/poltergeist/driver.rb @@ -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]') @@ -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 diff --git a/spec/integration/driver_spec.rb b/spec/integration/driver_spec.rb index d5121eb6..57241b10 100644 --- a/spec/integration/driver_spec.rb +++ b/spec/integration/driver_spec.rb @@ -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)