Read more

Set the accept-language of Chrome in selenium tests

Christoph Beck
May 10, 2012Software engineer

You can set the resolution and user agent used in selenium tests with chrome with the method described in this card, but you can also set the accept-language and other profile settings Show archive.org snapshot if you do this:

# features/support/chrome.rb
require "selenium/webdriver"


Capybara.register_driver :chrome320x480 do |app|
  args = []
  args << "--window-size=320,480"
  
  profile = Selenium::WebDriver::Chrome::Profile.new
  profile["intl.accept_languages"] = "en"
  
  Capybara::Selenium::Driver.new(app, :browser => :chrome, :args => args, :profile => profile)
end
Illustration money motivation

Opscomplete powered by makandra brand

Save money by migrating from AWS to our fully managed hosting in Germany.

  • Trusted by over 100 customers
  • Ready to use with Ruby, Node.js, PHP
  • Proactive management by operations experts
Read more Show archive.org snapshot

This does not just apply for Chrome, it also works for other browsers such as Firefox.
You might have to find out about other key value pairs. For firefox there is a list here Show archive.org snapshot .
Anyway, the following setting is the same for firefox:

profile = Selenium::WebDriver::Firefox::Profile.new
profile["intl.accept_languages"] =  "de-DE"
Capybara::Selenium::Driver.new(app, :browser => :firefox, :args => args, :profile => profile)
Posted by Christoph Beck to makandra dev (2012-05-10 14:18)