Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 0744826

Browse files
authored
feat: stabilize images before screenshot (#17)
1 parent 4717f21 commit 0744826

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

support.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,28 @@ Cypress.Commands.add(
7272
displayName: `Argos Screenshot`,
7373
message: name,
7474
});
75+
7576
// Inject styles
7677
cy.document().then((doc) => injectStyles(doc));
78+
7779
// Wait until there is no `[aria-busy="true"]` element on the page.
7880
waitUntilNoBusy();
81+
7982
// Wait for fonts to be loaded
8083
cy.document().its("fonts.status").should("equal", "loaded");
8184

85+
// Wait for images to be loaded
86+
cy.waitUntil(() =>
87+
cy.document().then((document) => {
88+
const allImages = Array.from(document.images);
89+
allImages.forEach((img) => {
90+
img.loading = "eager";
91+
img.decoding = "sync";
92+
});
93+
return allImages.every((img) => img.complete && img.naturalWidth > 0);
94+
})
95+
);
96+
8297
// Screenshot
8398
cy.wrap(subject).screenshot(name, {
8499
blackout: ['[data-visual-test="blackout"]'].concat(

0 commit comments

Comments
 (0)