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

Click and type events in after or afterEach hook don't work if one test fails #2831

Open
StanFisher opened this issue Nov 24, 2018 · 39 comments
Labels
E2E Issue related to end-to-end testing prevent-stale mark an issue so it is ignored by stale[bot] topic: hooks ↪ Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: bug

Comments

@StanFisher
Copy link

StanFisher commented Nov 24, 2018

Current behavior:

Any click event in the after block fails if one of the tests in an it block fails.

Desired behavior:

Click events in the after block should succeed even if there are tests that fail.

Steps to reproduce:

I forked the cypress-tiny-test repository and set up a reproducible example in the latest commit.
https://github.com/StanFisher/cypress-test-tiny

Here's the commit containing the failing after block.
StanFisher/cypress-test-tiny@c185242

Notice that if the failing test is changed to succeed, then the two click events in the after block succeed.

Versions

Cypress 3.1.2
macOS Mojave 10.14.1
Chrome 70.0.3538.102

@jennifer-shehane jennifer-shehane added type: feature New feature that does not currently exist stage: proposal 💡 No work has been done of this issue labels Nov 26, 2018
@StanFisher

This comment has been minimized.

@bahmutov

This comment has been minimized.

@jennifer-shehane jennifer-shehane added type: bug stage: ready for work The issue is reproducible and in scope and removed type: feature New feature that does not currently exist stage: proposal 💡 No work has been done of this issue labels Dec 5, 2018
@jennifer-shehane

This comment has been minimized.

@jennifer-shehane jennifer-shehane added stage: investigating Someone from Cypress is looking into this and removed stage: ready for work The issue is reproducible and in scope labels Dec 5, 2018
@jennifer-shehane

This comment has been minimized.

@jennifer-shehane jennifer-shehane changed the title Click events in "after" block don't work if one test fails Click events in after or afterEach hook don't work if one test fails Feb 15, 2019
@jennifer-shehane jennifer-shehane added stage: ready for work The issue is reproducible and in scope topic: hooks ↪ and removed stage: investigating Someone from Cypress is looking into this labels Feb 15, 2019
@cypress-bot cypress-bot bot added stage: backlog and removed stage: ready for work The issue is reproducible and in scope labels Feb 15, 2019
@immohsin
Copy link

immohsin commented Mar 6, 2019

Any workaround for this one?
After i run spec file, i want to cleanup few thing in case if anything fails.

@toannguyen83
Copy link

I'm having the same issue. In the afterEach i need to perform cleanup after each test, undoing certain UI actions, but if the test failed, any action in afterEach doesn't work properly.

I have to do a weird workaround for now, having my clean up code in beforeEach, but, it won't perform clean up on the last test, so I need to also add a dummy test to the very end.

@NareshGuduri

This comment has been minimized.

@jennifer-shehane jennifer-shehane added stage: ready for work The issue is reproducible and in scope and removed stage: backlog labels Aug 26, 2019
@jennifer-shehane

This comment has been minimized.

@Aishwarya-U-R
Copy link

Is this not fixed yet? Really need an approach to run a few code even if tests fail!
Blocking a whole suite of cases for us!

@joselee
Copy link

joselee commented Feb 18, 2022

Having the same issue in afterAll() when a testcase fails! I'm using cypress version 8, and have been relying of afterAll() to perform cleanup after test execution.

@cypress-bot cypress-bot bot added stage: backlog and removed stage: ready for work The issue is reproducible and in scope labels Apr 29, 2022
@kzahozhy
Copy link

Still expirience this issue in version 9.7.0
Need the fix so badly, cause it blocks bunch of tests.
In fact not only click or type is not working, but also no waiting for element is applied, all should checks are executed once and imediately.

@DevrathsinghMusikaar
Copy link

Facing same issue in version 10.3.1
The after hook don't work if one test fails.
The after hook doesn't recognize the properties like find element in DOM and also not able to click
Hope to see a fix soon.
Thank you Cypress community
image

@JSoet
Copy link

JSoet commented Aug 16, 2022

I'm not sure if I ran into the same issue, but I had a problem with a couple clicks not working in an afterEach (they seemed to work, cypress didn't say that they failed, but then the action in the UI didn't happen) and I added force: true and that resulted in them working.

@shreejan-regmi01
Copy link

Problem still exists in v10.2.0

@BathiyaL
Copy link

BathiyaL commented Dec 1, 2022

As a temp solution I just add another it hook for data cleanup (not nice)
Is there any workaround for this ?

@kzahozhy
Copy link

kzahozhy commented Dec 1, 2022

The only way for now is to add dummy test which will always be passed.

@vbukin
Copy link

vbukin commented Feb 8, 2023

why has not it fixed since 2018? Its really annoying bug ^(
how to catch errors in a running test and delete the created data?

@mishasgit
Copy link

I still have the issue in 12.7 , but there is a workaround you can use .click({ force: true }) it worked for me

@nagash77 nagash77 added the prevent-stale mark an issue so it is ignored by stale[bot] label Apr 3, 2023
@nagash77 nagash77 added E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. and removed routed-to-e2e labels Apr 19, 2023
@gabriel-syntax
Copy link

Can we please get a fix for this?

@Andor71
Copy link

Andor71 commented Apr 22, 2023

Is this a joke, it passed like 4 years and haven't been fixed since ?

@DenisBik
Copy link

DenisBik commented May 30, 2023

Hello! I encountered the same thing. If test fails - some of the components stop reacting to click() in afterEach hook. Even "force click" is not helping... Cypress V12.7. Are there any more suggestions? I have a lot of tests and they are all failing because of this issue...

@ghost
Copy link

ghost commented Jul 31, 2023

I do encounter this issue too. After some investigation, here are some workarounds which works for me:

For click() API, Cypress.$(cssSelector).trigger('click') can be used;

For type() API, a custom function setInputValue() can work (for React);

const setInputValue = function (input: any, value: any) {
  const lastValue = input.value;
  input.value = value;
  const event: any = new Event('input', { bubbles: true });
  // Hack React 15
  event.simulated = true;
  // Hack React 16
  const tracker = input._valueTracker;
  if (tracker) {
    tracker.setValue(lastValue);
  }
  input.dispatchEvent(event);
};

And, cy.wait() works in this situation, so you can use it to wait if you have to.

@Jonamarti
Copy link

I understand using the after hook is discouraged (https://docs.cypress.io/guides/references/best-practices#Using-after-or-afterEach-hooks) and we actually clean up right before each test run, but I find it quite frustrating having to launch the tests again and stop it 1 second later only for the app (DDBB) to have the initial state. Furthermore, I dont get why the code fails in the after hook even if discouraged, it's still a bug, right? Thanks!

@darrenclose
Copy link

5 years with no solution is quite a let down as this is causing a major issue in data cleanup for us. Our initial approach was to have it clean up on a blank test to start however if the previous set ran without issue then there would be no data to clean and thus fail the afterEach hook thus failing the rest of the run. So frustrating

@goska-malaga
Copy link

I actually cannot use force click as my after hook fails on loading a page and checking that intercepted call has status 200, it just doesn't wait as expected. I spent half a day thinking I must have made a mistake, but same code works if test pass and it actually looks like same rootcause.
Considering that conditional actions are not a strength in Cypress I have hard time thinking how to clean up state before not to mention doing revolution to delete things from db (that could be a benefit but I am not sure we have ability to do that currently)

@srclay
Copy link

srclay commented Feb 1, 2024

I've been having the same issue for days! Just stumbled across the workaround to add a test to the end of the run that will always pass. This solves the problem for the after all hook. I'm not using after each so can't comment on that. Needs to be fixed though!

@abrugaro
Copy link

This issue is still reproducible on Cypress 13.6.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing prevent-stale mark an issue so it is ignored by stale[bot] topic: hooks ↪ Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: bug
Projects
None yet
Development

No branches or pull requests