/** * yaml-generator.ts * * Converts test metadata (intent steps, element contexts, compact steps) * into a portable YAML test definition that can be re-executed by the * pwpilot_run_yaml MCP tool without the Playwright script. * * YAML schema: * version / name / description / url / source / generatedAt * config: timeouts, headless, continueOnFailure * steps[]: action, locator (primary + fallbacks), value, waitFor, assertion, screenshot * artifacts: paths to POM, spec, yaml, intent JSON * * The generator prefers rich CompactStep data (with assertion hints and element keys) * when available, and falls back to parsing plain intentSteps strings when not. * * For each element, it derives: * - A primary YamlLocator using the best available attribute (role+label, label, * placeholder, testId, text, or the original locator expression). * - An ordered list of fallback YamlLocators for self-healing. * * A singleton yamlGenerator instance is exported for use across all MCP tools. * * Role in the overall flow: * save_test → yamlGenerator.generate() → TestYaml → toYamlString() → .yaml file on disk * run_yaml → YamlExecutor reads the .yaml file and executes it */ import { ElementContext, CompactStep, TestYaml } from '../types'; /** All the input data needed to generate a TestYaml object. */ export interface YamlGeneratorInput { /** Human-readable test name. */ name: string; /** What this test verifies (user prompt). */ description: string; /** The URL under test. */ url: string; /** Where this test was generated from. */ source: 'live-browser' | 'video' | 'steps'; /** Natural-language step descriptions from the TestIntent. */ intentSteps: string[]; /** Rich step data from AssertionGenerationSkill (preferred over intentSteps when present). */ compactSteps?: CompactStep[]; /** Element context objects for locator derivation. */ elementContexts: ElementContext[]; /** Absolute path to the POM file. */ pomPath: string; /** Absolute path to the spec file. */ specPath: string; /** Absolute path where this YAML file will be written. */ yamlPath: string; /** Absolute path to the intent JSON file. */ intentPath: string; } /** * Converts test metadata into a portable, executable YAML test definition. */ export declare class YamlGenerator { /** * Build a TestYaml object from test metadata. * * Uses compactSteps if available (richer, with assertion hints); * falls back to intentSteps (plain text) otherwise. * * @param input - All the data needed to produce the YAML test definition. * @returns A fully populated TestYaml object ready to serialize. */ generate(input: YamlGeneratorInput): TestYaml; /** * Serialize a TestYaml object to a YAML-formatted string. * * @param test - The TestYaml to serialize. * @returns A YAML string with 2-space indentation and 120-character line width. */ toYamlString(test: TestYaml): string; /** * Build a YamlStep[] from rich CompactStep[] data + ElementContext lookup. * * Always prepends a navigate step to the base URL. * For each compact step, resolves the element context (if any) and builds * a primary locator + fallbacks. Assertions from the compact step are * converted to YamlAssertion objects — the first becomes an inline assertion * and the rest become separate assert steps. * * @param compactSteps - Ordered compact steps from AssertionGenerationSkill. * @param elementContexts - All element contexts from PlaywrightGenerationSkill. * @param baseUrl - The URL to navigate to in step 0. * @returns An ordered array of YamlStep objects. */ private stepsFromCompact; /** * Fallback step builder: parse plain-text intentSteps into YamlStep[] using * heuristic action detection and keyword-based element context matching. * * @param intentSteps - Natural-language step strings. * @param elementContexts - Element contexts for keyword-based matching. * @param baseUrl - The URL to navigate to in step 0. * @returns An ordered array of YamlStep objects. */ private stepsFromIntent; /** * Derive the primary YamlLocator for an element context using the best * available attribute (role+label > role+text > label > placeholder > testId > text > CSS). * * @param ec - The element context. * @returns A YamlLocator using the most stable available strategy. */ private primaryLocator; /** * Build an ordered list of fallback YamlLocators from an element context. * The primary locator is excluded from the fallback list to avoid duplication. * * @param ec - The element context. * @returns An array of fallback YamlLocators in priority order. */ private fallbackLocators; /** * Parse a Playwright locator expression string (e.g. "page.getByRole('button', { name: 'X' })") * into a YamlLocator object. Falls back to a CSS locator if no known pattern matches. * * @param expr - A Playwright locator expression string. * @returns A YamlLocator. */ private locatorFromExpression; /** * Convert an assertion expression string into a YamlAssertion object. * Detects the assertion type from keywords in the string. * * @param assertionText - An expect() expression string (e.g. "expect(el).toBeVisible()"). * @param ec - Optional element context for the associated locator. * @returns A YamlAssertion with the inferred type and locator. */ private buildAssertion; /** * Convert a plain-text assertion description into a YamlAssertion. * Tries to extract a quoted expected value; otherwise falls back to buildAssertion(). * * @param text - The assertion description text. * @param ec - Optional element context. * @returns A YamlAssertion. */ private assertionFromText; /** * Create a navigate YamlStep to the given URL. * * @param index - Step index. * @param url - URL to navigate to. * @returns A YamlStep with action="navigate" and waitFor="networkidle". */ private navigateStep; /** * Infer the YamlStep action type from a step description string and optional * element actionType. * * @param desc - The step description. * @param actionType - Optional pre-computed actionType from an ElementContext. * @returns The inferred YamlStep action. */ private inferAction; /** * Infer a sensible placeholder fill value from a step description. * Returns a quoted value from the description if one is present, * or a context-appropriate default (email, password, search term). * * @param desc - The step description. * @returns A fill value string. */ private inferFillValue; /** * Extract the first quoted string value from a text. * * @param text - The string to search. * @returns The content of the first quoted region, or empty string if none. */ private extractQuoted; /** * Find the ElementContext whose key, label, placeholder, text, or testId best * matches the words in the given step description. * * @param desc - The step description to match. * @param elementContexts - All available element contexts. * @returns The best-matching ElementContext, or undefined if none matched. */ private matchElementByDescription; } /** Singleton yaml generator instance for use across all MCP tools. */ export declare const yamlGenerator: YamlGenerator; //# sourceMappingURL=yaml-generator.d.ts.map