From 8e90854d53d63b1df283b03d20c755c1018fe832 Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Tue, 11 Feb 2014 13:08:45 -0800 Subject: [PATCH] Render full window size if document has no height When rendering a screenshot with `:full => true` on a document which has a height of zero, the call fails silently with no screenshot being created. This situation can occur with pages that use absolute or fixed positioning for all content, for example. Changed to use the `documentElement`'s `clientHeight` & `clientWidth` as a fallback, which will result in screenshots the size of the viewport in that case. --- CHANGELOG.md | 1 + lib/capybara/poltergeist/client/agent.coffee | 4 ++-- lib/capybara/poltergeist/client/compiled/agent.js | 4 ++-- spec/integration/driver_spec.rb | 11 +++++++++++ spec/support/views/fixed_positioning.erb | 6 ++++++ 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 spec/support/views/fixed_positioning.erb diff --git a/CHANGELOG.md b/CHANGELOG.md index e0d207aa..d56d6344 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ (Pedro CarriƧo and Erik Ostrom) [Issue #432] * Raise exception on PhantomJS "status: fail" result (i.e DNS issue) instead of returning minimal HTML body (Dean Holdren) [Issue #473] +* Render full window size when document has no height (Kevin McConnell) ### 1.5.0 ### diff --git a/lib/capybara/poltergeist/client/agent.coffee b/lib/capybara/poltergeist/client/agent.coffee index 50313080..df0fa48d 100644 --- a/lib/capybara/poltergeist/client/agent.coffee +++ b/lib/capybara/poltergeist/client/agent.coffee @@ -48,8 +48,8 @@ class PoltergeistAgent @elements.length - 1 documentSize: -> - height: document.documentElement.scrollHeight, - width: document.documentElement.scrollWidth + height: document.documentElement.scrollHeight || document.documentElement.clientHeight, + width: document.documentElement.scrollWidth || document.documentElement.clientWidth get: (id) -> @nodes[id] or= new PoltergeistAgent.Node(this, @elements[id]) diff --git a/lib/capybara/poltergeist/client/compiled/agent.js b/lib/capybara/poltergeist/client/compiled/agent.js index bcbf8494..0d7036ea 100644 --- a/lib/capybara/poltergeist/client/compiled/agent.js +++ b/lib/capybara/poltergeist/client/compiled/agent.js @@ -89,8 +89,8 @@ PoltergeistAgent = (function() { PoltergeistAgent.prototype.documentSize = function() { return { - height: document.documentElement.scrollHeight, - width: document.documentElement.scrollWidth + height: document.documentElement.scrollHeight || document.documentElement.clientHeight, + width: document.documentElement.scrollWidth || document.documentElement.clientWidth }; }; diff --git a/spec/integration/driver_spec.rb b/spec/integration/driver_spec.rb index bc21dc29..4f60bd55 100644 --- a/spec/integration/driver_spec.rb +++ b/spec/integration/driver_spec.rb @@ -131,6 +131,17 @@ def session_url(path) end end + it 'supports rendering the entire window when documentElement has no height' do + @session.visit('/poltergeist/fixed_positioning') + + create_screenshot file, full: true + File.open(file, 'rb') do |f| + expect(ImageSize.new(f.read).size).to eq( + @driver.evaluate_script('[window.innerWidth, window.innerHeight]') + ) + end + end + it 'supports rendering just the selected element' do @session.visit('/poltergeist/long_page') diff --git a/spec/support/views/fixed_positioning.erb b/spec/support/views/fixed_positioning.erb new file mode 100644 index 00000000..11f0c5f6 --- /dev/null +++ b/spec/support/views/fixed_positioning.erb @@ -0,0 +1,6 @@ + + +
+

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

+
+