How to Log in Cypress

How to Log in CypressWhen writing UI Tests in cypress you sometimes get stuck into the execution chain. Sometimes a simple console.log could help wonders. In this article, I will show you how to bring the log to your Cypress tests.
Categories cypresstesting
Hire me on Upwork!

The Cypress Log statement

Given the Cypress documentation, the Cy.Log has nearly the same functionality as the Console.log() statement.

The Only Problem is to use this functionality within the Cypress async API.

How to use Cypress Log in Complex statements

As you have the same problems as I do, the docs only cover simple problems. When it comes more difficult, you probably end up with multiple hours of digging into it.

I did this with Cy.log to log variables inside my Cypress tests, and it ended up all so simple.

As an Example, we will reuse the Code from my How to Access the Vuex state within Cypress article.

So all you have to do is, put your log inside a then of your call tree.

      .then(value => {
        cy.log("My koi: ", value);

Then you can access and print out the Variables as you are already familiar from Console.log.


I hope this small article about logging in to Cypress can help you to quickly debug your Cypress tests.

If you want to learn more about Cypress or testing in general, stay tuned for more articles.

Happy Debugging,


Recommended Products for you
recommended for you