Browser/page commands should not be used inside tests directly including before/after hooks. Browser/page commands should be moved to page objects or to an other abstraction layer for better readibility and mainability of tests (usually less verbose).
Examples of incorrect code for this rule:
describe('test suite', () => {
it('should do something', () => {
browser.url('/'); // options: 'webdriverio'
});
});
describe('test suite', () => {
it('should do something', () => {
// options: 'puppeteer' / 'playwright'
const page = browser.newPage();
page.goto('/');
page.type('#element', 'something');
});
});
Examples of correct code for this rule:
describe('test suite', () => {
it('should be able to login', () => {
myPage.login();
});
});
describe('test suite', () => {
beforeAll(() => {
myPage.visit();
});
it('should do something', () => {
myPage.addItem();
});
});
The supported automation tools for this rule are: playwright
, puppeteer
and webdriverio
.
{
"ui-testing/no-browser-commands-in-tests": ["warn", "webdriverio"]
}