Skip to content

Commit e740809

Browse files
committed
Fix intermittent issues in the issue14307.pdf integration tests
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.
1 parent 3f1d07a commit e740809

File tree

1 file changed

+24
-56
lines changed

1 file changed

+24
-56
lines changed

test/integration/scripting_spec.mjs

+24-56
Original file line numberDiff line numberDiff line change
@@ -1060,38 +1060,26 @@ describe("Interaction", () => {
10601060
it("must check input for US zip format", async () => {
10611061
// Run the tests sequentially to avoid any focus issues between the two
10621062
// browsers when an alert is displayed.
1063-
for (const [browserName, page] of pages) {
1063+
for (const [, page] of pages) {
10641064
await waitForScripting(page);
10651065

1066-
await clearInput(page, getSelector("29R"));
1067-
await clearInput(page, getSelector("30R"));
1068-
10691066
await page.focus(getSelector("29R"));
10701067
await typeAndWaitForSandbox(page, getSelector("29R"), "12A");
1071-
await page.waitForFunction(
1072-
`${getQuerySelector("29R")}.value !== "12A"`
1073-
);
1074-
1075-
let text = await page.$eval(getSelector(`29R`), el => el.value);
1076-
expect(text).withContext(`In ${browserName}`).toEqual("12");
1068+
await page.waitForFunction(`${getQuerySelector("29R")}.value === "12"`);
10771069

10781070
await page.focus(getSelector("29R"));
10791071
await typeAndWaitForSandbox(page, getSelector("29R"), "34");
10801072
await page.click("[data-annotation-id='30R']");
1081-
1082-
await page.waitForFunction(
1083-
`${getQuerySelector("29R")}.value !== "1234"`
1084-
);
1085-
1086-
text = await page.$eval(getSelector(`29R`), el => el.value);
1087-
expect(text).withContext(`In ${browserName}`).toEqual("");
1073+
await waitForSandboxTrip(page);
1074+
await page.waitForFunction(`${getQuerySelector("29R")}.value === ""`);
10881075

10891076
await page.focus(getSelector("29R"));
10901077
await typeAndWaitForSandbox(page, getSelector("29R"), "12345");
10911078
await page.click("[data-annotation-id='30R']");
1092-
1093-
text = await page.$eval(getSelector(`29R`), el => el.value);
1094-
expect(text).withContext(`In ${browserName}`).toEqual("12345");
1079+
await waitForSandboxTrip(page);
1080+
await page.waitForFunction(
1081+
`${getQuerySelector("29R")}.value === "12345"`
1082+
);
10951083
}
10961084
});
10971085
});
@@ -1115,38 +1103,28 @@ describe("Interaction", () => {
11151103
it("must check input for US phone number (long) format", async () => {
11161104
// Run the tests sequentially to avoid any focus issues between the two
11171105
// browsers when an alert is displayed.
1118-
for (const [browserName, page] of pages) {
1106+
for (const [, page] of pages) {
11191107
await waitForScripting(page);
11201108

1121-
await clearInput(page, getSelector("29R"));
1122-
await clearInput(page, getSelector("30R"));
1123-
11241109
await page.focus(getSelector("30R"));
11251110
await typeAndWaitForSandbox(page, getSelector("30R"), "(123) 456A");
11261111
await page.waitForFunction(
1127-
`${getQuerySelector("30R")}.value !== "(123) 456A"`
1112+
`${getQuerySelector("30R")}.value === "(123) 456"`
11281113
);
11291114

1130-
let text = await page.$eval(getSelector(`30R`), el => el.value);
1131-
expect(text).withContext(`In ${browserName}`).toEqual("(123) 456");
1132-
11331115
await page.focus(getSelector("30R"));
11341116
await typeAndWaitForSandbox(page, getSelector("30R"), "-789");
11351117
await page.click("[data-annotation-id='29R']");
1136-
1137-
await page.waitForFunction(
1138-
`${getQuerySelector("30R")}.value !== "(123) 456-789"`
1139-
);
1140-
1141-
text = await page.$eval(getSelector(`30R`), el => el.value);
1142-
expect(text).withContext(`In ${browserName}`).toEqual("");
1118+
await waitForSandboxTrip(page);
1119+
await page.waitForFunction(`${getQuerySelector("30R")}.value === ""`);
11431120

11441121
await page.focus(getSelector("30R"));
11451122
await typeAndWaitForSandbox(page, getSelector("30R"), "(123) 456-7890");
11461123
await page.click("[data-annotation-id='29R']");
1147-
1148-
text = await page.$eval(getSelector("30R"), el => el.value);
1149-
expect(text).withContext(`In ${browserName}`).toEqual("(123) 456-7890");
1124+
await waitForSandboxTrip(page);
1125+
await page.waitForFunction(
1126+
`${getQuerySelector("30R")}.value === "(123) 456-7890"`
1127+
);
11501128
}
11511129
});
11521130
});
@@ -1170,38 +1148,28 @@ describe("Interaction", () => {
11701148
it("must check input for US phone number (short) format", async () => {
11711149
// Run the tests sequentially to avoid any focus issues between the two
11721150
// browsers when an alert is displayed.
1173-
for (const [browserName, page] of pages) {
1151+
for (const [, page] of pages) {
11741152
await waitForScripting(page);
11751153

1176-
await clearInput(page, getSelector("29R"));
1177-
await clearInput(page, getSelector("30R"));
1178-
11791154
await page.focus(getSelector("30R"));
11801155
await typeAndWaitForSandbox(page, getSelector("30R"), "123A");
11811156
await page.waitForFunction(
1182-
`${getQuerySelector("30R")}.value !== "123A"`
1157+
`${getQuerySelector("30R")}.value === "123"`
11831158
);
11841159

1185-
let text = await page.$eval(getSelector(`30R`), el => el.value);
1186-
expect(text).withContext(`In ${browserName}`).toEqual("123");
1187-
11881160
await page.focus(getSelector("30R"));
11891161
await typeAndWaitForSandbox(page, getSelector("30R"), "-456");
11901162
await page.click("[data-annotation-id='29R']");
1191-
1192-
await page.waitForFunction(
1193-
`${getQuerySelector("30R")}.value !== "123-456"`
1194-
);
1195-
1196-
text = await page.$eval(getSelector("30R"), el => el.value);
1197-
expect(text).withContext(`In ${browserName}`).toEqual("");
1163+
await waitForSandboxTrip(page);
1164+
await page.waitForFunction(`${getQuerySelector("30R")}.value === ""`);
11981165

11991166
await page.focus(getSelector("30R"));
12001167
await typeAndWaitForSandbox(page, getSelector("30R"), "123-4567");
12011168
await page.click("[data-annotation-id='29R']");
1202-
1203-
text = await page.$eval(getSelector("30R"), el => el.value);
1204-
expect(text).withContext(`In ${browserName}`).toEqual("123-4567");
1169+
await waitForSandboxTrip(page);
1170+
await page.waitForFunction(
1171+
`${getQuerySelector("30R")}.value === "123-4567"`
1172+
);
12051173
}
12061174
});
12071175
});

0 commit comments

Comments
 (0)