Skip to content

Commit

Permalink
setup cypress for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mburri committed Nov 10, 2023
1 parent b16a0b2 commit abf87c2
Show file tree
Hide file tree
Showing 10 changed files with 4,199 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: run e2e tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build_and_test:
name: build and run e2e tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Cache node
uses: actions/cache@v2
with:
path: ~/.node
key: ${{ runner.os }}-node-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-node

- name: Setup chromedriver
uses: nanasess/setup-chromedriver@master

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

- name: Build docker image
run: |
cd AMW_e2e
npm install
npm run docker:build
- name: Run e2e tests
run: |
cd AMW_e2e
npm run test:ci
1 change: 1 addition & 0 deletions AMW_e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
67 changes: 67 additions & 0 deletions AMW_e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Liima End to End Tests

This module contains end-to-end tests using [cypress](https://www.cypress.io/)

## Getting started

Install all dependencies:

```bash
npm install
```


## Run the application

To run the e2e test, you need a running application on http://localhost:8080/AMW_web

You can use the docker image to get an application with a fresh h2 database:

```bash
npm run docker:build
```

Start and stop the application manually:

```bash
npm start
npm stop
```

Note: there are other ways to start the application. Using docker is the most convenient way if you want to focus on writen end-to-end tests.

## Using the cypress ui

You can run the cypress ui with the following command:

```bash
npm run test:ui
```

This will start the cypress ui that let's you run individual tests and inspect the runs. You have to choose the test type and environment first.
Note: onyle e2e tests are setup up for this project, no component testing.

See https://docs.cypress.io/guides/getting-started/opening-the-app for more information.


## Run tests in headless mode

To just run all tests, without the ui use:

```bash
npm run test
```

## Run tests on CI

Start the docker container, wait for the application startup and execute all tests with:

```bash
npm run test:ci
```

Notes:
* the container will not shut down when the tests are finished.
* you may need to build a new docker image if changes to your application where made.


9 changes: 9 additions & 0 deletions AMW_e2e/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
5 changes: 5 additions & 0 deletions AMW_e2e/cypress/e2e/logn.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("login", () => {
it("should login with basic auth", () => {
cy.visit("http://admin:admin@localhost:8080/AMW_web");
});
})
5 changes: 5 additions & 0 deletions AMW_e2e/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
25 changes: 25 additions & 0 deletions AMW_e2e/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions AMW_e2e/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading

0 comments on commit abf87c2

Please sign in to comment.