Playwright Declares a Test Step

Profile picture for user arilio666

In playwright, we declare a test step using the 'test' function provided by the test runner.

const { test, expect } = require('@playwright/test');

test('My test', async ({ page }) => {
 await page.goto('https://www.programsbuzz.com');

});
  • In this example, we declare a test step using the test function, passing in a name for the test and an async function that takes a page object as a parameter. 
  • Within the test function, we navigate to a website and get the page title. Using the test function, you can add as many test steps as needed within a test file. 
  • Each test step should have a unique name and be written as an async function that takes a page object as a parameter. 
  • Within each test step, you can use any of the Playwright API functions to interact with the page and make assertions about the state of the page.

Arguments used:

title: string

Step name is used here.

body function([]):Promise<Object>

Step body.