Playwright
Automated Web Testing and Monitoring with Playwright
Install Playwright using yarn, npm, or via VS Code as shown below :
Using yarn:
yarn create playwright
Using npm:
npm init playwright@latest
Using VS Code:
Install the extension called 'Playwright Test for VSCode'.
Open the Command Palette and type 'Install Playwright' as shown in the reference below.

You will be asked to choose the browsers you would like to run your tests on. Type the following command in the terminal to open Playwright Inspector and Chromium (or, another web driver).
npx playwright codegen
Type the URL of the application you would like to test in the browser and click ‘Record’ on the Playwright Inspector.

Go back to the application and perform a few actions to create scripts.
Copy the code and paste it to the file created under the extension '.spec.ts'.
Type the following command in the terminal to run the code:
To run all tests,
npx playwright test
To run a specific test (say, sample.spec.ts),
npx playwright test sample.spec.ts
To run a specific test (say, sample.spec.ts) in chromium,
npx playwright test sample.spec.ts --project=chromium
To view the HTML report of the test result,
npx playwright show-report
7. Integrate with PerfAgents
To take screenshots, add this line of code:
await page.screenshot({ path: process.env.BASE_PATH + '/<screenshot name>.png' });
Screen recording is by default turned on for all tests in Playwright
To include multiple tests inside a single file, create each test as different Playwright "test" functions
import { test, expect } from '@playwright/test';
//Test 1
test('test_1', async ({ page }) => {
// Add your test script here
});
//Test 2
test('test_2', async ({ page }) => {
// Add your test script here
});
Sequence monitoring now supports access to custom variables inside of test files as environmental variables
To use custom variables inside JavaScript or typescript fie
const userName = process.env.USER_NAME
Last updated