Skip to content

Instantly share code, notes, and snippets.

@przemuh
Created December 18, 2019 08:32
Show Gist options
  • Save przemuh/3b8610d3aef29f0bd8b01ee3f2b4618a to your computer and use it in GitHub Desktop.
Save przemuh/3b8610d3aef29f0bd8b01ee3f2b4618a to your computer and use it in GitHub Desktop.
Cypress.on('test:after:run', (test, runnable) => {
if (test.state === 'failed') {
let item = runnable
const nameParts = [runnable.title]
// Iterate through all parents and grab the titles
while (item.parent) {
nameParts.unshift(item.parent.title)
item = item.parent
}
const fullTestName = nameParts
.filter(Boolean)
.join(' -- ') // this is how cypress joins the test title fragments
const imageUrl = `screenshots/${
Cypress.spec.name
}/${fullTestName} (failed).png`
addContext({ test }, imageUrl)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment