Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Firefox Preferences in Nightwatch

How do you set firefox preferences in nightwatch? I would like to do the equivalent in java with nightwatch.

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages", "de");
WebDriver driver = new FirefoxDriver(profile);

I have this working in chrome, but again I can't figure out how to do it in Firefox.

"desiredCapabilities": {
  "browserName": "chrome",
  "javascriptEnabled": true,
  "acceptSslCerts": true,
  "chromeOptions" :{
    "prefs": {
      "intl.accept_languages":"fr"
    }
  }
}

Thanks

like image 376
Madison Haynie Avatar asked Oct 03 '15 04:10

Madison Haynie


1 Answers

The solution is to create a Firefox profile for your Nightwatch test.

1) Create a new Firefox profile:

In a terminal, execute this command : "firefox -p"
Then create a profil with the name "webdriver".

2) Configure the new profile

Go to this config page with the url : about:config
Search the name "intl.accept_languages" and update the value.
Exit Firefox for now.

3) Configure Nightwatch to use the new profile

  1. "webdriver.firefox.profile" : "webdriver"

  2. List item "browserName" : "firefox"

Be careful ! it is not a "desiredCapability" parameter.

Solution 1: (test config)

{
  "yourTest" : {
    "default" : {
       ...
       "webdriver.firefox.profile" : "webdriver",
       "launch_url": "http://localhost:3000",
       "desiredCapabilities" : {
         "browserName" : "firefox",
         "javascriptEnabled" : true,
         "acceptSslCerts" : true
    }
    }
  }
}

Solution 2: (global config)

{
  ...
  "selenium" : {
    "start_process" : false,
    "server_path" : "",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "",
      "webdriver.ie.driver" : "",
      "webdriver.firefox.profile" : "webdriver"
    }
  },
  ...
  "yourTest": {
    "default": {
        "launch_url": "http://localhost:3000",
        "desiredCapabilities" : {
            "browserName" : "firefox",
            "javascriptEnabled" : true,
            "acceptSslCerts" : true
        }
    },
  ...
  }
  ...
}

check the selenium settings : http://nightwatchjs.org/guide#selenium-settings

like image 74
Nicolas Pennec Avatar answered Oct 04 '22 10:10

Nicolas Pennec