lib/capybara/screenshot/diff/capybara_setup.rb in capybara-screenshot-diff-0.5.0 vs lib/capybara/screenshot/diff/capybara_setup.rb in capybara-screenshot-diff-0.5.1
- old
+ new
@@ -83,11 +83,14 @@
end
setup do
if Capybara::Screenshot.window_size
if selenium?
- page.driver.browser.manage.window.resize_to(*Capybara::Screenshot.window_size)
+ # TODO(uwe): Enable for Chrome and non-windows when it works)
+ if !page.driver.chrome? || ON_WINDOWS
+ page.driver.browser.manage.window.resize_to(*Capybara::Screenshot.window_size)
+ end
elsif poltergeist?
page.driver.resize(*Capybara::Screenshot.window_size)
end
end
end
@@ -110,16 +113,13 @@
FileUtils.rm_rf screenshot_dir
end
def screenshot(name)
return unless Capybara::Screenshot.active?
- if selenium? && Capybara::Screenshot.window_size
- return unless page.driver.browser.manage.window.size ==
- Selenium::WebDriver::Dimension.new(*Capybara::Screenshot.window_size)
- end
+ return if window_size_is_wrong?
if @screenshot_counter
- name = "#{'%02i' % @screenshot_counter}_#{name}"
+ name = "#{format('%02i', @screenshot_counter)}_#{name}"
@screenshot_counter += 1
end
name = full_name(name)
file_name = "#{self.class.screenshot_area_abs}/#{name}.png"
org_name = "#{self.class.screenshot_area_abs}/#{name}_0.png~"
@@ -128,9 +128,16 @@
FileUtils.mkdir_p File.dirname(file_name)
committed_file_name = check_vcs(name, file_name, org_name)
take_stable_screenshot(file_name)
return unless committed_file_name && File.exist?(committed_file_name)
(@test_screenshots ||= []) << [caller[0], name, file_name, committed_file_name, new_name, org_name]
+ end
+
+ private def window_size_is_wrong?
+ selenium? && Capybara::Screenshot.window_size &&
+ (!page.driver.chrome? || ON_WINDOWS) && # TODO(uwe): Allow for Chrome when it works
+ page.driver.browser.manage.window.size !=
+ Selenium::WebDriver::Dimension.new(*Capybara::Screenshot.window_size)
end
def check_vcs(name, file_name, org_name)
svn_file_name = "#{self.class.screenshot_area_abs}/.svn/text-base/#{name}.png.svn-base"
if File.exist?(svn_file_name)