Skip to content

Latest commit

 

History

History
61 lines (46 loc) · 1.5 KB

no-browser-commands-in-tests.md

File metadata and controls

61 lines (46 loc) · 1.5 KB

Disallow browser/page commands in tests

playwright-badge puppeteer-badge webdriverio-badge

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).

Rule Details

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();
    });
});

Options

The supported automation tools for this rule are: playwright, puppeteer and webdriverio.

{
  "ui-testing/no-browser-commands-in-tests": ["warn", "webdriverio"]
}