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:
- Detect your POM pattern (class-based, fixture-based, or functional).
- Match naming conventions from existing Page Objects in your project.
- Use the correct locator strategy (data-testid, role-based, CSS selectors) based on what your team already uses.
// 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/testblocks with meaningful names. - Setup and teardown hooks where needed.
- Assertions using
expectwith appropriate matchers. - Data-driven variants via
test.eachwhen 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:
| Capability | What it checks |
|---|---|
| Anti-patterns | Flaky selectors, hard-coded waits, missing assertions |
| Performance | Redundant page navigations, unnecessary reloads |
| Maintainability | Magic strings, duplicated locators, missing abstractions |
| Accessibility | Prefer 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.
