wdio chrome headless is not running headlessly - webdriver-io

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'],
      },
    },
  ],

Related

Custom args for each instance of Chrome when running parallel tests with Protractor

Is it possible to pass custom args for each instance of Chrome when running parallel tests in Protractor? I need to know the Remote debugging port for each instance so I can connect with the Dev Tools protocol.
As I see it there's two options. Set the port to a specific unique value for each instance, or let it be set automatically and fetch it somehow when preparing the tests. Would it be possible with any of these options?
exports.config = {
framework: 'jasmine',
chromeDriver: chromeDriverPath,
multiCapabilities: [{
browserName: 'chrome',
chromeOptions: {
args: process.env.HEADLESS && puppeteer ? ['--headless', `--remote-debugging-port=${DEV_TOOLS_PORT}`] : [`--remote-debugging-port=${DEV_TOOLS_PORT}`],
binary: puppeteer.executablePath()
},
shardTestFiles: true,
maxInstances: 1
}]
}
If I got the problem right, what you could do is to pass parameters as env variables to protractor on start. So your config would look like this:
exports.config = {
framework: 'jasmine',
chromeDriver: chromeDriverPath,
multiCapabilities: [{
'browserName': 'chrome',
'chromeOptions': {
args: [`--remote-debugging-port=${process.env.PORT_ONE}`]
}
}, {
'browserName': 'chrome',
'chromeOptions': {
args: [`--remote-debugging-port=${process.env.PORT_TWO}`]
}
}]
}
And then start your protractor process with env variables like so:
PORT_ONE=90 PORT_TWO=80 protractor protractor.conf.js
One of the two options are solved. But I would still like to know if there's a possibility to use custom args for each instance.
// Get Remote debugging port for chrome
let chromeRemoteDebuggingPort;
browser.getCapabilities().then((capabilities) => {
const chromeOptions = capabilities.get('goog:chromeOptions');
if( chromeOptions && chromeOptions.debuggerAddress) {
chromeRemoteDebuggingPort = chromeOptions.debuggerAddress.split(':')[1];
}
});

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

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

How to skip a test-case file from executing for a particular browser in Protractor

I am using Protractor for writing e2e test cases in Angular using Jasmin.
I am using Saucelab for executing my test cases on Chrome, Firefox, Edge and IE11.
I came across a issue that hover functionality using mouseMove doesen't work in case of IE11 so i want to skip those test-cases for IE11 but thost test must execute for rest 3 browsers.
My protractor.config.js file as below
...
...
multiCapabilities: ([
{
name: "ds-e2e-firefox",
browserName: "firefox",
version: "63"
},
{
name: "ds-e2e-chrome",
browserName: "googlechrome",
version: "70"
},
{
name: "ds-e2e-edge",
browserName: "MicrosoftEdge",
version: "16",
avoidProxy: true
},
{
name: "ds-e2e-ie11",
browserName: "internet explorer",
version: "11",
iedriverVersion: "3.12.0"
}
]).map(cap => Object.assign(cap, {
platform: "Windows 10",
seleniumVersion: SELENIUM_VERSION,
screenResolution: "1920x1080"
}))
};
...
I am open with some other workaround as i am unable to think how to achieve this.
multicapabilities is collection which takes array of capability so you Can try with exclude keyword reserved for ignoring spec files.
{
name: "ds-e2e-ie11",
browserName: "internet explorer",
version: "11",
iedriverVersion: "3.12.0",
exclude: [specfile.js, specfile2.js]
}
One of the ways to approach it is this way
it("Search by name", async () => {
// open home page
await browser.get(params.baseUrl);
let capabilities = await browser.getCapabilities();
let browserName = capabilities.map_.get('browserName');
if (browserName === "chrome") {
// your test goes here
}
});

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