Playwright Custom Annotations

The playwright can add custom metadata in the form of annotations. There comes a time when we need to create a custom reporter with some extra information added. With playwright, this is possible by using custom annotations to our tests.

Key-value pairs are done via test.info().annotations.

Syntax:

test('Alert', async ({ page }) => {
 test.info().annotations.push({ type: 'issue', description: 'some issue description' });
 // ...
});

Example:

test.info().annotations.push({ type: 'issue', description: 'Check Alert Popup' })
await page.goto("http://autopract.com/selenium/alert2/#");
await page.locator("tbody tr:nth-child(2) td:nth-child(3) a:nth-child(1)").click()
await page.on('dialog',dialog => dialog.accept())
  • Let us consider this test where we are pushing some info as custom annotations onto our report.
  • Annotations have many methods which can also be utilized.
  • Now let us check our HTML report.
  • We can see that the custom information has successfully been pushed into the report.
Fri, 02/03/2023 - 10:04
Ashwin possesses over five years of experience in the Quality Assurance industry and is currently serving as a Technical Lead at iVagus. His expertise encompasses a broad range of technologies, including Cypress, Rest Assured, Selenium, Cucumber, JavaScript and TypeScript.
Tags

Comments