bahmutov / cypress-if

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

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

Open bgk17 opened 2 years ago

bgk17 commented 2 years 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 2 years ago

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

bgk17 commented 2 years 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 2 years ago

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

bgk17 commented 2 years 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.