Next-gen browser and mobile automation test framework for Node.js.
Refer to official documentation for detailed usage. →

Writing Tests#

Testing your application will require interacting with UI elements. Best practice for selecting elements in your tests is with special attributes for testing.

  • Add test attributes to elements of your UI.
import React from "react";
import { Button } from "@components";
export const Main: React.FC = () => {
return (
<h1 data-test="main-heading">superplate</h1>
<p>The frontend boilerplate with superpowers!</p>
<Button data-test="docs-btn-anchor">Docs</Button>
  • Now these elements can be selected in tests with $ or $$.
const heading = await $('[data-test="main-heading"]');
  • Don't forget to visit the page before each test.
describe("Homepage", () => {
beforeEach(async () => {
await browser.url("/");
it("Brings header", async () => {
const heading = await $('[data-test="main-heading"]');
expect(await heading.getText()).toBe("superplate");
it("Should have true href", async () => {
const button = await $('[data-test="docs-btn-anchor"]');
expect(await button.getTagName()).toBe("a");
const buttonHref = await button.getAttribute("href");
it("Should have icons", async () => {
const icons = await $$('[data-test="icon"]');

Refer to official documentation on selecting elemets for detailed usage. →

Running Tests#

  • Configure baseUrl option in wdio.conf.js.
exports.config = {
baseUrl: "http://localhost:3000",

If your url parameter starts with /, the base url gets prepended, not including the path portion of your baseUrl. If your url parameter starts without a scheme or / (like some/path), the base url gets prepended directly.

Refer to official documentation on configuration for detailed usage. →

  • Add a command to run tests.
scripts: {
"webdriver:run": "wdio wdio.conf.js"
  • Start your project in dev mode
npm run dev
  • Run tests with wdio
npm run webdriver:run

Refer to official documentation on command line for detailed usage. →

File structure#

WebdriverIO test directory is placed in the root of the project.

  • Add tsconfig.json for WebdriverIO
"compilerOptions": {
"types": ["node", "webdriverio", "@wdio/mocha-framework"]
"include": ["./specs/**/*.ts"]
  • Don't forget to exclude WebdriveIO from main tsconfig.json
"exclude": ["test/*"]

All this work will be handled automatically by CLI, so you don’t need to do anything extra as long as you choose WebdriverIO plugin during the project creation phase.

Adding WebdriverIO to your project later#

If you didn't choose the plugin during project creation phase, you can follow the instructions below to add it.

npm install -D @wdio/cli
  • Generate configuration file
npx wdio config -y

Refer to official documentation on installation for detailed usage. →

Last updated on by Necati Özmen