Selenium/WebdriverIO Chrome headless?
I did not try this myself yet, but you can download --headless build from this docker image:
https://hub.docker.com/r/justinribeiro/chrome-headless/
or build it yourself (this takes few hours, and you need a lot of RAM :) ) http://www.zackarychapple.guru/chrome/2016/08/24/chrome-headless.html
Then you should be able to just specify --headless to your chrome launch script, and use chromedriver, acording to this question in dev mailing list: https://groups.google.com/a/chromium.org/forum/#!topic/headless-dev/aAGFq8n_s6g
You can use capabilities in wdio.conf.js file
capabilities: [{
maxInstances: 1,
browserName: 'chrome',
'goog:chromeOptions': {
args: ["--headless", "user-agent=...","--disable-gpu","--window-size=1440,735"]
}
You can add capabilities to your driver by adding the chromeOptions which sets the arguments as an array of String '--headless'
.
capabilities: [{
maxInstances: 1,
browserName: 'chrome',
chromeOptions: {
args: ['--headless'],
},
}],
WebdriverIO
Here is a working example with WebdriverIO: https://github.com/OliverJAsh/webdriverio-chrome-headless/blob/5f231990310023f63f9ea8581567e0d56e2d53ea/src/index.ts
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 avoid an error from a missing 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();
WebDriverJS
Here is a working example with WebDriverJs (the official JavaScript client to WebDriver): https://github.com/OliverJAsh/webdriverjs-chrome-headless/blob/554ea2f150e962257119703c2473753b90842087/src/index.ts
The basic idea:
import * as webdriver from 'selenium-webdriver';
import * as chromeDriver from 'selenium-webdriver/chrome';
// 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 = new chromeDriver.Options();
options.setChromeBinaryPath(CHROME_BIN_PATH);
options.addArguments(
'headless',
// Use --disable-gpu to avoid an error from a missing Mesa library, as per
// https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
'disable-gpu',
);
const driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();