ESLint rules for UI testing tools WebdriverIO, Cypress, TestCafe, Playwright, Puppeteer
npm install eslint-plugin-ui-testing
ESLint plugin that helps following best practices when writing UI tests. It supports the following automation tools (in alphabetical order):
- Cypress
- Playwright
- Puppeteer
- TestCafe
- WebdriverIO
Prerequisite:
- ESLint is installed (npm i eslint --save-dev)
1. Install eslint-plugin-ui-testing:
```
npm i eslint-plugin-ui-testing --save-dev
2. Add the ui-testing plugin to the .eslintrc configuration file.
`json`
{
"plugins": ["ui-testing"]
}
3. Configure the rules as follows by using the recommended ruleset per automation tool. Choose one from:
- plugin:ui-testing/cypressplugin:ui-testing/playwright
- plugin:ui-testing/puppeteer
- plugin:ui-testing/testcafe
- plugin:ui-testing/webdriverio
-
Example:
`json`
{
"extends": ["plugin:ui-testing/webdriverio"]
}
You can customize specific rules in the .eslintrc configuration file.
``
{
"rules": {
"ui-testing/no-disabled-tests": "error", // default = warn
"ui-testing/no-css-page-layout-selector": ["warn", "webdriverio"] // default = error
}
}
- In case you are using a recommended ruleset as described in step 3 (under Usage), then these customized rules will override the default.
- It is also possible to omit the recommended ruleset and just set each rule specifically as above.
| Rule | Default | Ruleset |
| ---------------------------------------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------- |
| missing-assertion-in-test | error | ![recommended-badge][] |warn
| no-absolute-url | | ![cypress-badge][] ![webdriverio-badge][] |error
| no-assertions-in-hooks | | ![recommended-badge][] |warn
| no-browser-commands-in-tests | | ![playwright-badge][] ![puppeteer-badge][] ![webdriverio-badge][] |error
| no-css-page-layout-selector | | ![cypress-badge][] ![playwright-badge][] ![puppeteer-badge][] ![testcafe-badge][] ![webdriverio-badge][] |warn
| no-disabled-tests | | ![recommended-badge][] |warn
| no-focused-tests | | ![recommended-badge][] |error
| no-hard-wait | | ![cypress-badge][] ![playwright-badge][] ![puppeteer-badge][] ![testcafe-badge][] ![webdriverio-badge][] |error
| no-implicit-wait | | ![webdriverio-badge][] |error
| no-link-text-selector | | ![webdriverio-badge][] |error
| no-tag-name-selector | | ![webdriverio-badge][] |warn
| no-wait-in-tests | | ![playwright-badge][] ![puppeteer-badge][] ![testcafe-badge][] ![webdriverio-badge][] |error
| no-xpath-page-layout-selector | | ![webdriverio-badge][] |warn` | ![webdriverio-badge][] |
| no-xpath-selector |
Note: All automation tool specific rulesets include the recommended ruleset.
[recommended-badge]: https://img.shields.io/badge/recommended-brightgreen
[cypress-badge]: https://img.shields.io/badge/cypress-black
[playwright-badge]: https://img.shields.io/badge/playwright-blue
[puppeteer-badge]: https://img.shields.io/badge/puppeteer-3eb489
[testcafe-badge]: https://img.shields.io/badge/testcafe-a4cada
[webdriverio-badge]: https://img.shields.io/badge/webdriverio-orange