I was excited to discover that WebdriverIO supports the use of ChromeDriver running in headless mode without the use of Selenium (because ChromeDriver supports the WebDriver protocol). Here’s a starter guide (assuming Node.js is installed):
- Install Chrome Web Browser
- Download ChromeDriver
- Run ChromeDriver
- Install WebdriverIO by running
npm i webdriverio
- Run the following file (based on the WebdriverIO example)
const webdriverio = require('webdriverio') const client = webdriverio.remote({ host: "localhost", port: 9515, path: "/", desiredCapabilities: { browserName: "chrome" } }) client .init() .url('https://duckduckgo.com/') .setValue('#search_form_input_homepage', 'WebdriverIO') .click('#search_button_homepage') .getTitle().then(function(title) { console.log('Title is: ' + title); }) .end()
To run Chrome in headless, use the following config:
const client = webdriverio.remote({ host: "localhost", port: 9515, path: "/", desiredCapabilities: { browserName: "chrome", chromeOptions: { args: ["headless", "disable-gpu"] } } })
Leave a Reply