bahmutov / cypress-if

Easy conditional if-else logic for your Cypress tests when there is no other way
https://cypress.tips/courses/cypress-plugins
96 stars 12 forks source link

will this work in before hooks and in custom commands? #51

Open bgk17 opened 1 year ago

bgk17 commented 1 year ago

I'm trying to detect if I'm logged in and if so, log out in a before hook. I put it in my custom login command. It's failing when it can't find an element (which I would think would just continue to the then())

bahmutov commented 1 year ago

I don't think I have enough information to answer this question

bgk17 commented 1 year ago

can I use cypress-if in my before hook to check if i'm logged in, and if so, log myself out?

bahmutov commented 1 year ago

before hook runs only once before all tests. You probably want to run it in beforeEach hook

bgk17 commented 1 year ago

Yes, sorry. But that scenario is perfectly fine, right? When I was trying before it was failing to find the element and then doing my .then(), which was confusing me. I will check again.