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

Commit e8e4144

Browse files
authored
feat: disable spellcheck in argosScreenshot (#19)
1 parent ccf8e07 commit e8e4144

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

cypress/pages/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ <h3>Red square</h3>
6969
class="red-square"
7070
style="width: 100px; height: 100px; background-color: red"
7171
></div>
72+
73+
<h3>Editable contents</h3>
74+
<div class="field">
75+
<div><input value="an orrange carrot" /></div>
76+
<div><textarea>an orrange carrot</textarea></div>
77+
<p contenteditable="true" autofocus>an orrange carrot</p>
78+
</div>
7279
</main>
7380

7481
<script>

support.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,36 @@ function waitUntilNoBusy() {
5858
);
5959
}
6060

61+
/**
62+
* Wait until all images are loaded.
63+
*/
64+
function waitForImagesLoading() {
65+
cy.waitUntil(() =>
66+
cy.document().then((document) => {
67+
const allImages = Array.from(document.images);
68+
allImages.forEach((img) => {
69+
img.loading = "eager";
70+
img.decoding = "sync";
71+
});
72+
return allImages.every((img) => img.complete && img.naturalWidth > 0);
73+
})
74+
);
75+
}
76+
77+
/**
78+
* Disable spellcheck on inputs, textareas, and contenteditable elements to avoid red underlines
79+
*/
80+
function disableSpellCheck() {
81+
cy.document().then((document) => {
82+
const query =
83+
"[contenteditable]:not([contenteditable=false]):not([spellcheck=false]), input:not([spellcheck=false]), textarea:not([spellcheck=false])";
84+
document.querySelectorAll(query).forEach((element) => {
85+
element.setAttribute("spellcheck", "false");
86+
});
87+
});
88+
return true;
89+
}
90+
6191
Cypress.Commands.add(
6292
"argosScreenshot",
6393
{ prevSubject: ["optional", "element", "window", "document"] },
@@ -83,16 +113,10 @@ Cypress.Commands.add(
83113
cy.document().its("fonts.status").should("equal", "loaded");
84114

85115
// 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-
);
116+
waitForImagesLoading();
117+
118+
// Wait for images to be loaded
119+
disableSpellCheck();
96120

97121
// Screenshot
98122
cy.wrap(subject).screenshot(name, {

0 commit comments

Comments
 (0)