Skip to content

Commit

Permalink
Fix intermittent issues in the issue14307.pdf integration tests
Browse files Browse the repository at this point in the history
The `must check input for US zip format` integration test fails pretty
consistently in Puppeteer 23.4.0+ with `Expected '12341' to equal
'12345'`. This is reproducible with the `pdf.sandbox.external.js` hack
from mozilla#18396 (comment).
Investigation uncovered two issues at play here:

1. We do two `clearInput` calls, but don't await processing of the two
   sandbox events that are triggered by that action. The three tests that
   use `issue14307.pdf` are in different `describe` blocks and therefore
   reload the PDF file, so we can simply remove those calls because the
   inputs are already empty by default.

2. We don't await processing of the sandbox events that occur after
   switching to another text field. This causes the expectation failure
   because the typing actions will happen too soon and interfere with
   the sandbox event processing. We solve the issue by explicitly
   awaiting the sandbox roundtrip.

Moreover, similar to PR mozilla#19001 and mozilla#18399 we remove any remaining room
for intermittent issues by directly checking for the expected value,
which also results in shorter code.
  • Loading branch information
timvandermeij committed Dec 7, 2024
1 parent 3f1d07a commit e740809
Showing 1 changed file with 24 additions and 56 deletions.
80 changes: 24 additions & 56 deletions test/integration/scripting_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,38 +1060,26 @@ describe("Interaction", () => {
it("must check input for US zip format", async () => {
// Run the tests sequentially to avoid any focus issues between the two
// browsers when an alert is displayed.
for (const [browserName, page] of pages) {
for (const [, page] of pages) {
await waitForScripting(page);

await clearInput(page, getSelector("29R"));
await clearInput(page, getSelector("30R"));

await page.focus(getSelector("29R"));
await typeAndWaitForSandbox(page, getSelector("29R"), "12A");
await page.waitForFunction(
`${getQuerySelector("29R")}.value !== "12A"`
);

let text = await page.$eval(getSelector(`29R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("12");
await page.waitForFunction(`${getQuerySelector("29R")}.value === "12"`);

await page.focus(getSelector("29R"));
await typeAndWaitForSandbox(page, getSelector("29R"), "34");
await page.click("[data-annotation-id='30R']");

await page.waitForFunction(
`${getQuerySelector("29R")}.value !== "1234"`
);

text = await page.$eval(getSelector(`29R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("");
await waitForSandboxTrip(page);
await page.waitForFunction(`${getQuerySelector("29R")}.value === ""`);

await page.focus(getSelector("29R"));
await typeAndWaitForSandbox(page, getSelector("29R"), "12345");
await page.click("[data-annotation-id='30R']");

text = await page.$eval(getSelector(`29R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("12345");
await waitForSandboxTrip(page);
await page.waitForFunction(
`${getQuerySelector("29R")}.value === "12345"`
);
}
});
});
Expand All @@ -1115,38 +1103,28 @@ describe("Interaction", () => {
it("must check input for US phone number (long) format", async () => {
// Run the tests sequentially to avoid any focus issues between the two
// browsers when an alert is displayed.
for (const [browserName, page] of pages) {
for (const [, page] of pages) {
await waitForScripting(page);

await clearInput(page, getSelector("29R"));
await clearInput(page, getSelector("30R"));

await page.focus(getSelector("30R"));
await typeAndWaitForSandbox(page, getSelector("30R"), "(123) 456A");
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "(123) 456A"`
`${getQuerySelector("30R")}.value === "(123) 456"`
);

let text = await page.$eval(getSelector(`30R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("(123) 456");

await page.focus(getSelector("30R"));
await typeAndWaitForSandbox(page, getSelector("30R"), "-789");
await page.click("[data-annotation-id='29R']");

await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "(123) 456-789"`
);

text = await page.$eval(getSelector(`30R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("");
await waitForSandboxTrip(page);
await page.waitForFunction(`${getQuerySelector("30R")}.value === ""`);

await page.focus(getSelector("30R"));
await typeAndWaitForSandbox(page, getSelector("30R"), "(123) 456-7890");
await page.click("[data-annotation-id='29R']");

text = await page.$eval(getSelector("30R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("(123) 456-7890");
await waitForSandboxTrip(page);
await page.waitForFunction(
`${getQuerySelector("30R")}.value === "(123) 456-7890"`
);
}
});
});
Expand All @@ -1170,38 +1148,28 @@ describe("Interaction", () => {
it("must check input for US phone number (short) format", async () => {
// Run the tests sequentially to avoid any focus issues between the two
// browsers when an alert is displayed.
for (const [browserName, page] of pages) {
for (const [, page] of pages) {
await waitForScripting(page);

await clearInput(page, getSelector("29R"));
await clearInput(page, getSelector("30R"));

await page.focus(getSelector("30R"));
await typeAndWaitForSandbox(page, getSelector("30R"), "123A");
await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "123A"`
`${getQuerySelector("30R")}.value === "123"`
);

let text = await page.$eval(getSelector(`30R`), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("123");

await page.focus(getSelector("30R"));
await typeAndWaitForSandbox(page, getSelector("30R"), "-456");
await page.click("[data-annotation-id='29R']");

await page.waitForFunction(
`${getQuerySelector("30R")}.value !== "123-456"`
);

text = await page.$eval(getSelector("30R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("");
await waitForSandboxTrip(page);
await page.waitForFunction(`${getQuerySelector("30R")}.value === ""`);

await page.focus(getSelector("30R"));
await typeAndWaitForSandbox(page, getSelector("30R"), "123-4567");
await page.click("[data-annotation-id='29R']");

text = await page.$eval(getSelector("30R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("123-4567");
await waitForSandboxTrip(page);
await page.waitForFunction(
`${getQuerySelector("30R")}.value === "123-4567"`
);
}
});
});
Expand Down

0 comments on commit e740809

Please sign in to comment.