protractor/selenium started ignoring the chrome options (chromeOptions) in protractor.conf.js - selenium

I just rebuilt our development environment. This forced the latest version of chrome and suddenly the protractor based tests stopped working. After some research, I tracked this down to the fact that our chrome options in the protractor configuration file are now ignored.
Here is the configuration that used to work fine before:
exports.config = {
...
multiCapabilities : [
{
browserName: "chrome",
chromeOptions: {
args: [
"--disable-gpu",
"--headless",
'--no-sandbox',
"--incognito"
]
}
},
},
],
...
};
Before After
protractor 6.0.0 6.0.0
selenium 4.0.0-alpha-1 4.0.0-alpha-1
chrome 74.0.3729.157 76.0.3809.100
chromedriver 74.0.3729.6 76.0.3809.68

In recent versions of selenium you have to specify the chrome options as goog:chromeOptions. So just change the chromeOptions line above to the following:
...
"goog:chromeOptions": {
...
and you are back in business.

"chromeOptions": {}
its still usable in most cases, but does not support new arguments provided by chrome
suggested to use
"goog:chromeOptions": {}
Ref to doc: http://chromedriver.chromium.org/capabilities
Same rule for firefox
"moz:firefoxOptions": {}
Ref to doc: https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions

Related

why It show me This version of ChromeDriver only supports Chrome version 104?

when I use wdio for e2e tests, I got an exception.But my chromedriver is 106.0.1.
[0-1] 2022-10-24T10:58:18.928Z ERROR webdriver: Request failed with status 500 due to session not created: session not created: This version of ChromeDriver only supports Chrome version 104
[0-1] Current browser version is 106.0.5249.119 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
but when I check chromedriver:
chromedriver -v
ChromeDriver 106.0.5249.61 (511755355844955cd3e264779baf0dd38212a4d0-refs/branch-heads/5249#{#569})
I has been tried all those methods:
SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81.
But I still got same exception.please help me.
My configureation:
module.exports.config = {
runner: "local",
path: "/wd/hub",
specs: ["./test/specs/*.js"],
maxInstances: 1,
capabilities: [
{
pageLoadStrategy: "none",
maxInstances: 1,
//
browserName: "chrome",
"goog:chromeOptions": {
excludeSwitches: ["enable-automation"],
},
},
],
logLevel: "warn",
bail: 0,
baseUrl: "http://localhost:3333",
waitforTimeout: 10000,
connectionRetryTimeout: 90000,
connectionRetryCount: 3,
services: ["chromedriver"],
framework: "mocha",
reporters: ["spec"],
}
I resolve this question by configure path.
services: [
[
"chromedriver",
{
chromedriverCustomPath: "/usr/local/bin/chromedriver",
},
],
],
I solved this problem by configuring the path. But I don't think this is a good method, because it means that any participant who uses this testing function needs to set the chromedriver in this path.
In fact, another project with the same npm version and my other configuration can run normally without configuring the path. This is really strange! This shows that my local chromedriver has no problems and can run directly.

wdio chrome headless is not running headlessly

Headless chrome doesn't seem to be headless for me. I'm using wdio and have this as my configuration:
capabilities: [
{
// maxInstances can get overwritten per capability. So if you have an in-house Selenium
// grid with only 5 firefox instances available you can make sure that not more than
// 5 instances get started at a time.
maxInstances: 5,
//
browserName: 'chrome',
args: ['--headless', '--disable-gpu', '--window-size=1280,800'],
binary: '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
}
]
I'm also outputting what the capabilities are prior to the browser starting:
{
"maxInstances": 5,
"browserName": "chrome",
"args": [
"--headless",
"--disable-gpu",
"--window-size=1280,800"
],
"binary": "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
}
My chrome browser is launching and I can see webdriver driving the test. Everything I have many posts doing it in this manner and it's supposed to just work. What am I missing?
UPDATE
I've modified capabilities to be read in from an environment variable. If I use BROWSER=chrome, I see the proper capabilities go through and the browser starts in chrome. If I use BROWSER=firefox, firefox opens up and I see the proper capabilities. If I don't use anything I see the proper capabilities, chrome opens up, but it's not headless.
const CHROME = {
browserName: 'chrome',
};
const FIREFOX = {
browserName: 'firefox',
};
const CHROME_HEADLESS = {
browserName: 'chrome',
args: ['headless', 'disable-gpu']
};
function getCapabilities() {
let browser;
switch(process.env.BROWSER && process.env.BROWSER.toLowerCase()) {
case 'chrome':
browser = CHROME;
break;
case 'firefox':
browser = FIREFOX;
break;
default:
browser = CHROME_HEADLESS;
break;
}
return [Object.assign({maxInstances: 5}, browser)];
}
To go along with the accepted answer, in newer version of Selenium (3.8 and higher) you may have to specify chromeOptions as "goog:chromeOptions"
https://gist.github.com/disintegrator/ff6e9341860e9b121099c71bc9381bd6
Have the capabilities inside your chrome options.
It works fine for me.
capabilities: [
{
      browserName: 'chrome',
      chromeOptions: {
        args: ['headless', 'disable-gpu'],
      },
    },
  ],

Cannot execute protractor tests using headless chrome on Selenium Grid nodes

I'm using Selenium server 3.8.1, with the hub and 2 nodes.
The hub and each node are executed on different machines.
Currently, I can launch the tests and they're working fine. But, I'm not able to make the headless mode run.
My config JSON only contains the capabilities object.
{
"capabilities":
[{
"browserName": "chrome",
"maxInstances": 3,
"seleniumProtocol": "WebDriver",
"chromeOptions": {
"args": [
"--headless",
"--disable-gpu",
"--window-size=1920x1080"]
}}]
}
I launch the selenium nodes using a .bat that contains the following command:
"C:\Program Files\Java\jre1.8.0_181\bin\java" -jar C:\jobs\selenium-node\selenium-server-standalone-3.8.1.jar -role node -hub http://172.16.0.5:5555/grid/register -port 5558 -nodeConfig config.json -maxSession 3
The selenium node works fine and appears on the selenium grid UI. Also, the capabilities of the chrome driver include the --headless and other parameters:
....
capabilities: Capabilities {browserName: chrome, chromeOptions: {args: [--headless, --disable-gpu, --window-size=1920x1080]}, maxInstances: 3, platform: XP, se:CONFIG_UUID: cdc21610-4c47-4d23-9478-a20..., seleniumProtocol: WebDriver}
....
On the protractor.conf file I have these capabilities, that work when I run the tests locally.
seleniumAddress:'http://172.16.0.5:5555/wd/hub',
getPageTimeout: 120000,
allScriptsTimeout: 120000,
ignoreUncaughtExceptions: true,
chromeOnly:true,
directConnect: false,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
"javascriptEnabled": true,
"acceptSslCerts": true,
"browserName": "chrome",
"chromeOptions": {
"args": [ "--headless", "--disable-gpu", "--window-size=1920,1080"]
}
},
But, when I launch the tests, the chrome driver isn't executed on headless mode. Works fine, but the different windows keep appearing.
Environment details:
chromedriver version: 2.36.540470
chrome version: 69.0.3497.100
As per your question/comment update you are using:
chromedriverVersion: '2.36.540470, chrome version' => '69.0.3497.100'
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.36
Release Notes of chromedriver=2.36 clearly mentions the following :
Supports Chrome v63-65
You are using chrome=69.0
Release Notes of ChromeDriver v2.42 clearly mentions the following :
Supports Chrome v68-70
So there is a clear mismatch between the ChromeDriver v2.36 and the Chrome Browser v69.0
Solution
Upgrade Selenium to current levels Version 3.14.0.
Upgrade ChromeDriver to current ChromeDriver v2.42 level.
Keep Chrome version between Chrome v68-70 levels. (as per ChromeDriver v2.42 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.

How to change browser language of webdriverio

I would like to change browser language. but it is not working. default browser language is displayed..
capabilities: [{
browserName: 'chrome',
chromeOptions: {
args: ['--lang=ja']
}
}],
If anyone is still interested in making this work, the WebdriverIO implementation would be:
capabilities: [{
browserName: 'chrome',
'goog:chromeOptions': {
args: [ '--your-args-go-here',
'--like-so',
'--and-so-and-so'
// e.g: '--headless', '--disable-gpu', '--start-fullscreen'
],
prefs: {
'intl.accept_languages': 'ru,RU'
}
}
}]
For the full list of Chromium switches (args array values), click here.
For the full list of Chromium preferences (prefs object properties), click here.
Note: another useful resource (which is always up to date) for Chromium switches is Peter Beverloo's Chromium CLI Switches portal.
Using the above Chrome config in the wdio.conf.js & running an Instagram login test will successfully convert the locale of the page to Russian, as seen below:
could you try this instead?
options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})
driver = webdriver.Chrome(chrome_options=options)
check on webdriver io how to use add_experimental_option

Error when running Selenium Server via Nightwatch

I'm attempting to run a simple test script. But I receive the following error:
I have my nightwatch config file setup as so:
nightwatch.conf.js
module.exports = {
"src_folders": [
"tests"// Where you are storing your Nightwatch e2e/UAT tests
],
"output_folder": "./reports", // reports (test outcome) output by nightwatch
"selenium": {
"start_process": true, // tells nightwatch to start/stop the selenium process
"server_path": "./node_modules/selenium-standalone/.selenium/selenium-server/2.53.1-server.jar",
"host": "127.0.0.1",
"port": 4444, // standard selenium port
"cli_args": { "webdriver.chrome.driver" : "./node_modules/selenium-standalone/.selenium/chromedriver/2.25-x64-chromedriver"
}
},
"test_settings": {
"default": {
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": './screenshots' // save screenshots here
},
"globals": {
"waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome"
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true // set to false to test progressive enhancement
}
}
}
}
guinea-pig.js
module.exports = { // addapted from: https://git.io/vodU0
'Guinea Pig Assert Title': function(browser) {
browser
.url('https://saucelabs.com/test/guinea-pig')
.waitForElementVisible('body')
.assert.title('I am a page title - Sauce Labs')
.saveScreenshot('ginea-pig-test.png')
.end();
}
};
The server path and chromedriver path are accurate and the most recent copy. I also have the latest version of chrome installed. Can someone please help me understand what could be the problem? Thanks!
Edit: I've also restarted the whole computer, same issue.
Try using the latest version of the Selenium standalone server v.3.0.1
If that doesn't work, then you can upgrade your chromedriver to the latest version and test. You can find the different versions here:
https://chromedriver.storage.googleapis.com/index.html
Also make sure you are using the most recent version of Nightwatch v0.9.9 and update it in you package.json file.
It is written very clear , your chrome version is lower than what chromedriver needs, just update your chrome to the latest version