Skip to content

Commit b6efa5e

Browse files
authored
chore(e2e): ignore stale element reference errors (#5623)
* ignore stale element reference errors * don't allow WebdriverIO.Element to be passed in - only ChainablePromiseElement or selectors and don't await it * screenshot before looking up the element again * bump some pauses in disconnect helper * pause after saving the favourite * saving the connection automatically selects it * pause before selecting favourite * screenshots * include the name in the screenshots * get rid of one more Element * click in one step, no checking if the element is enabled first
1 parent cf2d1a7 commit b6efa5e

12 files changed

+62
-60
lines changed

packages/compass-e2e-tests/helpers/commands/click-visible.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,29 @@ interface ClickOptions {
88

99
export async function clickVisible(
1010
browser: CompassBrowser,
11-
selector:
12-
| string
13-
| ChainablePromiseElement<WebdriverIO.Element>
14-
| WebdriverIO.Element,
11+
selector: string | ChainablePromiseElement<WebdriverIO.Element>,
1512
options?: ClickOptions
1613
): Promise<void> {
17-
async function getElement() {
18-
return typeof selector === 'string' ? await browser.$(selector) : selector;
14+
function getElement() {
15+
return typeof selector === 'string' ? browser.$(selector) : selector;
1916
}
2017

21-
const displayElement = await getElement();
18+
const displayElement = getElement();
2219

2320
await displayElement.waitForDisplayed();
2421

2522
// Clicking a thing that's still animating is unreliable at best.
2623
await browser.waitForAnimations(selector);
2724

2825
if (options?.scroll) {
29-
const scrollElement = await getElement();
26+
const scrollElement = getElement();
3027
await scrollElement.scrollIntoView();
3128
await browser.pause(1000);
3229
}
3330

34-
const clickElement = await getElement();
3531
if (options?.screenshot) {
3632
await browser.screenshot(options.screenshot);
3733
}
38-
if (await clickElement.isEnabled()) {
39-
await clickElement.click();
40-
} else {
41-
throw new Error(
42-
`Trying to click ${selector}, but the element is not enabled`
43-
);
44-
}
34+
const clickElement = getElement();
35+
await clickElement.click();
4536
}

packages/compass-e2e-tests/helpers/commands/export-to-language.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function exportToLanguage(
1717

1818
// pick the language
1919
await browser.waitUntil(async () => {
20-
const button = await browser.$(Selectors.ExportToLanguageLanguageField);
20+
const button = browser.$(Selectors.ExportToLanguageLanguageField);
2121
await browser.clickVisible(button);
2222
return (await button.getAttribute('aria-expanded')) === 'true';
2323
});

packages/compass-e2e-tests/helpers/commands/save-connection-string-as-favorite.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ export async function saveConnectionStringAsFavorite(
1414
connectionString
1515
);
1616
await browser.saveFavorite(favoriteName, color);
17+
1718
return favoriteName;
1819
}

packages/compass-e2e-tests/helpers/commands/select-favorite.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ export async function selectFavorite(
55
browser: CompassBrowser,
66
favoriteName: string
77
): Promise<void> {
8-
await browser.clickVisible(Selectors.sidebarFavoriteButton(favoriteName));
8+
// Usually we use this after disconnecting. I'm just trying to see where the
9+
// race condition is - are we clicking too quickly or is the act of clicking
10+
// causing something to re-render and the element to go stale?
11+
await browser.pause(1000);
12+
13+
await browser.clickVisible(Selectors.sidebarFavoriteButton(favoriteName), {
14+
screenshot: `selecting-favourite-${favoriteName}.png`,
15+
});
916
await browser.waitUntil(async () => {
1017
const text = await browser.$(Selectors.ConnectionTitle).getText();
1118
return text === favoriteName;

packages/compass-e2e-tests/helpers/commands/set-value-visible.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ import type { ChainablePromiseElement } from 'webdriverio';
44

55
export async function setValueVisible(
66
browser: CompassBrowser,
7-
selector:
8-
| string
9-
| ChainablePromiseElement<WebdriverIO.Element>
10-
| WebdriverIO.Element,
7+
selector: string | ChainablePromiseElement<WebdriverIO.Element>,
118
value: string
129
): Promise<void> {
1310
// The hardest thing in computer science? Reliably setting a text form field's
1411
// value in an E2E test.
15-
async function getElement() {
16-
return typeof selector === 'string' ? await browser.$(selector) : selector;
12+
function getElement() {
13+
return typeof selector === 'string' ? browser.$(selector) : selector;
1714
}
18-
const element = await getElement();
15+
const element = getElement();
1916

2017
await browser.waitForAnimations(element);
2118

packages/compass-e2e-tests/helpers/commands/wait-for-animations.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,37 @@ import type { CompassBrowser } from '../compass-browser';
44

55
export async function waitForAnimations(
66
browser: CompassBrowser,
7-
selector:
8-
| string
9-
| ChainablePromiseElement<WebdriverIO.Element>
10-
| WebdriverIO.Element
7+
selector: string | ChainablePromiseElement<WebdriverIO.Element>
118
): Promise<void> {
12-
async function getElement() {
13-
return typeof selector === 'string' ? await browser.$(selector) : selector;
9+
function getElement() {
10+
return typeof selector === 'string' ? browser.$(selector) : selector;
1411
}
1512

16-
const initialElement = await getElement();
13+
try {
14+
const initialElement = getElement();
1715

18-
let previousResult = {
19-
...(await initialElement.getLocation()),
20-
...(await initialElement.getSize()),
21-
};
22-
await browser.waitUntil(async function () {
23-
// small delay to make sure that if it is busy animating it had time to move
24-
// before the first check and between each two checks
25-
await browser.pause(50);
16+
let previousResult = {
17+
location: await initialElement.getLocation(),
18+
size: await initialElement.getSize(),
19+
};
20+
await browser.waitUntil(async function () {
21+
// small delay to make sure that if it is busy animating it had time to move
22+
// before the first check and between each two checks
23+
await browser.pause(50);
2624

27-
const currentElement = await getElement();
25+
const currentElement = getElement();
2826

29-
const result = {
30-
...(await currentElement.getLocation()),
31-
...(await currentElement.getSize()),
32-
};
33-
const stopped = _.isEqual(result, previousResult);
34-
previousResult = result;
35-
return stopped;
36-
});
27+
const result = {
28+
location: await currentElement.getLocation(),
29+
size: await currentElement.getSize(),
30+
};
31+
const stopped = _.isEqual(result, previousResult);
32+
previousResult = result;
33+
return stopped;
34+
});
35+
} catch (err: any) {
36+
if (err.name !== 'stale element reference') {
37+
throw err;
38+
}
39+
}
3740
}

packages/compass-e2e-tests/tests/collection-documents-tab.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ FindIterable<Document> result = collection.find(filter);`);
382382
);
383383
await value.doubleClick();
384384

385-
const input = await document.$(
385+
const input = document.$(
386386
`${Selectors.HadronDocumentElement}:last-child ${Selectors.HadronDocumentValueEditor}`
387387
);
388388
await browser.setValueVisible(input, '42');
@@ -518,7 +518,7 @@ FindIterable<Document> result = collection.find(filter);`);
518518
const value = await document.$('[col-id="j"] .element-value');
519519
await value.doubleClick();
520520

521-
const input = await document.$(
521+
const input = document.$(
522522
'[col-id="j"] [data-testid="table-view-cell-editor-value-input"]'
523523
);
524524
await browser.setValueVisible(input, '-100');

packages/compass-e2e-tests/tests/collection-import.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ describe('Collection import', function () {
12241224
await toastElement.waitForDisplayed();
12251225
// Click the toast element. This focuses the toast, and clicking the cancel
12261226
// button isn't consistent without it.
1227-
await browser.clickVisible(toastElement);
1227+
await browser.clickVisible(Selectors.ImportToast);
12281228

12291229
const importAbortButton = await browser.$(Selectors.ImportToastAbort);
12301230
await importAbortButton.waitForDisplayed();
@@ -1295,7 +1295,7 @@ describe('Collection import', function () {
12951295
await toastElement.waitForDisplayed();
12961296
// Click the toast element. This focuses the toast, and clicking the cancel
12971297
// button isn't consistent without it.
1298-
await browser.clickVisible(toastElement);
1298+
await browser.clickVisible(Selectors.ImportToast);
12991299

13001300
const importAbortButton = await browser.$(Selectors.ImportToastAbort);
13011301
await importAbortButton.waitForDisplayed();

packages/compass-e2e-tests/tests/collection-indexes-tab.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('Collection indexes tab', function () {
123123
await createModal.waitForDisplayed();
124124

125125
// Select i filed name from Combobox.
126-
const fieldNameSelect = await browser.$(
126+
const fieldNameSelect = browser.$(
127127
Selectors.createIndexModalFieldNameSelectInput(0)
128128
);
129129

packages/compass-e2e-tests/tests/in-use-encryption.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ describe('CSFLE / QE', function () {
487487
);
488488
await value.doubleClick();
489489

490-
const input = await document.$(
490+
const input = document.$(
491491
`${Selectors.HadronDocumentElement}[data-field="${field}"] ${Selectors.HadronDocumentValueEditor}`
492492
);
493493
await browser.setValueVisible(
@@ -639,7 +639,7 @@ describe('CSFLE / QE', function () {
639639
const isCopiedDocumentPhoneNumberEditorExisting =
640640
await copiedDocumentPhoneNumberEditor.isExisting();
641641
expect(isCopiedDocumentPhoneNumberEditorExisting).to.be.equal(true);
642-
const copiedDocumentFaxNumberEditor = await copiedDocument.$(
642+
const copiedDocumentFaxNumberEditor = copiedDocument.$(
643643
`${Selectors.HadronDocumentElement}[data-field="faxNumber"] ${Selectors.HadronDocumentValueEditor}`
644644
);
645645
const isCopiedDocumentFaxNumberEditorExisting =

0 commit comments

Comments
 (0)