How to handle toggle button in cypress
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Looking at the demo page, material-ui – switches
Saves all the guess-work!
So, on that page to target the second toggle,
Note: It’s a toggle so
click()
will go from on to off and from off to on.Each test should be written such that you know the state of the form. The idea of conditional testing is not good – I mean, when you navigate to the page you don’t get a random toggle state. Most likely it starts off with the form hidden.
You tests would be
etc.