Browser instance is shared between all tests in the same worker - this makes testing efficient. However, each test runs in an isolated BrowserContext and gets a fresh environment.
Learn how to configure browser and see [available options]TestOptions.
Usage
test.beforeAll(async ({ browser }) => {
const page = await browser.newPage();
// ...
});
Generated using TypeDoc
Playwright Test is based on the concept of the test fixtures. Test fixtures are used to establish environment for each test, giving the test everything it needs and nothing else.
Playwright Test looks at each test declaration, analyses the set of fixtures the test needs and prepares those fixtures specifically for the test. Values prepared by the fixtures are merged into a single object that is available to the
test
, hooks, annotations and other fixtures as a first parameter.Given the test above, Playwright Test will set up the
page
fixture before running the test, and tear it down after the test has finished.page
fixture provides a Page object that is available to the test.Playwright Test comes with builtin fixtures listed below, and you can add your own fixtures as well. Playwright Test also [provides options]TestOptions to configure fixtures.browser, fixtures.context and fixtures.page.