Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout not triggering fail event #6829

Closed
averri opened this issue Mar 24, 2020 · 3 comments
Closed

Timeout not triggering fail event #6829

averri opened this issue Mar 24, 2020 · 3 comments

Comments

@averri
Copy link

averri commented Mar 24, 2020

Current behavior:

The fail event is not being captured when a test fails due to timeout.

Desired behavior:

The fail event should be captured when a test fails due to timeout.

Test code to reproduce

  cy.on('fail', () => {
    // This code will never be reached.
    cy.log('Ignoring this fail.')
    return false
  })

cy.get('div#submit').click({timeout: 1000})  // This should timeout. Make the button disabled to reproduce the timeout.

Versions

cypress 4.2.0, Windows 10.

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Mar 25, 2020

Ok, so this is likely due to the difference between cy.on and Cypress.on explained here: https://on.cypress.io/catalog-of-events#Cypress (It's hard to be certain because you did not specify where your cy.get() is being called in an it.)

As a side note, you cannot call cy commands within the event listeners. #6316

cy.on will only listen to events within the specific test whereas Cypress.on will listen to all events across tests.

Cypress.on('fail', () => {
  // This code will run for any failure in any test
  console.log('Cypress.on: Fail event')
  return false
})

it('test', () => {
  cy.on('fail', () => {
    // This code will run for this test failure
    console.log('cy.on: Fail event')
    return false
  })

  cy.visit('index.html')
  cy.get('#btn').click({ timeout: 1000 })
})

Screen Shot 2020-03-25 at 4 36 23 PM

Please comment if you have an example outside of this where it is not working and we will consider reopening.

@averri
Copy link
Author

averri commented Mar 25, 2020

Hi @jennifer-shehane, this could be caused by a 3rd party plugin. I have added more examples here: badeball/cypress-cucumber-preprocessor#348

@jennifer-shehane
Copy link
Member

Yeah, that may be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants