πŸ’»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:

Next is to install 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)

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

Global step definitions exaple

Step definitions besides scenario

Step definitions in a directory besides the scenario

Combination of all of the above (default)

Installing of bundler Browserify and Webpack

Browesrify-ts installation:

And add this under cypress-config.ts file.

Webpack-ts installation:

And add this under cypress-config.ts file.

Install cucumber-json-formatter

And add this at package.json

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

Write a test

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

Running a test in browserless mode:

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

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

Last updated