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

If statement not ignore the rest of the condition #41

Closed hiyunfengzhao closed 2 years ago

hiyunfengzhao commented 2 years ago

I have a button that has text "power off". when I run cy.get('button').eq(1).if().contains('power_off').click(), the code will run with and without if().

Then when i tried to run "power on" (power on doesn't exist) : cy.get('button').eq(1).if().contains('power_on').click()I got the below error:

AssertionError: Timed out retrying after 4000ms: Expected to find content: 'power_on' within the element: but never did.

Based on the example provided: cy.get('dialog#survey').if().contains('button', 'Close').click(), wouldn't the rest of the if command skipped since i don't have 'power on'?

hiyunfengzhao commented 2 years ago

Figured out, if() only checks the existence of the element before and not the rest. Closing.