Skip to content

Commit 2238952

Browse files
Normalize waitForLoadState targets case-insensitively
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent a5ad40b commit 2238952

4 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎src/agent/shared/action-cache-script.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const normalizeWaitMs = (value: unknown): number => {
3939
};
4040

4141
const normalizeWaitUntil = (value: unknown): "domcontentloaded" | "load" | "networkidle" => {
42-
const parsed = asNonEmptyTrimmedString(value);
42+
const parsed = asNonEmptyTrimmedString(value)?.toLowerCase();
4343
if (parsed === "load" || parsed === "networkidle") {
4444
return parsed;
4545
}

‎src/agent/shared/action-cache.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,27 @@ describe("action cache helpers", () => {
235235
expect(script).not.toContain('await page.waitForLoadState("interactive");');
236236
});
237237

238+
it("normalizes waitForLoadState target casing in generated script", () => {
239+
const waitEntry: ActionCacheEntry = {
240+
stepIndex: 17,
241+
instruction: "wait uppercase target",
242+
elementId: null,
243+
method: null,
244+
arguments: ["LOAD"],
245+
actionType: "waitForLoadState",
246+
success: true,
247+
message: "ok",
248+
frameIndex: null,
249+
xpath: null,
250+
};
251+
252+
const script = createScriptFromActionCache({
253+
steps: [waitEntry],
254+
});
255+
256+
expect(script).toContain('await page.waitForLoadState("load");');
257+
});
258+
238259
it("renders waitForLoadState timeout from actionParams fallback", () => {
239260
const waitEntry: ActionCacheEntry = {
240261
stepIndex: 15,

‎src/agent/shared/replay-special-actions.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,21 @@ describe("executeReplaySpecialAction", () => {
178178
expect(result?.output).toBe("Waited for load state: domcontentloaded");
179179
});
180180

181+
it("normalizes waitForLoadState value case-insensitively", async () => {
182+
const page = createPage();
183+
184+
const result = await executeReplaySpecialAction({
185+
taskId: "task-loadstate-uppercase",
186+
actionType: "waitForLoadState",
187+
arguments: ["LOAD"],
188+
page: page as unknown as Page,
189+
});
190+
191+
expect(page.waitForLoadState).toHaveBeenCalledWith("load", undefined);
192+
expect(result?.status).toBe("completed");
193+
expect(result?.output).toBe("Waited for load state: load");
194+
});
195+
181196
it("parses string timeout for waitForLoadState", async () => {
182197
const page = createPage();
183198

‎src/agent/shared/replay-special-actions.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function normalizeOptionalTimeoutMs(value: unknown): number | undefined {
7373
}
7474

7575
function normalizeWaitUntil(value: unknown): "domcontentloaded" | "load" | "networkidle" {
76-
const parsed = asNonEmptyTrimmedString(value);
76+
const parsed = asNonEmptyTrimmedString(value)?.toLowerCase();
7777
if (parsed === "load" || parsed === "networkidle") {
7878
return parsed;
7979
}

0 commit comments

Comments
 (0)