Your app now has mobile-friendly views. Do they have any Webkit-specific functionality that you want to test in-browser? Or rather, why are you testing your mobile views in desktop Firefox? Is it because Capybara/Selenium support for Webkit browsers was sketchy? Worry no more. Chrome 12, Capybara 1.0, and Selenium 2 are your new best friends.
So install Chrome, make sure your Gemfile has Capybara set to >= 1.0,
bundle install and let’s get configuring.
Update your SpecHelper
You have to tell Capybara that you want to use Selenium/Webdriver and Chrome. Put this in your
Capybara.register_driver :selenium_chrome do |app| Capybara::Selenium::Driver.new(app, :browser => :chrome) end
While there’s been limited Selenium support in Chrome for a while, with release 12 there is an entirely new and complete automation interface to Chrome. To use it you need a platform-specifc chromedriver binary in order to connect Webdriver and Chrome. Download it, make sure it’s executable, and put it on your path.
Chrome likes to update, so stay on the general release (if you can) to reduce update frequency. You can even take steps to prevent Chrome from updating, but I’ll leave that as an exercise for the reader.
That should be enough to get your Capybara specs to start using Chrome. You’ll want to play with your setup and maybe only run some specs with this driver.
Webdriver does not appear to support Safari. This may matter to you if you’re using this setup to approximate Mobile Safari. But for the types of tests you’re likely writing for Selenium it should be good enough. After all, every mobile Webkit build is slightly different.
While complete (in terms of browser features) and far faster than previous Selenium-Chrome pairings, it’s still slow-ish – for example, typing isn’t nearly as fast as Firefox. So you might not want to make this your default stack for your entire Rails app.
But that’s another post.
About the Author
BiographyMore Content by Davis W. Frank