follow me icons

Sunday, November 7, 2010

Upgrading to Capybara 0.4.0

So Capybara 0.4.0 is out now and if you do a 'gem install capybara', you will get Capybara 0.4.0 by default. This has byfar the most changes and not backward compatible with the previous version.

After upgrading to 0.4.0, my test started to fail with a very weird error message ("superclass mismatch for class Node (TypeError)"). It took me one whole day to familiarize myself with the new version which include looking at Capybara code to be able to modify my current test.

Here are what I have to do to upgrade to Capybara 0.4.0 from 0.3.9 in my project

1. Changed "class Node < Capybara::Node" to "class Capybara::Element < Capybara::Node"
See How to send keystrokes to an element in the browser
2. Changed the use of variable "node" to "native"
3. #locate is now deprecated, changed all of my use of "locate" into "find"
4. Changed the way we setup the capybara config

Before

Capybara.default_driver = :selenium
Capybara.run_server = false
Capybara.default_selector = :css
Capybara.default_wait_time = 30


After

Capybara.configure do |config|
config.default_driver = :selenium
config.default_driver = :selenium
config.run_server = false
config.default_selector = :css
config.default_wait_time = 30
end


5. Changed the way we register the browser driver

Before

class Capybara::Driver::Selenium
def self.driver
unless @driver

profile = Selenium::WebDriver::Firefox::Profile.new
profile["network.proxy.type"] = 1
profile["network.proxy.http"] = "proxy setting"
profile["network.proxy.http_port"] = 8080
@driver = Selenium::WebDriver.for(:firefox, :profile => profile)

at_exit do
@driver.quit
end
end
@driver
end
end


After

Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
profile["network.proxy.type"] = 1
profile["network.proxy.http"] = "proxy setting"
profile["network.proxy.http_port"] = 8080
Capybara::Driver::Selenium.new(app, :browser => :firefox, :profile => profile)
end

No comments:

Post a Comment