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 3.8.3.
tsconfig.json needs the following:
- Sync Mode
- Async Mode
Please avoid importing
WebDriver types are accessible from anywhere once added to
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.