Skip to content

Commit

Permalink
[test] Wait for images to load (#11004)
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii committed Nov 12, 2023
1 parent a578fc9 commit 961bee1
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions test/regressions/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ async function main() {
// Move cursor offscreen to not trigger unwanted hover effects.
page.mouse.move(0, 0);

// Wait for the flags to load
await page.waitForFunction(() => {
const images = Array.from(document.querySelectorAll('img'));
return images.every((img) => img.complete);
});

if (/^\docs-charts-.*/.test(pathURL)) {
// Run one tick of the clock to get the final animation state
await sleep(10);
Expand All @@ -119,6 +113,22 @@ async function main() {
'[data-testid="testcase"]:not([aria-busy="true"])',
);

// Wait for the flags to load
await page.waitForFunction(
() => {
const images = Array.from(document.querySelectorAll('img'));
return images.every((img) => {
if (!img.complete && img.loading === 'lazy') {
// Force lazy-loaded images to load
img.setAttribute('loading', 'eager');
}
return img.complete;
});
},
undefined,
{ timeout: 1000 },
);

await testcase.screenshot({ path: screenshotPath, type: 'png' });
});

Expand Down

0 comments on commit 961bee1

Please sign in to comment.