Our AI-generated test is designed to set up its own state and tear down after itself. This ensures that it is not dependent or affected by the state of previous test runs.

e.g., this is an example generated test that includes additional setup and tear down steps:

import { test, expect } from '@playwright/test';

test.beforeEach(async ({ page }) => {
  // Setup - create an account
  await page.goto('https://example.com');
  await page.click("text=Create an account");
  await page.fill('input[name="username"]', "testuser");
  await page.fill('input[name="password"]', "password");
  await page.click('button[type="submit"]');
});

test.afterEach(async ({ page }) => {
  // Tear down - delete the account
  await page.goto('https://example.com');
  await page.click("text=Delete account");
  await page.click('button[type="submit"]');
});

test('Sign in with email', async ({ page }) => {
  // Setup
  await page.goto('https://example.com');
  await page.click('text=Sign in');
  await page.fill('input[name="username"]', '[email protected]',
  await page.fill('input[name="password"]', 'testpwd');
  await page.click('button[type="submit"]');
});
Currently, we only support setup/tear down with Playwright actions. We are working on adding support for API-based setup/tear down.

Was this page helpful?