问题
I am trying to go to different urls and compare screenshots with baseline image using matchImageSnapshot. Issue here is when one of my url fail with matchimagesnapshot -it is not continuing to next URL.NOTE:I tried to run with variable --env failOnSnapshotDiff=false -issue with this approach is -i wont get any clue which url failed unless i go manually and check diff folder.
Is there any way i can achieve this Say for eg i have 3 urls in my sample - i want to continue to next url even if url1 failed and i need to get a error for failed urls? Thanks for any help
beforeEach(function() {
cy.viewport(1680,1050);
});
const pages=[
"https://URL1",
"https://URL2",
"https://URL3",
"https://URL4"
]
describe('screencheck', () => {
it('scree', () => {
cy.login().then(()=>{
pages.forEach((page)=>{
cy.setResolution([1680,1050]);
cy.visit(page);
cy.wait(30000);
cy.get('.itl-exit-info-panel > .ng-scope').then(()=>
{
cy.get('.itl-exit-info-panel > .ng-scope').root().matchImageSnapshot(page);
// })
})
});
});
})
})
回答1:
Cypress uses Chai assertions. What you need is a soft assertion (continue execution even after failure). Chai doesn't support soft assertions. You would need to use a NPM library called soft-assert: https://www.npmjs.com/package/soft-assert
回答2:
Sameer Wakude already pointed to the soft assertion. Another option can be to put every screenshot test in a seperate it()
. Since an it()
may fail and won't stop the rest of the it()
s to stop.
来源:https://stackoverflow.com/questions/57122122/how-to-continue-to-execution-even-when-one-check-fail