End-to-end tests with cypress (e2e-cypress)

cypress e2e testing quickstarter project

Purpose of this quickstarter

This is a cypress e2e testing project quickstarter with basic setup for Docker, Jenkins, SonarQube and OpenShift.

What files / architecture is generated?

.
├── Jenkinsfile
├── README.md
├── files
│   ├── README.md
│   ├── build
│   │   ├── integration
│   │   │   └── main.spec.js
│   │   └── support
│   │       ├── commands.js
│   │       └── index.js
│   ├── cypress.json
│   ├── fixtures
│   │   └── example.json
│   ├── integration
│   │   └── main.spec.ts
│   ├── package.json
│   ├── plugins
│   │   └── index.js
│   ├── support
│   │   ├── commands.ts
│   │   └── index.ts
│   ├── tsconfig.json
│   └── tslint.json
└── init.sh

9 directories, 16 files

Frameworks used

This project is generated by Angular CLI

Usage - how do you start after you provisioned this quickstarter

  • Run command npm install in project directory to install npm packages

  • Run npm run e2e to execute the end-to-end tests via cypress against the test instance of the front end

  • Run npm run watch to develop the e2e test. The tests will automatically rebuild and run, if you change any of the source files. The test will run against a local instance of the front end, e.g. localhost:4200. This destination is configurable in cypress.json. Provide credentials for a test user by defining them in a file called secrets.json inside the base directory. This file should have the following format:

{
  "e2e": {
    "testUserName": "User Name",
    "testUserPassword": "xxxx"
  }
}

Please note: secrets.json is mentioned in .gitignore to prevent it from being added to version control. Please keep it this way.

How this quickstarter is built through jenkins

The Jenkinsfile is provisioned with this quickstarter to ease CI/CD process. In Jenkinsfile, there is the following stage:

  • stageTest - Lint the TypeScript code by running npm install and npm run lint, and transpiles it to JavaScript and run the tests with the npm run build command.

Builder Slave used

This quickstarter uses Nodejs10-Angular builder slave Jenkins builder slave.

Known limitations

For now the URL of the front end instance to test is hard-coded inside the package.json file. There should be a better solution for handing this over. It is also possible to run npm run e2e-at with an additional parameter, e.g. npm run e2e-at https://domain.com.