Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

Is it possible to do automated browser testing with Selenium/WebdriverIO using Chrome in headless mode?

Supposedly Chrome --headless is a thing now, but I can't get their example working. I was hoping Selenium had an option for this?

I'm initializing WebdriverIO like so:

const WebdriverIO = require('webdriverio');

let driver = WebdriverIO.remote({

    desiredCapabilities: {

        browserName: browser, // "chrome" or "firefox"

    },

});

And I'm starting Selenium using selenium-standalone: 

selenium-standalone start > /dev/null 2>&1

1 Answer

0 votes
by (62.9k points)

WebdriverIO

Here is a working example with WebdriverIO: https://github.com/prabhpreetkb/webdriverio-chrome-headless

The basic idea:

 import * as webdriverio from 'webdriverio';

// Headless is supported in Chrome >= 58. Not currently stable, so using dev

// build.

const CHROME_BIN_PATH = '/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome';

const options = {

    desiredCapabilities: {

        browserName: 'chrome',

        chromeOptions: {

            binary: CHROME_BIN_PATH,

            args: [

                'headless',

               //Use --disable-gpu to include Mesa library, as per

                // https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md

                'disable-gpu',

            ],

        },

    },

};

webdriverio

    .remote(options)

    .init()

    .url('http://www.google.com')

    .getTitle().then(title => {

        console.log({ title });

    })

    .end();

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s selenium course online

Browse Categories

...