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

before() function is executed twice (doubled) in two tests in one test suite #30902

Open
gustawx opened this issue Jan 17, 2025 · 0 comments
Open

Comments

@gustawx
Copy link

gustawx commented Jan 17, 2025

Current behavior

I have a simple test where I do a log in and next I send a http request. What happens is that before() function is executed twice (is doubled) before two tests in this test suite - so overall it runs 4 times.

Observation:

  1. When I run this test from Cypress runner (UI), it fails ALWAYS for the first time after opening the runner, next runs are fine
  2. Because first runs always fail - in the pipeline or when running from cli it always fails
  3. In the second test in this test suite I log in in UI and despite the fact that the domain is the same as baseUrl, test is restarted and state is lost, e.g. variables "lose" it's values! - this is causing test to fail
  4. The fact that before is executed twice per test seems to be irrelevant with the fact that it's being executed in two tests in this test suite because even if I run the test for the second time (so it passes and test doesn't restart) before is executed twice before first test

screenshot on first run:

Image

next run:

Image

Desired behavior

  1. before executed only once and before one test
  2. test not restarted
  3. state not lost

Test code to reproduce

due to company policy I can't paste the code but it's pretty simple:
test suite:

  • test 1: send some API requests
  • test 2: log in in UI and next send API request

in e2e.ts I defined common before() function

Cypress Version

13.17.0

Node version

v20.14.0

Operating System

Microsoft Windows 10 Enterprise - 10.0.19045 Build 19045

Debug Logs

Other

No response

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

1 participant