santhoshshetty / cypress-toolkit

0 stars 0 forks source link

Cypress Test Automation

This is a demo test framework developed with a goal to have end to end testing and component testing capabilities with the best possible standards covering most of the features and build as a template or prototype that anyone can incorporate in the projects.

Testing tools and Technologies:

Getting Started:

Installation:

  1. Download and Install Node.js and NPM:

    • Verify Installation: To verify that Node.js and NPM are installed successfully, open your terminal or command prompt and run the following commands:
      node -v
      npm -v
  2. Clone the project https://github.com/santhoshshetty/cypress.git

  3. Open the project in your favorite editor.

  4. Install Project Dependencies: Navigate to the project directory using the terminal and run the following command to install the project dependencies:

    npm install
  5. External Cypress Installation: If you want to set up Cypress externally, use the following npm command to install Cypress as a dev dependency. This is optional and can be skipped if completed the step 4:

    npm install cypress --save-dev
  6. Run Cypress: Verify your Cypress installation by launching the Test Runner:

    npx cypress open

    If the setup was successful, the Test Runner will be displayed. From here, you can choose the specific feature to run and select the preferred browser. Navigate to the test runner, select the option 'E2E Testing', choose the feature you want to execute, and then select your desired browser from the dropdown to visualize the test execution.

    Alternatively, to run the tests via CLI in headless mode:

    npx cypress run
  7. Run specific Cypress Tests: By default, Cypress runs all the specs in the project. If you want to run a specific spec, use the following command:

    npx cypress run --spec path/to/your/spec/file.feature

Cypress Configuration and File Structure

Below you'll find a list of default Cypress files included in the project:

Tests development

Writing Test Cases in BDD Format:

When creating your end-to-end (E2E) test cases, use the Behavior-Driven Development (BDD) format within the feature file. BDD encourages collaboration among stakeholders by providing a shared language for expressing requirements and test scenarios.

Follow these guidelines:

Example:

Feature: Visit and validate

As a user, I want to have an E2E test example.

Scenario: Visit and validate Cypress TODO website
  When I visit Cypress TODO website
  Then I validate TODO list

Build

Within the root project, you'll find a workflows folder containing the workflows tailored for pipeline runs. The workflow is encapsulated in a file named cypresstest.yml. It orchestrates the creation of an Ubuntu container, configuration of Cypress, and execution of smoke tests.