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
  • In a nut Shell
  • TypeScript Support
  • How to run the tests
  1. Tools and Guidelines

Setup End to end test with Cypress test suite

PreviousSetup Cypress v10 E2E testingNextSetup Performance test with k6

Last updated 2 years ago

In a nut Shell

Cypress is a next generation front end testing tool built for the modern web. We address the key pain points developers and QA engineers face when testing modern applications.

We make it possible to:

Cypress is most often compared to Selenium; however Cypress is both fundamentally and architecturally different. Cypress is not constrained by the same restrictions as Selenium.

This enables you to write faster, easier and more reliable tests.

Cypress supports Linux Operating system as listed above.

  • Linux Ubuntu 12.04 and above, Fedora 21 and Debian 8 (64-bit only)

If you're using Linux, you'll want to have the required dependencies installed on your system.

We also have an official Docker container with all of the required dependencies installed.

For Ubuntu/Debian, do this first:

apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb

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. Notice that node_modules and cypress folder will be added in the directory as well as other files like cypress.json

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"]
}

To add Cucumber plugin used this command:

npm install --save-dev cypress-cucumber-preprocessor

Run GUI cypress

Add this configuration commands:

Add it to your plugins from this path cypress/plugins/index.js

const cucumber = require('cypress-cucumber-preprocessor').default

module.exports = (on, config) => {
  on('file:preprocessor', cucumber())
}

cypress.json

{
  "testFiles": "**/*.feature",
	"ignoreTestFiles": "*.ts",
}

Configuration

"cypress-cucumber-preprocessor": {
  "nonGlobalStepDefinitions": true
}

TypeScript Support

Install

Install the plug-in type definitions:

npm install --save-dev @types/cypress-cucumber-preprocessor

Without Webpack

If you want to use TypeScript, add this to your plugins/index.js:

const cucumber = require("cypress-cucumber-preprocessor").default;
const browserify = require("@cypress/browserify-preprocessor");

module.exports = (on) => {
  const options = browserify.defaultOptions;

  options.browserifyOptions.plugin.unshift(['tsify']);
  // Or, if you need a custom tsconfig.json for your test files:
  // options.browserifyOptions.plugin.unshift(['tsify', {project: 'path/to/other/tsconfig.json'}]);
  
  on("file:preprocessor", cucumber(options));
};

...and install tsify. I'm assuming you already have typescript installed. :-)

npm install tsify

Then in your .ts files you need to make sure you either require/import the functions defining step definitions, or declare them as global:

declare const Given, When, Then; // OR import { Given, Then, When } from "cypress-cucumber-preprocessor/steps";

How to organize the tests

To try out your environment, you can test and try writing scripts by putting your feature files in cypress/integration/

Example: cypress/integration/Google.feature

Feature: Google Main Page

  I want to open a search engine
  
  @focus
  Scenario: Opening a search engine page
    Given I open Google page
    Then I see "Google" in the title

Step definitions

This is the RECOMMENDED way

Step definitions creation

The .feature file will use steps definitions from a directory with the same name as your .feature file. The javascript files containing the step definitions can have other names if you want to break them into different concerns.

Easier to show than to explain, so, assuming the feature file is in cypress/integration/Google.feature , as proposed above, the preprocessor will read all the files inside cypress/integration/Google/, so:

cypress/integration/Google/google.js (or any other .js file in the same path)

import { Given } from "cypress-cucumber-preprocessor/steps";

const url = 'https://google.com'
Given('I open Google page', () => {
  cy.visit(url)
})

This is a good place to put before/beforeEach/after/afterEach hooks related to that particular feature. This is incredibly hard to get right with pure cucumber.

Reusable step definitions

We also have a way to create reusable step definitions. Put them in cypress/integration/common/

Example: cypress/integration/common/i_see_string_in_the_title.js

import { Then } from "cypress-cucumber-preprocessor/steps";

Then(`I see {string} in the title`, (title) => {
  cy.title().should('include', title)
})

This is a good place to put global before/beforeEach/after/afterEach hooks.

How to run the tests

Run your Cypress Launcher the way you would usually do, for example:

npx cypress open

click on a .feature file on the list of specs, and see the magic happening!

Running tagged tests

Example:

./node_modules/.bin/cypress-tags run -e TAGS='not @foo and (@bar or @zap)'

This concludes the environment setup of Cypress automation with cucumberrTS. If you have able to run your test, then it means everything works smooth during the setup. You can refer from the references below for more information about cypress cucumberTS.

References:

Please make use of to create a configuration for the plugin, for example, by adding this section to your package.json:

You can use tags to select which test should run using . Keep in mind we are using newer syntax, eg. 'not @foo and (@bar or @zap)'. In order to initialize tests using tags you will have to run cypress and pass TAGS environment variable.

๐Ÿงช
Set up tests
Write tests
Run tests
Debug Tests
cypress/base
cosmiconfig
cucumber's tag expressions
GitHub - badeball/cypress-cucumber-preprocessor: Run cucumber/gherkin-syntaxed specs with CypressGitHub
Why Cypress? | Cypress DocumentationCypress Documentation
Logo
Logo