You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I executed tests (13.13.0) with this command snapshotIframeContents. I have error cy.task() must only be invoked from the spec file or support file.
Worked in version 12.3.0
Desired behavior
No response
Test code to reproduce
cypress\support\commands.ts
Cypress.Commands.add("snapshotIframeContents",{prevSubject: "element"},(subject)=>{returncy.wrap(subject[0]).its("0.contentWindow.document.body.innerHTML").then(async(innerHTML: string)=>{constwrapper=document.createElement("div");wrapper.innerHTML=innerHTML;// Remove style since its compilation differs between enviromentsArray.from(wrapper.querySelectorAll("style")).forEach((element)=>element.remove());// Reduce base64 image sizeawaitPromise.all(Array.from(wrapper.querySelectorAll("img")).map(async(element)=>{if(/data:image\//.exec(element.src)){// Taken from: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest, there is no nicer way of doing thisconstmsgUint8=newTextEncoder().encode(element.src);// encode as (utf-8) Uint8ArrayconsthashBuffer=awaitcrypto.subtle.digest("SHA-256",msgUint8);// hash the messageconsthashArray=Array.from(newUint8Array(hashBuffer));// convert buffer to byte arrayconsthashHex=hashArray.map((b)=>b.toString(16).padStart(2,"0")).join("");// convert bytes to hex stringelement.src=hashHex;}}),);cy.wrap(wrapper).toMatchSnapshot();//problem here});});
also tried this variant with spy:
Cypress.Commands.add("snapshotIframeContents",{prevSubject: "element"},(subject)=>{constcallbackSpy=cy.spy().as("callbackSpy");cy.wrap(subject[0]).its("0.contentWindow.document.body.innerHTML").then(async(innerHTML: string)=>{constwrapper=document.createElement("div");wrapper.innerHTML=innerHTML;// Remove style since its compilation differs between enviromentsArray.from(wrapper.querySelectorAll("style")).forEach((element)=>element.remove());// Reduce base64 image sizeawaitPromise.all(Array.from(wrapper.querySelectorAll("img")).map(async(element)=>{if(/data:image\//.exec(element.src)){// Taken from: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest, there is no nicer way of doing thisconstmsgUint8=newTextEncoder().encode(element.src);// encode as (utf-8) Uint8ArrayconsthashBuffer=awaitcrypto.subtle.digest("SHA-256",msgUint8);// hash the messageconsthashArray=Array.from(newUint8Array(hashBuffer));// convert buffer to byte arrayconsthashHex=hashArray.map((b)=>b.toString(16).padStart(2,"0")).join("");// convert bytes to hex stringelement.src=hashHex;}}),);callbackSpy();});cy.get("@callbackSpy").should("be.called");cy.wrap(subject[0]).its("0.contentWindow.document.body.innerHTML").toMatchSnapshot();});
calling it:
EhicReissue\ehicReissueFormCertificate.spec.ts
cy.log("8. Vyzkoušej tlačítko pro tisk");cy.get("[data-testid='newborn-certificate-printer']").snapshotIframeContents();
Cypress Version
13.13.0
Node version
18.20.3
Operating System
Windows 10 Pro
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered:
Current behavior
When I executed tests (13.13.0) with this command snapshotIframeContents. I have error cy.task() must only be invoked from the spec file or support file.
Worked in version 12.3.0
Desired behavior
No response
Test code to reproduce
cypress\support\commands.ts
also tried this variant with spy:
calling it:
EhicReissue\ehicReissueFormCertificate.spec.ts
Cypress Version
13.13.0
Node version
18.20.3
Operating System
Windows 10 Pro
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered: