Generate Test Cases and Playwright Scaffold from Figma
Reads a Figma design's structured description (frames, interactions, prototype links, states) and returns user-flow test cases plus a Playwright spec scaffold with `data-testid` suggestions matched to design layer names. Flags missing interaction states.
When to use it
- Pre-implementation: write tests before the feature is built (TDD-ish for UI).
- Validating that a design has thought through all interaction states (hover, disabled, error).
- Onboarding test plans for a new feature based on design artifacts.
- Generating data-testid naming conventions that align with design layer names.
The prompt
<role>You are a test designer who works upstream: from design artifacts, not from implemented code. You produce test scaffolds that surface design gaps (missing states, ambiguous interactions) and provide a starting structure for implementation testing.</role> <context>A Figma design describes:- Frames (screens / states)- Interactions (click, hover, etc.)- Prototype links between frames- Component variants (default, hover, disabled, error, loading)- Layer naming (often hierarchical: `Login / Inputs / Email`) Test generation from Figma works best when the design is structured. AI cannot infer business logic from visuals: it CAN identify which states a design covers and which it skips.</context> <task>For the Figma description below:1. Identify user flows (sequences of frames connected via prototype interactions).2. For each flow, generate 3-6 test cases covering: happy path, primary error path, edge cases visible in design.3. Generate Playwright spec scaffold with locators based on layer names (e.g., layer `Login / Submit Button` → suggested testid `login-submit-button`).4. Flag MISSING states the design doesn't show (hover, disabled, error, loading, empty) that tests SHOULD cover.5. Generate a testid naming convention summary derived from observed layer-name patterns.</task> <input>Figma description (frames, interactions, layer names): {figma}Design intent (what the feature is for): {intent}Component states present in design: {states}</input> <constraints>- Test cases at the USER FLOW level (happy path, error, edge), not at the frame level.- testid suggestions MUST be derived from layer names, not invented.- Missing-state warnings MUST be specific (e.g., "no disabled state for Submit button shown: add a test for disabled state behavior").- Spec scaffold uses Playwright + TypeScript.- Acknowledge what the design CAN'T tell you (validation rules, business logic, exact error messages).</constraints> <output_format>Four sections:1. **User flows identified**: list with frame sequences2. **Test cases per flow**: table per flow: Test | Steps | Expected behavior3. **Playwright spec scaffold**: code block with comments where ambiguity exists4. **Missing states / ambiguities**: bullets on what the design doesn't show but tests should cover5. **Testid naming convention**: derived from layer naming patterns</output_format> <approach>Before writing, identify which design states are present vs missing; that's the most valuable output.</approach>## RoleTest designer working upstream from design. Surface gaps in design before implementation. ## ContextFigma describes: frames, interactions, prototype links, component variants (default, hover, disabled, error, loading), layer naming. AI can't infer business logic from visuals. Can identify covered vs skipped states. ## TaskFor Figma description:1. Identify user flows (frame sequences).2. 3-6 test cases per flow (happy path, error, edge).3. Playwright spec scaffold with testids from layer names.4. Flag MISSING states (hover, disabled, error, loading, empty).5. Testid naming convention derived from layer patterns. ## Input- Figma description: {figma}- Design intent: {intent}- Component states present: {states} ## Constraints- Test cases at USER FLOW level, not frame level.- testid suggestions derived from layer names, not invented.- Missing-state warnings SPECIFIC.- Playwright + TypeScript scaffold.- Acknowledge what design CAN'T tell you. ## Output format5 sections: User flows | Test cases per flow | Spec scaffold | Missing states/ambiguities | Testid naming convention. ## ApproachIdentify covered vs missing states first.Example
Input
Figma description: - Frame "Cart": shows items, subtotal, "Apply discount" button, "Checkout" button - Frame "Discount input": slide-in panel with input field, "Apply" button, "Cancel" button - Frame "Discount applied": Cart with green badge showing discount, updated subtotal - Frame "Checkout payment": payment form Interactions: - Click "Apply discount" → Cart → Discount input - Click "Apply" in Discount input with code "SAVE20" → Discount applied (animated subtotal update) - Click "Cancel" → back to Cart (no state change) - Click "Checkout" → Checkout payment Layer naming (sample): - Cart / Header / Title - Cart / Items / Item 1 / Name - Cart / Items / Item 1 / Price - Cart / Footer / Subtotal - Cart / Footer / Apply Discount Button - Cart / Footer / Checkout Button - Discount Input / Modal / Code Field - Discount Input / Modal / Apply Button - Discount Input / Modal / Cancel Button - Discount Applied / Discount Badge - Discount Applied / New Subtotal Design intent: Allow users to apply a promo code at the cart stage before checkout. Component states present in design: default, applied
Output
## 1. User flows identified
- **Flow A: Apply discount successfully**, Cart → Discount Input → Discount Applied
- **Flow B: Cancel discount entry**, Cart → Discount Input → back to Cart (no change)
- **Flow C: Proceed to checkout**, Cart (with or without discount) → Checkout payment
## 2. Test cases per flow
### Flow A: Apply discount successfully
| Test | Steps | Expected behavior |
|------|-------|-------------------|
| Apply a valid discount code | 1. Open cart with items 2. Click "Apply discount" 3. Enter "SAVE20" 4. Click Apply | Cart shows discount badge; subtotal decreases by discount amount |
| Apply discount with empty input | 1. Click Apply with empty input | UI shows error (NOT in design: see Missing states) |
| Apply discount with whitespace-only code | 1. Enter " "; click Apply | UI rejects (see Missing states) |
### Flow B: Cancel discount entry
| Test | Steps | Expected behavior |
|------|-------|-------------------|
| Cancel discount input | 1. Open cart 2. Click "Apply discount" 3. Enter "SAVE20" 4. Click Cancel | Discount input closes; cart returns to original state; entered code NOT applied |
| Close discount input via X (if present) | (not in design) | (see Missing states) |
| Click outside the panel to dismiss | (not in design) | (see Missing states) |
### Flow C: Proceed to checkout
| Test | Steps | Expected behavior |
|------|-------|-------------------|
| Checkout without discount | 1. Open cart with items 2. Click Checkout | Navigation to /checkout/payment |
| Checkout with applied discount | 1. Apply SAVE20 2. Click Checkout | Navigation to /checkout/payment; discount preserved in checkout state |
## 3. Playwright spec scaffold
```typescript
import { test, expect } from '@playwright/test';
// Test ids are PROPOSED from the Figma layer names (see section 5): add them to the app first.
// Routes (/cart, /checkout/payment) are not in the design: TODO confirm with engineering.
test.describe('Cart: Apply discount flow', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/cart');
await expect(page.getByTestId('cart-header-title')).toBeVisible();
});
test('apply valid discount updates subtotal', async ({ page }) => {
// Capture original subtotal for diff
const originalSubtotal = await page.getByTestId('cart-footer-subtotal').textContent();
await page.getByTestId('cart-footer-apply-discount-button').click();
await expect(page.getByTestId('discount-input-modal-code-field')).toBeVisible();
await page.getByTestId('discount-input-modal-code-field').fill('SAVE20');
await page.getByTestId('discount-input-modal-apply-button').click();
// Discount applied state
await expect(page.getByTestId('discount-applied-discount-badge')).toBeVisible();
const newSubtotal = await page.getByTestId('discount-applied-new-subtotal').textContent();
expect(newSubtotal).not.toBe(originalSubtotal); // TODO: replace with exact expected amount
});
test('cancel discount input returns to cart unchanged', async ({ page }) => {
const originalSubtotal = await page.getByTestId('cart-footer-subtotal').textContent();
await page.getByTestId('cart-footer-apply-discount-button').click();
await page.getByTestId('discount-input-modal-code-field').fill('SAVE20');
await page.getByTestId('discount-input-modal-cancel-button').click();
await expect(page.getByTestId('discount-input-modal-code-field')).toBeHidden();
expect(await page.getByTestId('cart-footer-subtotal').textContent()).toBe(originalSubtotal);
});
test('proceed to checkout from cart with discount', async ({ page }) => {
await page.getByTestId('cart-footer-apply-discount-button').click();
await page.getByTestId('discount-input-modal-code-field').fill('SAVE20');
await page.getByTestId('discount-input-modal-apply-button').click();
await expect(page.getByTestId('discount-applied-discount-badge')).toBeVisible();
await page.getByTestId('cart-footer-checkout-button').click();
await expect(page).toHaveURL(/\/checkout\/payment/);
});
});
```
## 4. Missing states / ambiguities
The design covers default and applied states. The following are NOT shown in design but should be tested:
- **Disabled state**: Should "Apply discount" button be disabled when cart is empty? Design doesn't show.
- **Loading state**: When discount is being validated server-side, is there a spinner? Design doesn't show.
- **Error state**: What happens when discount code is invalid, expired, or already used? Design doesn't show error UI.
- **Multiple discounts**: Can a user apply a second discount on top of the first? Design implies no, but no constraint enforcement is shown.
- **Discount already applied**: When a discount is already applied, what does the "Apply discount" button show? Default? Hidden?
- **Long discount codes**: Input field max length not visible.
- **Validation feedback**: Real-time validation as user types? Design shows static state only.
- **Mobile responsive**: Modal behavior on small screens, full-screen modal vs slide-in?
The design CAN'T tell us:
- Expected discount amount for SAVE20 (business logic)
- Validation rules (code format, expiration, eligibility)
- Server-side error messages text
- How discount integrates with cart totals (round-down, round-up, multi-currency)
These need to be clarified with PM / engineering before testing.
## 5. Testid naming convention
Pattern observed: `<area>-<section>-<element>` (derived from layer hierarchy with hyphens):
- `cart-header-title`
- `cart-items-item-1-name` (sequential items get index)
- `cart-footer-subtotal`
- `discount-input-modal-code-field`
- `discount-applied-discount-badge`
Recommend documenting this naming convention in your component library so designers and engineers stay aligned. When adding new components, generate the testid from the layer name following this pattern.Common pitfalls
- Model hallucinates UI elements not in the Figma description: surface only what's explicitly described.
- Missing-states section gets glossed over; that's the most valuable insight. Demand specifics.
- Testid suggestions don't match real layer naming patterns; they get invented. Force derivation from input.
- Tests rely on business-logic assumptions (e.g., 'SAVE20 = 20% off') without flagging that the design didn't communicate the rule.
Tips
- Use Figma's Dev Mode to export the structured description before prompting: manual description loses nuance.
- Pair with `generate-test-cases-from-requirements` for tests that need business-logic understanding.
- Run BEFORE engineering builds the feature: the design-gap warnings often save expensive late-cycle rework.
- Have a designer review the missing-states section; they often have answers that didn't make it into the Figma.
FAQ
Can this use Figma's API directly?
In 2026, yes: Figma has a structured API + Dev Mode that exports layer trees and prototypes as JSON. Feed that JSON directly to the prompt. Quality dramatically improves vs manually described designs.
What can't the design tell me?
Business logic (validation rules, calculation rules, error messages text), backend behavior (API endpoints, timing), and customer-specific UX assumptions. Always pair design-derived tests with conversations with PM and engineering.
When NOT to use this prompt?
When the design is too high-fidelity to be a test source: sometimes a wireframe in Figma is just a sketch, not a contract. Distinguish between 'representative' designs and 'pixel-perfect spec' designs; only the latter is a reliable test source.
How testids should evolve when design changes?
Document the testid generation rule in your design system so it's stable. When a layer is renamed, the testid changes too: handle this by either keeping the original testid OR doing a coordinated rename across design and code.