cypress tags with soft assertions #27753
Arunreddy733
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
when I used the cypress tags for the test files, the odd test cases are failing instead of pending. so when i started to find the bug then i came to know that it is causing from softassertion. how to fix it?
e2e.js file structure
import './commands'
const registerCypressGrep = require('@cypress/grep')
registerCypressGrep()
// Alternatively you can use CommonJS syntax:
// require('./commands')
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from failing the test
return false
})
let isSoftAssertion = false;
let errors = [];
chai.softExpect = function ( ...args ) {
isSoftAssertion = true;
return chai.expect(...args);
},
chai.softAssert = function ( ...args ) {
isSoftAssertion = true;
return chai.assert(...args);
}
const origAssert = chai.Assertion.prototype.assert;
chai.Assertion.prototype.assert = function (...args) {
if ( isSoftAssertion ) {
try {
origAssert.call(this, ...args)
} catch ( error ) {
errors.push(error);
}
isSoftAssertion = false;
} else {
};
// monkey-patch
Cypress.log
so that the lastcy.then()
isn't logged to command logconst origLog = Cypress.log;
Cypress.log = function ( data ) {
if ( data && data.error && /soft assertions/i.test(data.error.message) ) {
data.error.message = '\n\n\t' + data.error.message + '\n\n';
throw data.error;
}
return origLog.call(Cypress, ...arguments);
};
// monkey-patch
it
callback so we insertcy.then()
as a last command// to each test case where we'll assert if there are any soft assertion errors
function itCallback ( func ) {
func();
cy.then(() => {
if ( errors.length ) {
const _ = Cypress._;
let msg = '';
}
const origIt = window.it;

window.it = (title, func) => {
origIt(title, func && (() => itCallback(func)));
};
window.it.only = (title, func) => {
origIt.only(title, func && (() => itCallback(func)));
};
window.it.skip = (title, func) => {
origIt.skip(title, func);
};
here in above image instead of failing it should be in pending state what is issue...?
Beta Was this translation helpful? Give feedback.
All reactions