Skip to content

Commit eb2edb4

Browse files
committed
Remove most waitForTimeout usage from the scripting integration tests
This commit replaces most `waitForTimeout` occurrences with calls to `waitForFunction` or `waitForSandboxTrip`. Note that the occurrences in the "must check that focus/blur callbacks aren't called" test remain until we find a good way to ensure that nothing happened after the tab switches (because currently we can't be sure that nothing happens since there is nothing to await).
1 parent 661a62b commit eb2edb4

File tree

1 file changed

+27
-39
lines changed

1 file changed

+27
-39
lines changed

test/integration/scripting_spec.mjs

+27-39
Original file line numberDiff line numberDiff line change
@@ -1713,11 +1713,9 @@ describe("Interaction", () => {
17131713
await clearInput(page, getSelector("27R"));
17141714
await page.type(getSelector("27R"), exportValue);
17151715
await page.click("[data-annotation-id='28R']");
1716-
// eslint-disable-next-line no-restricted-syntax
1717-
await waitForTimeout(10);
1718-
1719-
value = await page.$eval(getSelector("24R"), el => el.value);
1720-
expect(value).withContext(`In ${browserName}`).toEqual(exportValue);
1716+
await page.waitForFunction(
1717+
`${getQuerySelector("24R")}.value === "${exportValue}"`
1718+
);
17211719
}
17221720
})
17231721
);
@@ -1761,9 +1759,10 @@ describe("Interaction", () => {
17611759
await page.waitForFunction(
17621760
`${getQuerySelector("30R")}.value !== "abc"`
17631761
);
1764-
// eslint-disable-next-line no-restricted-syntax
1765-
await waitForTimeout(100);
17661762

1763+
await page.waitForFunction(
1764+
`window.document.activeElement.getAttribute("data-element-id") !== "30R"`
1765+
);
17671766
const focusedId = await page.evaluate(_ =>
17681767
window.document.activeElement.getAttribute("data-element-id")
17691768
);
@@ -1858,8 +1857,7 @@ describe("Interaction", () => {
18581857
expect(text).withContext(`In ${browserName}`).toEqual("00000000123");
18591858

18601859
await page.click(getSelector("26R"));
1861-
// eslint-disable-next-line no-restricted-syntax
1862-
await waitForTimeout(10);
1860+
await waitForSandboxTrip(page);
18631861

18641862
text = await page.$eval(getSelector("25R"), el => el.value);
18651863
expect(text).withContext(`In ${browserName}`).toEqual("00000000123");
@@ -1893,15 +1891,15 @@ describe("Interaction", () => {
18931891
expect(text).withContext(`In ${browserName}`).toEqual("5,25");
18941892

18951893
await page.click(getSelector("22R"));
1896-
// eslint-disable-next-line no-restricted-syntax
1897-
await waitForTimeout(10);
1894+
await waitForSandboxTrip(page);
18981895

18991896
text = await page.$eval(getSelector("22R"), el => el.value);
19001897
expect(text).withContext(`In ${browserName}`).toEqual("5,25");
19011898

19021899
await page.click(getSelector("31R"));
1903-
// eslint-disable-next-line no-restricted-syntax
1904-
await waitForTimeout(10);
1900+
await page.waitForFunction(
1901+
`${getQuerySelector("31R")}.value !== "5,25"`
1902+
);
19051903

19061904
text = await page.$eval(getSelector("31R"), el => el.value);
19071905
expect(text).withContext(`In ${browserName}`).toEqual("5.25");
@@ -1993,18 +1991,10 @@ describe("Interaction", () => {
19931991

19941992
await page.click(getSelector("26R"));
19951993
await page.type(getSelector("26R"), "abcde", { delay: 10 });
1996-
19971994
await page.click(getSelector("23R"));
1998-
// eslint-disable-next-line no-restricted-syntax
1999-
await waitForTimeout(10);
2000-
await page.click(getSelector("26R"));
2001-
2002-
await kbSelectAll(page);
2003-
await page.keyboard.press("Backspace");
2004-
1995+
await clearInput(page, getSelector("26R"));
20051996
await page.click(getSelector("23R"));
2006-
// eslint-disable-next-line no-restricted-syntax
2007-
await waitForTimeout(10);
1997+
await waitForSandboxTrip(page);
20081998

20091999
text = await page.$eval(getSelector("26R"), el => el.value);
20102000
expect(text).withContext(`In ${browserName}`).toEqual("");
@@ -2151,33 +2141,37 @@ describe("Interaction", () => {
21512141
);
21522142
expect(readonly).withContext(`In ${browserName}`).toEqual(true);
21532143
await page.click(getSelector("334R"));
2154-
// eslint-disable-next-line no-restricted-syntax
2155-
await waitForTimeout(10);
2144+
await waitForSandboxTrip(page);
21562145

21572146
readonly = await page.$eval(getSelector("353R"), el => el.disabled);
21582147
expect(readonly).withContext(`In ${browserName}`).toEqual(true);
21592148
await page.click(getSelector("351R"));
2160-
// eslint-disable-next-line no-restricted-syntax
2161-
await waitForTimeout(10);
2149+
await waitForSandboxTrip(page);
21622150

21632151
readonly = await page.$eval(getSelector("353R"), el => el.disabled);
21642152
expect(readonly).withContext(`In ${browserName}`).toEqual(true);
21652153
await page.click(getSelector("352R"));
2166-
// eslint-disable-next-line no-restricted-syntax
2167-
await waitForTimeout(10);
2154+
await page.waitForFunction(
2155+
`${getQuerySelector("353R")}.disabled !== true`
2156+
);
21682157

21692158
readonly = await page.$eval(getSelector("353R"), el => el.disabled);
21702159
expect(readonly).withContext(`In ${browserName}`).toEqual(false);
21712160

21722161
await page.click(getSelector("353R"));
2173-
// eslint-disable-next-line no-restricted-syntax
2174-
await waitForTimeout(10);
2162+
await page.waitForFunction(
2163+
`${getQuerySelector("353R")}.checked !== false`
2164+
);
21752165

21762166
let checked = await page.$eval(getSelector("353R"), el => el.checked);
21772167
expect(checked).withContext(`In ${browserName}`).toEqual(true);
21782168
await page.click(getSelector("334R"));
2179-
// eslint-disable-next-line no-restricted-syntax
2180-
await waitForTimeout(10);
2169+
await page.waitForFunction(
2170+
`${getQuerySelector("353R")}.disabled !== false`
2171+
);
2172+
await page.waitForFunction(
2173+
`${getQuerySelector("353R")}.checked !== true`
2174+
);
21812175

21822176
readonly = await page.$eval(getSelector("353R"), el => el.disabled);
21832177
expect(readonly).withContext(`In ${browserName}`).toEqual(true);
@@ -2216,13 +2210,9 @@ describe("Interaction", () => {
22162210
await page.click(getSelector("55R"));
22172211
await page.type(getSelector("55R"), "Hello", { delay: 10 });
22182212
await page.click(getSelector("56R"));
2219-
// eslint-disable-next-line no-restricted-syntax
2220-
await waitForTimeout(10);
22212213

22222214
await page.click(getSelector("55R"));
22232215
await page.type(getSelector("55R"), " World", { delay: 10 });
2224-
// eslint-disable-next-line no-restricted-syntax
2225-
await waitForTimeout(10);
22262216

22272217
await otherPages[i].bringToFront();
22282218
// eslint-disable-next-line no-restricted-syntax
@@ -2264,8 +2254,6 @@ describe("Interaction", () => {
22642254
);
22652255

22662256
await page.click(getSelector("25R"));
2267-
// eslint-disable-next-line no-restricted-syntax
2268-
await waitForTimeout(10);
22692257
await page.click(getSelector("26R"));
22702258

22712259
await page.waitForFunction(

0 commit comments

Comments
 (0)