Disable browser cache for cucumber scenarios

Some time back, we faced this issue where we had setup cache control headers for certain actions in our rails app. Now when the cucumber scenarios for these actions ran, for scenarios in the same feature when the browser did not go off, the cached results would show up and our build would fail.

So here’s a quick tip to disable browser cache (for firefox) for cucumber. In your env.rb where you initialize the selenium driver, you need to put in some settings for the profile that gets used for your browser.

Capybara.register_driver :selenium do |app|

    profile = Selenium::WebDriver::Firefox::Profile.new

    profile[“browser.cache.disk.enable”] = false

    profile[“browser.cache.memory.enable”] = false

    Capybara::Driver::Selenium.new(app, :profile => profile, :http_client => WebDriver::Remote::Http::Curb)

end

 

For details on these two properties of firefox see 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s