Skip to content

Code Generation

The AI Assistant generates code that matches your project's existing style, patterns, and conventions. It can scaffold Page Objects, write test cases, create fixtures, and suggest refactoring — all aware of your actual codebase.

Page Object Generation

Ask the assistant to generate a Page Object Model class and it will:

  1. Detect your POM pattern (class-based, fixture-based, or functional).
  2. Match naming conventions from existing Page Objects in your project.
  3. Use the correct locator strategy (data-testid, role-based, CSS selectors) based on what your team already uses.
typescript
// Example: generated POM matching project style
import { type Page, type Locator } from '@playwright/test';

export class CheckoutPage {
  readonly page: Page;
  readonly cartSummary: Locator;
  readonly promoCodeInput: Locator;
  readonly placeOrderButton: Locator;

  constructor(page: Page) {
    this.page = page;
    this.cartSummary = page.getByTestId('cart-summary');
    this.promoCodeInput = page.getByLabel('Promo code');
    this.placeOrderButton = page.getByRole('button', { name: 'Place order' });
  }

  async applyPromoCode(code: string) {
    await this.promoCodeInput.fill(code);
    await this.page.getByRole('button', { name: 'Apply' }).click();
  }
}

TIP

The assistant reads your existing pages/ or pom/ directory to learn your patterns. The more Page Objects you already have, the more consistent the generated output.

Test Case Generation

Describe a scenario in natural language and the assistant produces a complete spec file:

  • Proper test.describe / test blocks with meaningful names.
  • Setup and teardown hooks where needed.
  • Assertions using expect with appropriate matchers.
  • Data-driven variants via test.each when multiple inputs are implied.

Fixture Creation

The assistant generates Playwright fixtures that integrate with your existing test.extend setup. It detects shared state patterns and avoids duplicating fixtures you already have.

Code Review & Refactoring

Paste code or reference a file path and ask for a review. The assistant will:

CapabilityWhat it checks
Anti-patternsFlaky selectors, hard-coded waits, missing assertions
PerformanceRedundant page navigations, unnecessary reloads
MaintainabilityMagic strings, duplicated locators, missing abstractions
AccessibilityPrefer role/label selectors over CSS where possible

Applying Generated Code

Every code block in the assistant's response includes an Apply button. Clicking it opens a diff view showing exactly what will change in the target file. You review and confirm before any file is modified.

WARNING

Generated code is a starting point. Always review the diff before applying, especially for test logic that asserts business-critical behavior.

Local-first QA orchestration.