generatePOM function ✓ 100.0%

Last updated: 2026-03-01T23:25:47.084Z

Metrics

LOC: 56 Complexity: 11 Params: 3 Coverage: 100.0% (17/17 lines, 2x executed)

Signature

generatePOM( actions: CapturedAction[], useSmartSelectors: boolean, ): : string

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'generatePOM' has cyclomatic complexity 11 (max 10)

Source Code

function generatePOM(
  actions: CapturedAction[],
  useSmartSelectors: boolean,
): string {
  const fieldLines = actions
    .filter((a) => a.actionType !== "click" && a.actionType !== "submit")
    .map((a) => {
      const sel = escapeString(resolveSelector(a, useSmartSelectors));
      const propName = toCamelCase(a.label ?? a.fieldType ?? "field");
      return `  get ${propName}() { return this.page.locator('${sel}'); }`;
    });

  const submitAction = actions.find(
    (a) => a.actionType === "click" || a.actionType === "submit",
  );
  const submitLine = submitAction
    ? `  get submitButton() { return this.page.locator('${escapeString(resolveSelector(submitAction, useSmartSelectors))}'); }`
    : "";

  const fillLines = actions
    .filter((a) => a.actionType === "fill")
    .map((a) => {
      const propName = toCamelCase(a.label ?? a.fieldType ?? "field");
      return `    await this.${propName}.fill(${propName}Value);`;
    });

  const fillParams = actions
    .filter((a) => a.actionType === "fill")
    .map((a) => {
      const propName = toCamelCase(a.label ?? a.fieldType ?? "field");
      return `${propName}Value: string`;
    })
    .join(", ");

  return [
    `import type { Page } from '@playwright/test';`,
    ``,
    `export class FormPage {`,
    `  constructor(private readonly page: Page) {}`,
    ``,
    ...fieldLines,
    submitLine,
    ``,
    `  async fillForm(${fillParams}) {`,
    ...fillLines,
    `  }`,
    ``,
    submitAction
      ? `  async submit() {\n    await this.submitButton.click();\n  }`
      : "",
    `}`,
    ``,
  ]
    .filter(Boolean)
    .join("\n");
}

Dependencies (Outgoing)

graph LR generatePOM["generatePOM"] escapeString["escapeString"] resolveSelector["resolveSelector"] toCamelCase["toCamelCase"] generatePOM -->|calls| escapeString generatePOM -->|calls| resolveSelector generatePOM -->|calls| toCamelCase style generatePOM fill:#dbeafe,stroke:#2563eb,stroke-width:2px click generatePOM "7423c874e7c3dfa3.html" click escapeString "5c2f25e3b4548c2d.html" click resolveSelector "361a4021ea67e76c.html" click toCamelCase "d9182ff869942bb8.html"
TargetType
escapeString calls
resolveSelector calls
toCamelCase calls

Impact (Incoming)

graph LR generatePOM["generatePOM"] generate["generate"] generate -->|calls| generatePOM style generatePOM fill:#dbeafe,stroke:#2563eb,stroke-width:2px click generatePOM "7423c874e7c3dfa3.html" click generate "a1352a91ca2859ed.html"
SourceType
generate calls