DEV Community

Khairun Nahar Nowrin
Khairun Nahar Nowrin

Posted on • Updated on

End-to-End Testing With Cypress

Initial steps

  1. Download vs code- https://code.visualstudio.com/download
  2. Clone repository from github- git clone git@github.com:KhairunNaharNowrin/End-to-End-Testing-With-Cypress.git
  3. Now open the project folder in VS Code.

Set the environment

  1. Initialize a New Node.js Project: Open a terminal, navigate to your project directory, and run the following command to initialize a new Node.js project:
npm init -y
Enter fullscreen mode Exit fullscreen mode

Image description

  1. Install Cypress: Install Cypress as a development dependency in your project using npm:
npm install cypress --save-dev
Enter fullscreen mode Exit fullscreen mode

3.Opening Cypress: After the installation is complete, you can open Cypress with the following command:

npx cypress open

Enter fullscreen mode Exit fullscreen mode
  • After run this command it will open cypress modal Image description
  • After click on Continue button it will open testing type modal. Select E2E Testing. Image description
  • After select the E2E testing it will oprn Configuration files modal. Click on "Continue" button.
    Image description

  • Select preferable browser and Start E2E Testing.
    Image description

  • After that select first spec
    Image description
    Image description
    Image description

  1. Opening Cypress: After the installation is complete, you can open Cypress with the following command:
npx cypress open

Enter fullscreen mode Exit fullscreen mode

This command will open the Cypress Test Runner, where you can write and run your tests.

Project Setup

  1. Disabling watchForFileChanges: false , in cypress.confiq.js improves performance and control by preventing automatic reloading of application files during test runs.
module.exports = {
  e2e: {
    watchForFileChanges: false,
    setupNodeEvents(on, config) {
      // implement node event listeners here

    },
  },
};

Enter fullscreen mode Exit fullscreen mode

Page Object Model (POM) pattern:

└── cypress
    ├── fixtures
    │   └── (static data files)
    ├── integration
    │   └── (test files)
    ├── plugins
    │   └── (Cypress plugins)
    ├── support
    │   ├── commands.js
    │   ├── index.js
    │   └── (other support files)
    ├── page objects
    │   ├── LoginPage.js
    │   ├── HomePage.js
    │   └── (other page object files)
    ├── utilities
    │   └── (utility functions)
    └── (other Cypress configuration files)


Enter fullscreen mode Exit fullscreen mode
  • fixtures: Contains static data files used by tests.
  • integration: Contains test files.
  • plugins: Contains Cypress plugins.
  • support: Contains helper functions, custom commands, and global configuration.
  • page objects: Contains page object classes representing different pages of the application.
  • utilities: Contains utility functions shared across tests.

Top comments (0)