I have been wondering how to hide a successful assertion log on Cypress Desktop (npx cypress open), but show a failed one?
I have been searching in stackoverflow (for similar question), documentation and the closes one I find is only CYPRESS_NO_COMMAND_LOG=1
. but, that is not the result what I am expecting. because when I do that, it just minimizing the runner and it's actually not running my test cases. hence, no result of all assertion.
The .should()
assertion uses the Cypress.log() method to output messages
This is the internal API for controlling what gets printed to the Command Log.
Useful when writing your own custom commands.
So you can use it to filter out the passing assertions.
In the following example, the <h1>
text content is successfully asserted, but the log is suppressed.
const originalLog = Cypress.log
Cypress.log = (log) => {
if (log.name === 'assert' && log.passed === true) return
originalLog(log)
}
cy.visit('https://example.com')
cy.get('h1')
.should('have.text', 'Example Domain')
If I add a second failing assertion, the details are logged
cy.get('h1')
.should('have.text', 'Example Domain')
.and('have.text', 'Cypress')