What is Cypress?

In the following, I would like to introduce the Cypress framework. It is easy to integrate Cypress into existing projects to enable tests to be implemented quickly.
Created with Lunacy

What is Cypress?

by Alex Fredekind

In the following, I would like to introduce the Cypress framework. It is easy to integrate Cypress into existing projects to enable tests to be implemented quickly. Furthermore, the syntax of the framework is easy to learn to provide a comfortable way of writing tests.

The tests in Cypress are formulated in JavaScript and are intended for the frontend. Cypress also offers an interactive interface to execute tests and offer functions for debugging.

Implementation of tests

When implementing a test for an existing component, problems arise if the formulation of tests has not been considered during implementation of the component:

  • Unclear references
  • Difficult debugging
  • Future expenses

These arise because without adaption, references must be used which already exist in the code. For example, imagine a class which will be used to reference an element. If this class is changed in a future adaption, the element is no longer referenced which results in failing tests. Unique reference also facilitates debugging, because it is clear which element caused a problem. In this way, future expenses can also be avoided. Tests do not have to be submitted later and bugs can be caught at an early stage. Cypress uses the data-cy property to reference elements.

describe('Add Dialog Test', () =>{
    it('inputs a text and check if element contains text', () =>{
        cy.get('[data-cy=inputField]').type('test')
        cy.get('[data-cy=output]').should('have.text', 'test')
    })
})

 

Comparison Cypress and Selenium

In addition, it is of interest to compare Cypress with another framework to decide which framework to use. The decision which of these two frameworks should be used depends on the requirements. We are comparing Selenium and Cypress. The programming language in which the tests must be written must be considered to decide. Cypress tests are written in Javascript while Selenium offers different languages for writing tests. Also relevant are the supported browsers. For example Selenium supports Safari, which is not the case for Cypress but it is planned to add Safari support.

More on this topic can be found here on heise.de.

 

 

back