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

Repetitive actions execution question #1976

Closed
uoziod opened this issue Jun 18, 2018 · 4 comments
Closed

Repetitive actions execution question #1976

uoziod opened this issue Jun 18, 2018 · 4 comments

Comments

@uoziod
Copy link

uoziod commented Jun 18, 2018

I have some repetitive actions in my tests, so I moved them to a separate functions out of actual tests and calling them from tests assuming that they'd be executed just as bunch of commands:

describe( "Page one", () => {
    function one() {
      cy.get("...")
      ...
    }

    function two() {
      cy.get("...")
      ...
    }

    it( "Test 1", async () => {
      cy.get("...")

      one();
      two();
    }

    it( "Test 2", async () => {
      cy.get("...")

      one();
      two();
    }

    ...

Although in this particular case I see that functions one and two will be called only in Test 2, whereas Test 1 will run only cy.get("..., then Test 2 will start straight away.

Might be that I'm just approaching the problem from an incorrect way.
In any case, suggestions are much appreciated)

@uoziod uoziod changed the title Repetitive actions executions question Repetitive actions execution question Jun 18, 2018
@uoziod
Copy link
Author

uoziod commented Jun 20, 2018

Guys, is this expected behavior? Should I elaborate on details?
Seems like a bug to me, unless I doing it wrong.

Once I commenting out Test 2 section it works as expected - rules from my functions are executing.

@kuceb
Copy link
Contributor

kuceb commented Jun 20, 2018

@uoziod is there a reason for async ? You shouldn't need that

@uoziod
Copy link
Author

uoziod commented Jun 20, 2018

Indeed. I've been using them for other purposes, but refactored code and now it works fine. Thanks for pointing out!

@uoziod uoziod closed this as completed Jun 20, 2018
@brian-mann
Copy link
Member

brian-mann commented Jun 20, 2018

@uoziod yes, @bkucera is right, you were mixing up async / Promise code with Cypress, which is never necessary. You also weren't returning like this return one() which would have meant the promisifed async test callback would not have awaited.

This is one of the reasons I don't like the idea of conforming to async/await. It's not necessary in Cypress, there's no reason to enforce it, and it creates a confusing mismatch between the two styles.

You can read more here: #1417

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

No branches or pull requests

4 participants