You can write tests using TypeScript to get autocompletion and type safety.
You will need
ts-node installed as
devDependencies. WebdriverIO will automatically detect if these dependencies are installed and will compile your config and tests for you. If you need to configure how ts-node runs please use the environment variables for ts-node or use wdio config's autoCompileOpts section.
The minimum TypeScript version is
You can provide custom
tsconfig-paths options through your
tsconfig.json needs the following:
- Sync Mode
- Async Mode
Please avoid importing
WebDriver types are accessible from anywhere once added to
tsconfig.json. If you use additional WebdriverIO services, plugins or the
devtools automation package, please also add them to the
types list as many provide additional typings.
Depending on the framework you use, you will need to add the types for that framework to your
tsconfig.json types property, as well as install its type definitions. This is especially important if you want to have type support for the built-in assertion library
For instance, if you decide to use the Mocha framework, you need to install
@types/mocha and add it like this to have all types globally available:
If you use services that add commands to the browser scope you also need to include these into your
tsconfig.json. For example if you use the
@wdio/devtools-service ensure that you add it to the
types as well, e.g.:
Adding services and reporters to your TypeScript config also strengthen the type safety of your WebdriverIO config file.
With TypeScript, it's easy to extend WebdriverIO interfaces. Add types to your custom commands like this:
- Create a type definition file (e.g.,
- Make sure to include path in the
- Add definitions for your commands according to your execution mode.