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 and beforeEach in supportFile - unexpected behavior during 'run all specs' #4703

Closed
MUTOgen opened this issue Jul 12, 2019 · 9 comments
Labels
stage: ready for work The issue is reproducible and in scope stale no activity on this issue for a long period topic: hooks ↪ type: unexpected behavior User expected result, but got another

Comments

@MUTOgen
Copy link

MUTOgen commented Jul 12, 2019

Current behavior:

before and beforeEach executed from support file seems unlogical.
As docs described, beforeEach runs before each test in each spec file.
In this way, I expect to see before hook before starting each spec file. But it doesn't, it runs only once.

Снимок экрана 2019-07-12 в 11 22 22

Desired behavior:

Seems like more clear to run before hook before each spec file, like each before hook from spec file does.

Steps to reproduce: (app code and test code)

I just pasted this piece of code into support/index.js

before(() => {
    cy.log('Run before');
});

beforeEach(() => {
    cy.log('Run before each');
});

Versions

Cypress: 3.3.1
MacOs: 10.14.5
Google Chrome: 75.0.3770.100

@Songyu-Wang
Copy link
Contributor

you can also put before() and beforeeach() inside spec files...

@MUTOgen
Copy link
Author

MUTOgen commented Jul 13, 2019

you can also put before() and beforeeach() inside spec files...

Sure, but I'd like to extract some logic to support file. I don't really want to copy-paste before hook to each spec file.

@Songyu-Wang
Copy link
Contributor

I'm so confused… If you have generic before and before each, you put it in support file, cypress will apply them to the spec you wanna run… if you have unique logic for each spec file, you put before and before each into particular spec files. I don't see anything wrong with that.

And based on the screenshot you have, you fixture loading got ran for each spec. What is the issue?

@MUTOgen
Copy link
Author

MUTOgen commented Jul 13, 2019

I'm so confused… If you have generic before and before each, you put it in support file, cypress will apply them to the spec you wanna run… if you have unique logic for each spec file, you put before and before each into particular spec files. I don't see anything wrong with that.

And based on the screenshot you have, you fixture loading got ran for each spec. What is the issue?

That is what I'm talking about. I want to put some generic code into support file as before hook.
In my case it's just cy.log('Run before');.
Then I want to run all spec files at once (like CI does, for example). As you can see, I got a log message only once. When For non-registered users runs, there is no log message. I expected the same before hook there.
Fixtures loading is ok, b/c I copy-pasted it in each spec file.

@Songyu-Wang
Copy link
Contributor

Oh, I see the issue now… sorry I didn't realize there are two before defined by you. Sorry… please ignore whatever I said… I think you are right

@jennifer-shehane
Copy link
Member

This falls under this body of work: #1586

@jennifer-shehane jennifer-shehane added the type: unexpected behavior User expected result, but got another label Jul 15, 2019
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Jul 15, 2019
@MUTOgen
Copy link
Author

MUTOgen commented Jul 15, 2019

This falls under this body of work: #1586

Are there any estimates about finishing this?

@jennifer-shehane jennifer-shehane changed the title Before and beforeEach - unexpected behavior Before and beforeEach in supportFile - unexpected behavior during 'run all specs' Dec 15, 2020
@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 17, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: ready for work The issue is reproducible and in scope stale no activity on this issue for a long period topic: hooks ↪ type: unexpected behavior User expected result, but got another
Projects
None yet
Development

No branches or pull requests

4 participants