generate function ✓ 100.0%
Last updated: 2026-03-01T23:25:47.084Z
Metrics
LOC: 63
Complexity: 13
Params: 3
Coverage: 100.0% (29/29 lines, 24x executed)
Signature
generate(
actions: CapturedAction[],
options?: E2EGenerateOptions,
): : string
Architecture violations
- [warning] max-cyclomatic-complexity: 'generate' has cyclomatic complexity 13 (max 10)
Source Code
function generate(
actions: CapturedAction[],
options?: E2EGenerateOptions,
): string {
const opts = options ?? {};
const testName = opts.testName ?? "fill form";
const useSmartSelectors = opts.useSmartSelectors !== false;
const urlLine = opts.pageUrl
? ` await page.goto('${escapeString(opts.pageUrl)}');\n\n`
: "";
const fillActions = actions.filter(
(a) => a.actionType !== "click" && a.actionType !== "submit",
);
const submitActions = actions.filter(
(a) => a.actionType === "click" || a.actionType === "submit",
);
const fillLines = fillActions.map((a) => actionLine(a, useSmartSelectors));
const submitLines = submitActions.map((a) =>
actionLine(a, useSmartSelectors),
);
const assertionLines =
opts.includeAssertions && opts.assertions?.length
? ["\n // Assertions", ...opts.assertions.map(assertionLine)]
: [];
const parts = [
`import { test, expect } from '@playwright/test';`,
``,
`test('${escapeString(testName)}', async ({ page }) => {`,
urlLine + fillLines.join("\n"),
];
if (submitLines.length > 0) {
parts.push("");
parts.push(" // Submit");
parts.push(submitLines.join("\n"));
}
if (assertionLines.length > 0) {
parts.push(assertionLines.join("\n"));
}
parts.push(`});`);
// Negative test
if (opts.includeNegativeTest) {
const negativeTest = generateNegativeTest(actions, opts, useSmartSelectors);
if (negativeTest) parts.push(negativeTest);
}
// POM
if (opts.includePOM) {
parts.push("");
parts.push("// --- Page Object Model ---");
parts.push(generatePOM(actions, useSmartSelectors));
}
parts.push("");
return parts.join("\n");
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| escapeString | calls |
| actionLine | calls |
| generateNegativeTest | calls |
| generatePOM | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| generateWithTensorFlow | uses |
| OrchestratorCallbacks | uses |
| handleRuleButtonClick | uses |
| setNativeValue | uses |
| generateDateForField | uses |
| makeField | uses |