Writing and Running Integration Tests in Empress Using Cypress

Introduction

Welcome to our comprehensive guide on using Cypress for writing integration tests in Empress. Cypress is a potent NodeJS full-stack testing framework that doesn’t rely on Selenium, making it an excellent tool for developers to ensure the robustness and reliability of their code.

What is Cypress?

Cypress is a front-end testing tool built for the modern web. It allows developers to build and run end-to-end tests within the browser, greatly simplifying the process and providing a more reliable and faster mechanism for testing applications.

Writing Integration Tests with Cypress

To write integration tests with Cypress in Empress, you will need to create a .js file in the cypress/integration directory.

Here’s an integration test example for checking the insertion of a To Do:

context('ToDo', () => {
    before(() => {
        cy.login('Administrator', 'admin');
        cy.visit('/desk');
    });

    it('creates a new todo', () => {
        cy.visit('/app/todo/new-todo-1');
        cy.fill_field('description', 'this is a test todo', 'Text Editor').blur();
        cy.get('.page-title').should('contain', 'Not Saved');
        cy.get('.primary-action').click();
        cy.visit('/desk#List/ToDo');
        cy.location('hash').should('eq', '/app/todo');
        cy.get('.list-row').should('contain', 'this is a test todo');
    });
});

In this test, we are emulating the process of creating a To Do item in the application. We begin by logging into the application, then visiting the To Do creation page (/app/todo/new-todo-1). We then fill in the description of the To Do item and ensure that it is saved and visible in the To Do list.

Running Cypress Tests Locally

Cypress uses any Chromium-based browser installed on your system to run tests. Each app has its own Cypress test suite.

To run tests for the frappe app, for instance, you would run the following commands:

cd ~/frappe-bench/apps/frappe
yarn cypress:open

This will open the Cypress Electron shell, where you can choose to run any test manually or execute all of the tests.

Concluding Thoughts

Cypress is a powerful tool that can greatly enhance the efficacy and efficiency of your integration testing in Empress. By incorporating Cypress into your development workflow, you can ensure that your code is robust, reliable, and ready for deployment. Happy coding!