-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
I've been playing around with ways of defining reusable helpers (blog post coming) and have been using the Cypress log API and passing { log: false }
to allow control of the log output of these helpers/commands. This has been useful, but there are some times that I want to dive into that abstraction (most likely on failure) to see what step of the helper failed.
I think a concept of a group
would be useful here. Instead of passing { log: false }
to every encapsulated command, having a group would help a lot more
Current behavior:
// This will work on https://github.com/cypress-io/cypress-example-todomvc
export const createTodo = (name) => {
const log = Cypress.log({
name: 'createTodo',
message: name,
consoleProps() {
return {
'Inserted Todo': name,
}
}
})
cy.get('.new-todo', { log: false }).type(`${name}{enter}`, { log: false })
return cy
.get('.todo-list li', { log: false })
.contains('li', name.trim(), { log: false })
.then(($el) => {
log.set({ $el }).snapshot().end()
})
}
// to use this helper:
createTodo('Learn the Cypress Log API')
.then(console.log) // logs the created todo element from the TodoMVC Cypress example
Proposed behavior:
export const createTodo = (name) => {
const group = Cypress.group({
name: 'createTodo',
message: name,
consoleProps() {
return {
'Inserted Todo': name,
}
}
})
cy.get('.new-todo').type(`${name}{enter}`)
return cy
.get('.todo-list')
.contains('li', name.trim())
.then($el => { group.set({ $el }).snapshot().end() })
Matching the log API seems like a logical choice. In the UI it would show createTodo
with the logging the same as the Current behavior
example, but would have an arrow that would expand to the grouped commands. This would both simplify creating custom command output (don't have to pass { log: false }
to everything) as well as make it easier to understand that's going on under the hood of a custom command. The group would be collapsed by default and expanded if a nested command failed.