Skip to content

Commit

Permalink
E2E: Work around images not loading (#3344)
Browse files Browse the repository at this point in the history
# Motivation

We have an e2e test that tests that images load.
Sometimes images don't load and the test times out:
https://github.com/dfinity/nns-dapp/actions/runs/6245207559?pr=3337

I'm not sure why they don't always load on CI but let's retry the test
when they don't.

# Changes

1. Set a timeout on waiting for images to be loaded.
2. Retry the test up to 2 times when it fails.

# Tests

Still pass, hopefully less flaky.

# Todos

- [ ] Add entry to changelog (if necessary).
not necessary
  • Loading branch information
dskloetd authored Sep 21, 2023
1 parent a84933f commit 0e3aa5a
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions frontend/src/tests/e2e/images.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ const expectImagesLoaded = async ({ page, sources }) => {
baseImageSources.sort();
expect(baseImageSources).toEqual(sources);

await page.waitForFunction((expectedImageCount) => {
const images = Array.from(document.querySelectorAll("img"));
if (images.length !== expectedImageCount) {
return false;
}
// The browser might decide not to load images that are outside the
// viewport.
images.forEach((img) => img.scrollIntoView());
return images.every((img) => img.complete);
}, sources.length);
await page.waitForFunction(
(expectedImageCount) => {
const images = Array.from(document.querySelectorAll("img"));
if (images.length !== expectedImageCount) {
return false;
}
// The browser might decide not to load images that are outside the
// viewport.
images.forEach((img) => img.scrollIntoView());
return images.every((img) => img.complete);
},
sources.length,
{ timeout: 10000 }
);
};

test.describe.configure({ retries: 2 });

test("Test images load on accounts page", async ({ page, context }) => {
await page.goto("/accounts");
await expect(page).toHaveTitle("My Tokens / NNS Dapp");
Expand Down

0 comments on commit 0e3aa5a

Please sign in to comment.