Skip to content
Advertisement

How can I do an if else in cypress?

I’m doing a test and I put a value in a texfield. If I get some data I want it to be found, otherwise I want “no data” to be found. This code doesn’t work… Why? And how can I do it?

JavaScript

Advertisement

Answer

You are trying to use the contains command from cypress to get a boolean, but it acts like an assertion itself. It tries to search something that contains the provided text and if gets no results, the test fails. I am doing conditional testing like this:

JavaScript
Advertisement