Skip to content

Commit

Permalink
Merge pull request #2 from edwinvdgraaf/selenium-webdriver
Browse files Browse the repository at this point in the history
Support selenium-webdriver for capybara
  • Loading branch information
ronen committed Feb 26, 2014
2 parents 27ade6a + ed0f386 commit dc9711c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
20 changes: 20 additions & 0 deletions README.md
Expand Up @@ -107,6 +107,26 @@ The default window size for the renders is 1024 x 768 pixels. You can specify a

Note that this specifies the size of the browser window viewport; but rspec-page-regression requests a render of the full page, which might extend beyond the window. So the rendered file dimensions may be larger than this configuration value.

### Using the selenium driver

You can also use the selenium driver with capybara. This offers the possiblity to visually test your pages against a range of real browsers.

Add the [selenium-webdriver](https://rubygems.org/gems/selenium-webdriver) to your Gemfile:

gem 'selenium-webdriver'

And in your spec_helper replace:

require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist

With:

require 'selenium/webdriver'
Capybara.javascript_driver = :selenium


See also the [capybara readme](https://github.com/jnicklas/capybara#selenium) and [selenium wiki](https://code.google.com/p/selenium/wiki/RubyBindings) for more information.

## Contributing

Expand Down
9 changes: 7 additions & 2 deletions lib/rspec/page-regression/renderer.rb
Expand Up @@ -4,8 +4,13 @@ module Renderer
def self.render(page, test_image_path)

test_image_path.dirname.mkpath unless test_image_path.dirname.exist?
page.driver.resize *RSpec::PageRegression.page_size
page.driver.render test_image_path, :full => true
# Capybara doesn't implement resize in API
unless page.driver.respond_to? :resize
page.driver.browser.manage.window.resize_to *RSpec::PageRegression.page_size
else
page.driver.resize *RSpec::PageRegression.page_size
end
page.driver.save_screenshot test_image_path, :full => true
end
end
end
21 changes: 18 additions & 3 deletions spec/match_expectation_spec.rb
Expand Up @@ -7,7 +7,7 @@
@opts = { :full => true }
@driver = mock("Driver")
@driver.stubs :resize
@driver.stubs :render
@driver.stubs :save_screenshot
@page = mock("Page")
@page.stubs(:driver).returns @driver
@match_argument = nil
Expand All @@ -25,7 +25,22 @@

context "framework" do
Then { @driver.should have_received(:resize).with(1024, 768) }
Then { @driver.should have_received(:render).with(test_path, @opts) }
Then { @driver.should have_received(:save_screenshot).with(test_path, @opts) }

context "selenium" do
Given {
@browser = mock("Browser")
@window = mock("Window")
@window.stubs(:resize_to)
manage = mock("Manage")
manage.stubs(:window).returns @window
@browser.stubs(:manage => manage)
@driver.stubs(:browser => @browser)
@driver.unstub(:resize)
}

Then { @window.should have_received(:resize_to).with(1024, 768) }
end
end

context "when files match" do
Expand Down Expand Up @@ -102,7 +117,7 @@
example_group: { description: "parent" }
}
end
Then { @driver.should have_received(:render).with(Pathname.new("tmp/spec/expectation/parent/test.png"), @opts) }
Then { @driver.should have_received(:save_screenshot).with(Pathname.new("tmp/spec/expectation/parent/test.png"), @opts) }
Then { @error.message.should include "Missing expectation image spec/expectation/parent/expected.png" }
end

Expand Down

0 comments on commit dc9711c

Please sign in to comment.