Skip to content

Commit

Permalink
feat: aja automaattitestit automaattisesti. Korjaa kirjautumis-uudell…
Browse files Browse the repository at this point in the history
…eenohjaus.
  • Loading branch information
haapamakim committed Jun 28, 2022
1 parent 96cc8c2 commit 80319b6
Show file tree
Hide file tree
Showing 33 changed files with 160 additions and 375 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ build

/test/.report

/robotenv.py
__pycache__
/.eslintcache
.sonar
migration/node_modules
Expand Down
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ RUN apt install -y curl && curl -o- https://raw.githubusercontent.com/creationix
ENV NVM_DIR=/root/.nvm
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION} && nvm use v${NODE_VERSION} && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"

RUN . "$NVM_DIR/nvm.sh" && npm install -g npm@8.1.3
RUN . "$NVM_DIR/nvm.sh" && npm install -f -g @aws-amplify/cli

COPY tools /tools
RUN cd /tools/velho && ./gradlew dependencies

RUN apt-get update \
&& apt-get install -y xvfb wget ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 \
libatspi2.0-0 libcups2 libdbus-1-3 libgbm1 libgtk-3-0 libnspr4 libnss3 \
libxcomposite1 libxkbcommon0 libxrandr2 xdg-utils ntpdate openssl

RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
&& dpkg -i google-chrome*.deb \
&& rm google-chrome*.deb
5 changes: 5 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
"env": {
"projektiNimi": "HASSU AUTOMAATTITESTIPROJEKTI1",
"oid": "1.2.246.578.5.1.2978288874.2711575506"
},
"reporter": "junit",
"reporterOptions": {
"mochaFile": ".report/e2e-test-output-[hash].xml",
"toConsole": true
}
}
27 changes: 20 additions & 7 deletions cypress/integration/1 - login/1-login.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
/// <reference types="cypress" />

// Ignore javascript error on login page
Cypress.on("uncaught:exception", (err) => {
if (err.message.indexOf("saveLastUsername") > 0) {
return false;
}
});

describe("Login", () => {
it("Ohjaa kirjoutumaton kirjautumissivulle", () => {
cy.intercept("/yllapito/graphql", (req) => req.reply({ statusCode: 302 })).as("graphql");
cy.intercept("/yllapito/kirjaudu", (req) => req.reply({ statusCode: 400, body: "login page" })).as("kirjaudu");
cy.visit(Cypress.env("host") + "/yllapito");
cy.wait("@graphql");
cy.wait("@kirjaudu");
cy.contains("login page");
it("Ohjaa kirjautumaton kirjautumissivulle", () => {
cy.clearCookies();
if (Cypress.env("localServer") === true) {
cy.intercept("/yllapito/graphql", (req) =>
req.reply({ statusCode: 302, headers: { location: "https://www.vayla.fi/should_not_actually_redirect_here" } })
).as("graphql");
cy.visit(Cypress.env("host") + "/yllapito");
cy.wait("@graphql");
cy.url().should("contain", "login");
} else {
cy.visit(Cypress.env("host") + "/yllapito");
cy.url().should("contain", "login");
}
});

it("Kirjaudu A1 käyttäjänä", () => {
Expand Down
1 change: 1 addition & 0 deletions cypress/integration/2-perusta-projekti/1-velhohaku.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const oid = Cypress.env("oid");

describe("Hae projekti Velhosta", () => {
before(() => {
cy.abortEarly();
cy.login("A1");

cy.visit(Cypress.env("host") + "/yllapito/projekti/" + oid + "/arkistoi");
Expand Down
1 change: 1 addition & 0 deletions cypress/integration/2-perusta-projekti/2-perusta.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const oid = Cypress.env("oid");

describe("Perusta projekti", () => {
before(() => {
cy.abortEarly();
Cypress.config("scrollBehavior", "nearest");
cy.login("A1");
cy.visit(Cypress.env("host") + "/yllapito/projekti/" + oid + "/arkistoi");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const oid = Cypress.env("oid");

describe("Projektin perustiedot", () => {
before(() => {
cy.abortEarly();
cy.login("A1");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const oid = Cypress.env("oid");

describe("Projektin aloituskuulutus", () => {
before(() => {
cy.abortEarly();
cy.login("A1");
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/// <reference types="cypress" />

const oid = Cypress.env("oid");

describe("Projektin aloituskuulutus kansalaisille", () => {
before(() => {
cy.abortEarly();
});
it("Aloituskuulutus näkyy kansalaisille", () => {
cy.visit(Cypress.env("host") + "/suunnitelma/" + oid + "/aloituskuulutus");
cy.contains("Hankkeen kuvaus Suomeksi");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/// <reference types="cypress" />

import { abortEarly } from "../../support/commands";

const projektiNimi = Cypress.env("projektiNimi");
const oid = Cypress.env("oid");

describe("Projektin suunnitteluvaihe (perustiedot)", () => {
before(() => {
cy.abortEarly();
cy.login("A1");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const oid = Cypress.env("oid");

describe("Projektin suunnitteluvaihe (vuorovaikutukset)", () => {
before(() => {
cy.abortEarly();
cy.login("A1");
});

Expand Down
18 changes: 13 additions & 5 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

let shouldSkip = false;
/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
module.exports = (on) => {
on("task", {
resetShouldSkipFlag() {
shouldSkip = false;
return null;
},
shouldSkip(value) {
if (value != null) shouldSkip = value;
return shouldSkip;
},
});
};
43 changes: 24 additions & 19 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,36 @@ Cypress.Commands.overwrite("type", (originalFn, subject, text, options = {}) =>

Cypress.config("scrollBehavior", "nearest");

// The following code copied from https://rajneesh-m49.medium.com/skipping-cypress-tests-on-first-failure-and-saving-resources-2c63e3bb0705 to skip running tests after failure
before(() => {
if (Cypress.browser.isHeaded) {
cy.clearCookie("shouldSkip");
} else {
cy.getCookie("shouldSkip").then((cookie) => {
if (cookie && typeof cookie === "object" && cookie.value === "true") {
Cypress.runner.stop();
}
});
function abortEarly() {
if (this.currentTest.state === "failed") {
return cy.task("shouldSkip", true);
}
});
cy.task("shouldSkip").then((value) => {
if (value) this.skip();
});
}

afterEach(function onAfterEach() {
function setAbortEarlyStatus() {
if (this.currentTest.state === "failed") {
cy.setCookie("shouldSkip", "true");
//set cookie to skip tests for further specs
Cypress.runner.stop();
//this will skip tests only for current spec
return cy.task("shouldSkip", true);
}
});
}

Cypress.Cookies.defaults({
preserve: "shouldSkip",
beforeEach(abortEarly);
afterEach(setAbortEarlyStatus);

before(() => {
if (Cypress.browser.isHeaded) {
// Reset the shouldSkip flag at the start of a run, so that it
// doesn't carry over into subsequent runs.
// Do this only for headed runs because in headless runs,
// the `before` hook is executed for each spec file.
cy.task("resetShouldSkipFlag");
}
});

Cypress.Commands.add("abortEarly", abortEarly);

Cypress.Commands.add("login", (testuser) => {
cy.session(testuser, () => {
const username = Cypress.env(testuser + "-username");
Expand Down Expand Up @@ -90,6 +94,7 @@ Cypress.Commands.add("login", (testuser) => {
});
});
});
cy.url({ timeout: 4000 }).should("not.contain", "sso");
}
});
});
60 changes: 0 additions & 60 deletions deployment/bin/setupRobotEnvironment.ts

This file was deleted.

12 changes: 6 additions & 6 deletions deployment/bin/updateECRImages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 283563576583.dkr.ecr.eu-west-1.amazonaws.com

# Copy localstack into private repository
LOCALSTACK_VERSION=0.14.1
aws ecr create-repository --repository-name localstack || true
docker pull 283563576583.dkr.ecr.eu-west-1.amazonaws.com/localstack:latest || true
docker pull localstack/localstack:latest
docker tag localstack/localstack:latest 283563576583.dkr.ecr.eu-west-1.amazonaws.com/localstack:latest
docker push 283563576583.dkr.ecr.eu-west-1.amazonaws.com/localstack:latest
docker pull 283563576583.dkr.ecr.eu-west-1.amazonaws.com/localstack:$LOCALSTACK_VERSION || true
docker pull localstack/localstack:$LOCALSTACK_VERSION
docker tag localstack/localstack:$LOCALSTACK_VERSION 283563576583.dkr.ecr.eu-west-1.amazonaws.com/localstack:$LOCALSTACK_VERSION
docker push 283563576583.dkr.ecr.eu-west-1.amazonaws.com/localstack:$LOCALSTACK_VERSION

# Create buildimage to provide faster builds
BUILD_IMAGE_VERSION=1.0.0

BUILD_IMAGE_VERSION=1.0.2
REPO_TAG=283563576583.dkr.ecr.eu-west-1.amazonaws.com/hassu-buildimage:$BUILD_IMAGE_VERSION
aws ecr create-repository --repository-name hassu-buildimage || true
docker pull $REPO_TAG || true
Expand Down
4 changes: 2 additions & 2 deletions deployment/lib/buildspec/buildspec-feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ phases:
commands:
- aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 283563576583.dkr.ecr.eu-west-1.amazonaws.com

- nohup docker pull 283563576583.dkr.ecr.eu-west-1.amazonaws.com/hassu-buildimage:1.0.0 &
- nohup docker pull 283563576583.dkr.ecr.eu-west-1.amazonaws.com/localstack:latest &
- nohup docker pull 283563576583.dkr.ecr.eu-west-1.amazonaws.com/hassu-buildimage:1.0.2 &
- nohup docker pull 283563576583.dkr.ecr.eu-west-1.amazonaws.com/localstack:0.14.1 &

- npm install -g npm@8.1.3
- npm ci
Expand Down
6 changes: 3 additions & 3 deletions deployment/lib/buildspec/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ phases:
commands:
- aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 283563576583.dkr.ecr.eu-west-1.amazonaws.com

- nohup docker pull 283563576583.dkr.ecr.eu-west-1.amazonaws.com/hassu-buildimage:1.0.0 &
- nohup docker pull 283563576583.dkr.ecr.eu-west-1.amazonaws.com/localstack:latest &
- nohup docker pull 283563576583.dkr.ecr.eu-west-1.amazonaws.com/hassu-buildimage:1.0.2 &
- nohup docker pull 283563576583.dkr.ecr.eu-west-1.amazonaws.com/localstack:0.14.1 &

- npm install -g npm@8.1.3
- npm ci
Expand All @@ -38,7 +38,7 @@ phases:
post_build:
on-failure: ABORT
commands:
- aws codebuild start-build --project-name Hassu-robottest-$ENVIRONMENT --source-version $CODEBUILD_SOURCE_VERSION
- aws codebuild start-build --project-name Hassu-e2etest-$ENVIRONMENT --source-version $CODEBUILD_SOURCE_VERSION
cache:
paths:
- "/root/.cache/**/*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@ version: 0.2
phases:
install:
commands:
- npm ci --no-audit
- npm run robot:setup
- npm i --no-audit
- npm run setupenvironment
build:
commands:
- ./tools/robot/run_suite_local.sh
- npm run e2e:test:run
- echo Test report available at https://$FRONTEND_DOMAIN_NAME_DEV/report/robot-$ENVIRONMENT/$CODEBUILD_BUILD_NUMBER/report.html
artifacts:
files:
- "test/.report/**/*"
- ".report/e2e-test-output-*.xml"
- "cypress/screenshots/**/*"
- "cypress/videos/**/*"
discard-paths: yes
name: report/robot-$ENVIRONMENT/$CODEBUILD_BUILD_NUMBER

cache:
paths:
- "/root/.npm/**/*"
- "/root/.cache/**/*"

reports:
unit-tests:
files: "xunit.xml"
base-directory: test/.report
files: "e2e-test-output-*.xml"
base-directory: .report
discard-paths: true
Loading

0 comments on commit 80319b6

Please sign in to comment.