ESLint plugin for your Playwright testing needs.
Yarn
yarn add -D eslint-plugin-playwright
NPM
npm install -D eslint-plugin-playwright
This plugin bundles two configurations to work with both @playwright/test
or jest-playwright
.
{
"extends": ["plugin:playwright/playwright-test"]
}
With Jest Playwright
{
"extends": ["plugin:playwright/jest-playwright"]
}
Identify false positives when async Playwright APIs are not properly awaited.
Example of incorrect code for this rule:
expect(page).toMatchText("text");
test.step("clicks the button", async () => {
await page.click("button");
});
Example of correct code for this rule:
await expect(page).toMatchText("text");
await test.step("clicks the button", async () => {
await page.click("button");
});
The rule accepts a non-required option which can be used to specify custom matchers which this rule should also warn about. This is useful when creating your own async expect
matchers.
{
"playwright/missing-playwright-await": [
"error",
{ "customMatchers": ["toBeCustomThing"] }
]
}
Prevent usage of page.pause()
.
Example of incorrect code for this rule:
await page.click('button');
await page.pause();
Example of correct code for this rule:
await page.click('button');
Disallow the creation of element handles with page.$
or page.$$
.
Examples of incorrect code for this rule:
// Element Handle
const buttonHandle = await page.$('button');
await buttonHandle.click();
// Element Handles
const linkHandles = await page.$$('a');
Example of correct code for this rule:
const buttonLocator = page.locator('button');
await buttonLocator.click();