WebdriverIO with ChromeDriver headless without Selenium

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):

  1. Install Chrome Web Browser
  2. Download ChromeDriver
  3. Run ChromeDriver
  4. Install WebdriverIO by running npm i webdriverio
  5. 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"]
}
}
})

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *