Why is cypress present on both, the node server and the browser (client)?

Viewed 42

The node server (a part of the OS) helps the node browser to run and hence a web app in it. Now, If I look at the architecture of cypress, it seems that it is present on both the sides: Node Server and the Browser. I do not understand why there is a need for it to exist on both the sides?

What role does it play in the browser, and in the Node server?

1 Answers

Regarding documentation:

Cypress is executed in the same run loop as your application. Behind Cypress is a Node.js server process. Cypress and the Node.js process constantly communicate, synchronize, and perform tasks on behalf of each other. Having access to both parts (front and back) gives us the ability to respond to your application's events in real time, while at the same time work outside of the browser for tasks that require a higher privilege.

In practice, Cypress in the browser does most of the "users" actions, clicking button, typing text, etc...

And Cypress in node what you often do is:

  • Seeding your test database.
  • Storing state in Node that you want persisted between spec files.
  • Performing parallel tasks, like making multiple http requests outside of Cypress.
  • Running an external process.

Here you can see how you can run code from Node using task https://docs.cypress.io/api/commands/task#Syntax

    cy.window().then(() => console.log('this will be output to the browser !'))
    cy.task('log', 'this will be output to the node server !')
Related