HOV QA Engineers
  • ๐Ÿ”HOV QA Engineers
  • AGILE TESTING
    • ๐Ÿ’ปCSS elements for QA
    • ๐Ÿ›ซOn-boarding QA
    • ๐ŸคTesters Communications, Task and Responsibilities
    • โ™ป๏ธSoftware Testing Life cycle
    • ๐Ÿ““Test Plan
    • ๐ŸŽŸ๏ธKanban board and ticket flows
    • ๐Ÿ““User Stories and Acceptance Criteria
    • ๐Ÿ‘ฃGherkin syntax
    • ๐Ÿค–Test Design
    • ๐Ÿ“…Test Strategy
    • ๐Ÿ‘ฌTypes of Testing strategy
    • ๐ŸงชTesting types
    • ๐Ÿ›Bug and Bug life Cycle
    • โœ๏ธManual Testing
    • Automation testing
    • ๐Ÿ‘ทโ€โ™‚๏ธE2E Testing
    • E2E testing best practices
    • Accessibility testing
    • Performance testing
    • Mobile Testing
  • Tools and Guidelines
    • Software QA Engineer Roadmap
    • ๐Ÿ’ปSetup Cypress v10 E2E testing
    • ๐ŸงชSetup End to end test with Cypress test suite
    • Setup Performance test with k6
    • API testing with postman
    • Building GitHub Action part 1
    • โœ๏ธPlaywright + Cucumber
  • Training Videos
    • SQA Trainings
  • Research
    • ๐Ÿ“ฑMobile Automation with Appium
      • Setup Project and Configuration (Android)
    • ๐ŸŽญPlaywright - Web Apps E2E Testing Tool
      • Setup Project and Configuration (Android)
    • Testing Library
  • PROJECTS
    • Page 2
    • Opexa
    • ๐Ÿ“ฃIdentifi
      • โš–๏ธSQA Metrics and Testing progress
      • ๐ŸงชManual testing
        • WEB
          • Sanity Testing
          • Regression Test cases
          • Credentials and URLs
        • Android
          • Sanity Testing
          • Regression Testing
          • End to end Testing
          • Credentials
        • IOS
          • Sanity Testing
          • Regression Testing
      • ๐Ÿ“”API Testing
      • ๐Ÿค–Web Automation
        • E2E Automation Test Plan
        • Web Automation Setup
          • ๐ŸšงSetup WSL2 Environment for Windows
          • ๐Ÿ—๏ธSetup local Environment (Linux/Ubuntu)
        • Regression Testing Coverage
        • Sanity Testing Coverage
      • ๐ŸŽญPerformance Testing
        • K6 Test Runs
      • ๐Ÿ“ดMobile Automation
        • Mobile Automation Test Plan
        • Identifi Mobile Automation Setup
      • Page 1
    • ๐Ÿ–ผ๏ธsubsit
      • Test plan
      • Smoke Test cases
      • ๐ŸงชTest Scenarios
      • ๐Ÿ•ธ๏ธWeb Automation
    • ๐ŸงตThreadSync
      • Test Plan
    • ๐Ÿ‘๏ธUpWatch
      • Product Requirement
      • Test plan
      • Monitoring & Bug Reporting
      • E2E Test
        • E2E UpWatch Test
      • E2E QA Automation
    • ๐ŸŽฒWallet
      • ๐ŸงฌTest Plan
      • ๐Ÿ’ปE2E Wallet Automation Test Plan
      • ๐Ÿ“–E2E Test Automation Docs
      • ๐Ÿ“‘Credentials| Urls
      • ๐Ÿ“šWallet Feature List
    • ๐Ÿ‘จโ€๐Ÿ’ปDevLuvs
      • ๐ŸงชTest Cases
      • ๐Ÿ”‘Credentials For Automation
        • ๐Ÿค–Automation Test Cases
      • ๐Ÿ“ŠAutomation Board
    • โš™๏ธMehira
      • ๐Ÿ•ธ๏ธWeb Automation
      • Sanity Testing Document
      • How to start running Mehira application from your local using Docker engine via Ubuntu platform
Powered by GitBook
On this page
  • Installing
  • Now that cypress is installed we can proceed to installation of cucumber plugins and Typescript.
  • Next is to install Cypress cucumber preprocessor
  • Installing of bundler Browserify and Webpack
  • Write a test
  1. Tools and Guidelines

Setup Cypress v10 E2E testing

Installing

First is navigate to your intended directory and initialized npm by:

npm init

This will create a package.json file on your directory.

Next is to install Cypress via npm:

npm install cypress --save-dev

This will install Cypress locally as a dev dependency for your project.

Running the test with the command below will open the cypress test window:

npx cypress open

Notice that node_modules and cypress folder will be added in the directory as well as other files like cypress-config.js

Now that cypress is installed we can proceed to installation of cucumber plugins and Typescript.

To install Typescript, execute this command:

npm install typescript --save-dev

Initialized typescript by running:

npx tsc --init

This is to define and create your tsconfig file.

Change your tsconfig.json with this configuration:

{
  "compilerOptions": {
    "target": "es2020",

    "module": "commonjs",
    "strict": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "noImplicitAny": true,
    "removeComments": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowJs": true,
    "types": ["cypress","node"],
    "lib": ["es2020", "dom"]
  },
  "include": ["**/*.ts"]
}

Next is to install Cypress cucumber preprocessor

npm install @badeball/cypress-cucumber-preprocessor

In version 10, plugins File is removed because Cypress now supports JavaScript and TypeScript configuration files, a separate "plugins file" (which used to default to cypress/plugins/index.js)

Global step definitions exaple

{
  "name": "my project",
  "depdendencies": {},
  "devDepdendencies": {},
  "cypress-cucumber-preprocessor": {
    "stepDefinitions": "cypress/support/step_definitions/**/*.{js,ts}"
  }
}

Step definitions besides scenario

{
  "name": "my project",
  "depdendencies": {},
  "devDepdendencies": {},
  "cypress-cucumber-preprocessor": {
    "stepDefinitions": "cypress/integration/[filepath].{js,ts}"
  }
}

Step definitions in a directory besides the scenario

{
  "name": "my project",
  "depdendencies": {},
  "devDepdendencies": {},
  "cypress-cucumber-preprocessor": {
    "stepDefinitions": "cypress/integration/[filepath]/**/*.{js,ts}"
  }
}

Combination of all of the above (default)

{
  "name": "my project",
  "depdendencies": {},
  "devDepdendencies": {},
  "cypress-cucumber-preprocessor": {
    "stepDefinitions": [
      "cypress/integration/[filepath]/**/*.{js,ts}",
      "cypress/integration/[filepath].{js,ts}",
      "cypress/support/step_definitions/**/*.{js,ts}"
    ]
  }
}

Installing of bundler Browserify and Webpack

Browesrify-ts installation:

npm install --save-dev @cypress/browserify-preprocessor

And add this under cypress-config.ts file.

import { defineConfig } from "cypress";
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";
import browserify from "@badeball/cypress-cucumber-preprocessor/browserify";

async function setupNodeEvents(
  on: Cypress.PluginEvents,
  config: Cypress.PluginConfigOptions
): Promise<Cypress.PluginConfigOptions> {
  await addCucumberPreprocessorPlugin(on, config);

  on(
    "file:preprocessor",
    browserify(config, {
      typescript: require.resolve("typescript"),
    })
  );

  // Make sure to return the config object as it might have been modified by the plugin.
  return config;
}

export default defineConfig({
  e2e: {
    specPattern: "**/*.feature",
    setupNodeEvents,
  },
});ter

Webpack-ts installation:

npm install --save-dev @cypress/webpack-preprocessor
npm install --save-dev ts-loader

And add this under cypress-config.ts file.

import { defineConfig } from "cypress";
import webpack from "@cypress/webpack-preprocessor";
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";

async function setupNodeEvents(
  on: Cypress.PluginEvents,
  config: Cypress.PluginConfigOptions
): Promise<Cypress.PluginConfigOptions> {
  await addCucumberPreprocessorPlugin(on, config);

  on(
    "file:preprocessor",
    webpack({
      webpackOptions: {
        resolve: {
          extensions: [".ts", ".js"],
        },
        module: {
          rules: [
            {
              test: /\.ts$/,
              exclude: [/node_modules/],
              use: [
                {
                  loader: "ts-loader",
                },
              ],
            },
            {
              test: /\.feature$/,
              use: [
                {
                  loader: "@badeball/cypress-cucumber-preprocessor/webpack",
                  options: config,
                },
              ],
            },
          ],
        },
      },
    })
  );

  // Make sure to return the config object as it might have been modified by the plugin.
  return config;
}

export default defineConfig({
  e2e: {
    specPattern: "**/*.feature",
    setupNodeEvents,
  },
});

Install cucumber-json-formatter

npm install -g @deepakvishwakarma/cucumber-json-formatter

And add this at package.json

  "cypress-cucumber-preprocessor": {
    "json": {
      "enabled": true,
      "formatter": "cucumber-json-formatter"
    }
  }

Now that everything are set, we can start writing our test.

Write a test

# cypress/e2e/duckduckgo.feature
Feature: duckduckgo.com
  Scenario: visiting the frontpage
    When I visit duckduckgo.com
    Then I should see a search bar
// cypress/e2e/duckduckgo.ts
import { When, Then } from "@badeball/cypress-cucumber-preprocessor";

When("I visit duckduckgo.com", () => {
  cy.visit("https://www.duckduckgo.com");
});

Then("I should see a search bar", () => {
  cy.get("input").should(
    "have.attr",
    "placeholder",
    "Search the web without being tracked"
  );
});

Running a test in browserless mode:

npx cypress run --browser chrome

Running the test with browser that directs into the spec file:

npx cypress run --browser chrome --e2e

PreviousSoftware QA Engineer RoadmapNextSetup End to end test with Cypress test suite

Last updated 2 years ago

Support for the plugins file has been removed, and it has been replaced with the new and config options. If you wan't to read further about the depreciation of plugins file follow this .

Write Gherkin documents and add a file for type definitions with a corresponding name (read more about how step definitions are resolved in ). Reading is highly recommended.

For further details and changes about the migration, your can read it in .

๐Ÿ’ป
setupNodeEvents()
devServer
link
docs/step-definitions.md
docs/cucumber-basics.md
here