Skip to content

Commit a5a0b26

Browse files
committed
Merge remote-tracking branch 'origin/master' into renovate/eslint-plugin-jest-29.x
2 parents d19049b + 29d6556 commit a5a0b26

1 file changed

Lines changed: 31 additions & 13 deletions

File tree

tests/selenium.spec.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,39 @@ async function waitForLoad() {
8989
}
9090

9191
// making this a little easier to read in tests
92-
async function clickByCss(css, retries = 3) {
92+
async function retry(fn, errorsToRetry = [], retries = 5) {
9393
let attempts = 0;
94+
let lastError = null;
9495
while (attempts < retries) {
9596
try {
96-
let element = await driver.findElement(By.css(css));
97-
await element.click();
98-
return;
97+
if (attempts > 0) {
98+
await driver.sleep(busyWait);
99+
}
100+
return await fn();
99101
} catch (error) {
100-
if (error.name === "StaleElementReferenceError") {
102+
lastError = error;
103+
// Retry all errors or only the ones specified in `errorsToRetry`.
104+
if (!errorsToRetry.length || errorsToRetry.includes(error.name)) {
101105
console.warn(`Attempt ${attempts + 1} failed. Retrying...`);
102106
attempts++;
103-
await driver.sleep(busyWait);
104107
} else {
105108
// Re-throw other errors
106109
throw error;
107110
}
108111
}
109112
}
113+
throw lastError;
114+
}
115+
116+
async function clickByCss(css, retries = 3) {
117+
return await retry(
118+
async () => {
119+
let element = await driver.findElement(By.css(css));
120+
await element.click();
121+
},
122+
["StaleElementReferenceError"],
123+
retries,
124+
);
110125
}
111126

112127
describe("End to end browser tests", () => {
@@ -142,19 +157,22 @@ describe("End to end browser tests", () => {
142157
await clickByCss("#clear-all-data");
143158
await waitForLoad();
144159

145-
// verify everything is cleared as expected
146-
expect(
147-
(await driver.findElements(By.css("#status .unsync"))).length,
148-
).toBeGreaterThan(1);
149-
expect(
150-
(await driver.findElements(By.css("#status .up-to-date"))).length,
151-
).toBe(0);
160+
await retry(async () => {
161+
// verify everything is cleared as expected
162+
expect(
163+
(await driver.findElements(By.css("#status .unsync"))).length,
164+
).toBeGreaterThan(1);
165+
expect(
166+
(await driver.findElements(By.css("#status .up-to-date"))).length,
167+
).toBe(0);
168+
});
152169
});
153170

154171
test("Clear and re-download a collection", async () => {
155172
// force sync the first collection and verify it worked
156173
await clickByCss("#status .sync");
157174
await waitForLoad();
175+
158176
let firstTimestamp = await driver.findElement(
159177
By.css("#status .human-local-timestamp"),
160178
);

0 commit comments

Comments
 (0)