Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End to End Tests with Cypress - Setup #713

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion AMW_angular/io/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.

## Running end-to-end tests

Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
See `AMW_e2e` for end-to-end tests

## Further help

Expand Down
12 changes: 0 additions & 12 deletions AMW_angular/io/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,6 @@
"src/styles.scss"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "liima:serve"
},
"configurations": {
"production": {
"devServerTarget": "liima:serve:production"
}
}
}
}
}
Expand Down
32 changes: 0 additions & 32 deletions AMW_angular/io/e2e/protractor.conf.js

This file was deleted.

34 changes: 0 additions & 34 deletions AMW_angular/io/e2e/src/app/app.e2e.ts

This file was deleted.

13 changes: 0 additions & 13 deletions AMW_angular/io/e2e/tsconfig.json

This file was deleted.

2 changes: 0 additions & 2 deletions AMW_angular/io/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"test": "ng test",
"test-headless": "ng test --browsers=ChromeHeadless",
"lint": "ng lint",
"e2e": "ng e2e",
"mavenbuild": "ng test --watch=false --browsers=ChromeHeadless && ng build --configuration production"
},
"private": true,
Expand Down Expand Up @@ -54,7 +53,6 @@
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.1.0",
"prettier": "3.0.3",
"protractor": "~7.0.0",
"ts-node": "~10.9.1",
"tslint": "~6.1.3",
"typescript": "~5.1.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
[message]="errorMessage"
[messageType]="'warning'"
></app-notification>
<app-toast></app-toast>

<div>
<div class="form-group row">
Expand Down
21 changes: 7 additions & 14 deletions AMW_angular/io/src/app/deployments/deployments.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { NavigationStoreService } from '../navigation/navigation-store.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { DeploymentsEditModalComponent } from './deployments-edit-modal.component';
import { DateTimeModel } from '../shared/date-time-picker/date-time.model';
import { DATE_FORMAT } from "../core/amw-constants";
import { ToastComponent } from 'src/app/shared/elements/toast/toast.component';

declare var $: any;

Expand Down Expand Up @@ -83,6 +83,7 @@ export class DeploymentsComponent implements OnInit {

@ViewChild('selectModel', { static: true })
selectModel: NgModel;
@ViewChild(ToastComponent) toast: ToastComponent;

constructor(
private activatedRoute: ActivatedRoute,
Expand Down Expand Up @@ -289,22 +290,14 @@ export class DeploymentsComponent implements OnInit {
);
}

copyURL() {
async copyURL() {
const url: string = decodeURIComponent(window.location.href);
$('body')
.append(
$(
'<input type="text" name="fname" class="textToCopyInput" style="opacity:0"/>'
).val(url)
)
.find('.textToCopyInput')
.select();
try {
document.execCommand('copy');
} catch (e) {
window.prompt('Press Ctrl + C, then Enter to copy to clipboard', url);
await navigator.clipboard.writeText(url);
this.toast.display('URL copied to clipboard');
} catch (err) {
this.toast.display('Failed to copy URL. Please try again.');
}
$('.textToCopyInput').remove();
}

sortDeploymentsBy(col: string) {
Expand Down
49 changes: 49 additions & 0 deletions AMW_angular/io/src/app/shared/elements/toast/toast.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {Component, Input} from '@angular/core';

@Component({
selector: 'app-toast',
template: `
<div *ngIf="show" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-body">
<ul class="toast-list">
<li>{{ message }}</li>
</ul>
</div>
</div>
`,
styles: [`
.toast {
z-index: 1050;
display: block !important;
width: auto;
padding: 0.25rem;
position: fixed;
right: 2rem;
bottom: 2.5rem;

}

.toast-body {
color: #127e94;
}

.toast-list {
list-style-type: disc;
padding-left: 1rem;
margin-bottom: 0;
}
`]
})
export class ToastComponent {
@Input() message: string = '';
show: boolean = false;

public display(message: string, duration: number = 3000) {
this.message = message;
this.show = true;

setTimeout(() => {
this.show = false;
}, duration);
}
}
3 changes: 3 additions & 0 deletions AMW_angular/io/src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { NotificationComponent } from './elements/notification/notification.comp
import { DateTimePickerComponent } from './date-time-picker/date-time-picker.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { IconComponent } from './icon/icon.component';
import { ToastComponent } from './elements/toast/toast.component';

@NgModule({
declarations: [
Expand All @@ -20,6 +21,7 @@ import { IconComponent } from './icon/icon.component';
NotificationComponent,
DateTimePickerComponent,
IconComponent,
ToastComponent,
],
imports: [CommonModule, FormsModule, NgbModule],
exports: [
Expand All @@ -30,6 +32,7 @@ import { IconComponent } from './icon/icon.component';
NotificationComponent,
DateTimePickerComponent,
IconComponent,
ToastComponent,
],
})
export class SharedModule {}
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"
}
Loading
Loading