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
- [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)
| Target | Type |
|---|---|
| escapeString | calls |
| resolveSelector | calls |
| toCamelCase | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| generate | calls |