WebdriverIO
WebdriverIO is a next-generation Node.js-based test automation framework for web browsers and mobile applications. It provides a comprehensive API built on top of the WebDriver and Appium protocols, allowing for robust end-to-end testing. The current stable version is 9.27.0, with releases occurring frequently, often multiple times a month, indicating active development and quick bug fixes. Key differentiators include its flexibility to run tests locally with WebDriver or remotely with cloud providers like Sauce Labs, built-in support for Puppeteer for browser automation, and its modular architecture allowing integration with various services and reporters. It offers a standalone API for custom scripts and a powerful test runner via `@wdio/cli` for structured test suites, supporting popular frameworks like Mocha, Jasmine, and Cucumber.
Common errors
-
Error: WebdriverIO requires Node.js >=18.20.0.
cause Your Node.js environment is running an older version that does not meet WebdriverIO's minimum requirements.fixUpgrade your Node.js installation to version 18.20.0 or higher. Use a Node Version Manager (like `nvm`) to easily switch and manage Node.js versions. -
TypeError: remote is not a function or is undefined
cause Attempting to use `remote` in a CommonJS module without proper destructuring, or trying to access the global `browser` object in a standalone script without initializing it.fixFor standalone scripts, ensure you use `import { remote } from 'webdriverio'` at the top. If working within the `@wdio/cli` test runner, the `browser` object is automatically globally available and does not need explicit import or initialization via `remote`. -
Error: Element with selector "#lst-ib" not found.
cause The specified CSS or XPath selector did not match any element on the page, or the element was not yet present/visible when the command was executed.fixVerify the selector is correct and unique for the desired element. Use explicit waits (e.g., `browser.waitUntil` or `element.waitForExist`) to ensure the element is available and interactable before attempting to use it. -
ReferenceError: browser is not defined
cause This error typically occurs when attempting to use the `browser` object in a standalone WebdriverIO script without first initializing it via `remote()`.fixIn standalone scripts (not run by `@wdio/cli`), you must explicitly create the browser instance: `const browser = await remote({ capabilities: { browserName: 'chrome' } })`. The global `browser` object is only injected by the WebdriverIO test runner.
Warnings
- breaking Deprecated Appium protocol commands were renamed for Appium 3 compatibility, potentially breaking existing mobile tests.
- breaking The global `multiremotebrowser` object was renamed to `multiRemoteBrowser` to adhere to camelCase naming conventions.
- gotcha WebdriverIO introduced fixes for TypeScript 7 compatibility, which might cause issues with older TypeScript versions.
- gotcha A bug fix restored `jiti` fallback for CommonJS (CJS) named imports, implying that CJS users might have experienced import issues around this version.
- gotcha Mobile command argument mismatches were fixed for Appium 3 compatibility, which could affect how arguments are passed to certain mobile automation commands.
Install
-
npm install webdriverio -
yarn add webdriverio -
pnpm add webdriverio
Imports
- remote
const { remote } = require('webdriverio')import { remote } from 'webdriverio' - Browser
import type { Browser } from 'webdriverio' - ChainablePromiseElement
import type { ChainablePromiseElement } from 'webdriverio'
Quickstart
import { remote } from 'webdriverio'
const browser = await remote({
capabilities: { browserName: 'chrome' }
})
await browser.navigateTo('https://www.google.com/ncr')
const searchInput = await browser.$('#lst-ib')
await searchInput.setValue('WebdriverIO')
const searchBtn = await browser.$('input[value="Google Search"]')
await searchBtn.click()
console.log(await browser.getTitle()) // outputs "WebdriverIO - Google Search"
await browser.deleteSession()