From 91c83eccd2af17c48b8f5fba195ea900a6fe5fd5 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 25 Oct 2019 18:53:29 +1300 Subject: [PATCH] feat(project): add automated testing with cypress (#3305) * feat(project): add automated testing with cypress * feat(project): made suggested edits * feat(project): add init test * feat(project): add socket to correct container --- test/e2e/.env | 1 + test/e2e/cypress.json | 3 +++ test/e2e/cypress/integration/spec.js | 21 +++++++++++++++++++++ test/e2e/cypress/plugins/index.js | 17 +++++++++++++++++ test/e2e/cypress/support/commands.js | 25 +++++++++++++++++++++++++ test/e2e/cypress/support/index.js | 20 ++++++++++++++++++++ test/e2e/docker-compose.yml | 19 +++++++++++++++++++ 7 files changed, 106 insertions(+) create mode 100644 test/e2e/.env create mode 100644 test/e2e/cypress.json create mode 100644 test/e2e/cypress/integration/spec.js create mode 100644 test/e2e/cypress/plugins/index.js create mode 100644 test/e2e/cypress/support/commands.js create mode 100644 test/e2e/cypress/support/index.js create mode 100644 test/e2e/docker-compose.yml diff --git a/test/e2e/.env b/test/e2e/.env new file mode 100644 index 000000000..95d0b0cb8 --- /dev/null +++ b/test/e2e/.env @@ -0,0 +1 @@ +PORTAINER_TAG=develop \ No newline at end of file diff --git a/test/e2e/cypress.json b/test/e2e/cypress.json new file mode 100644 index 000000000..5e0725b20 --- /dev/null +++ b/test/e2e/cypress.json @@ -0,0 +1,3 @@ +{ + "video": false +} \ No newline at end of file diff --git a/test/e2e/cypress/integration/spec.js b/test/e2e/cypress/integration/spec.js new file mode 100644 index 000000000..cf2b5a1f9 --- /dev/null +++ b/test/e2e/cypress/integration/spec.js @@ -0,0 +1,21 @@ +// Tests to run +context('Tests to run', () => { + //Browse to homepage before each test + beforeEach(() => { + cy.visit('/') + }) + describe('Init admin', function() { + it('Create user and verify success', function() { + cy.get('#username') + .should('have.value', 'admin') + cy.get('#password') + .type('portaineriscool') + .should('have.value', 'portaineriscool') + cy.get('#confirm_password') + .type('portaineriscool') + .should('have.value', 'portaineriscool') + cy.get('[type=submit]').click() + cy.url().should('include', '/init/endpoint') + }) + }) +}) diff --git a/test/e2e/cypress/plugins/index.js b/test/e2e/cypress/plugins/index.js new file mode 100644 index 000000000..fd170fba6 --- /dev/null +++ b/test/e2e/cypress/plugins/index.js @@ -0,0 +1,17 @@ +// *********************************************************** +// This example plugins/index.js can be used to load plugins +// +// You can change the location of this file or turn off loading +// the plugins file with the 'pluginsFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/plugins-guide +// *********************************************************** + +// This function is called when a project is opened or re-opened (e.g. due to +// the project's config changing) + +module.exports = (on, config) => { + // `on` is used to hook into various events Cypress emits + // `config` is the resolved Cypress config +} diff --git a/test/e2e/cypress/support/commands.js b/test/e2e/cypress/support/commands.js new file mode 100644 index 000000000..c1f5a772e --- /dev/null +++ b/test/e2e/cypress/support/commands.js @@ -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 is will overwrite an existing command -- +// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) diff --git a/test/e2e/cypress/support/index.js b/test/e2e/cypress/support/index.js new file mode 100644 index 000000000..d68db96df --- /dev/null +++ b/test/e2e/cypress/support/index.js @@ -0,0 +1,20 @@ +// *********************************************************** +// This example support/index.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') diff --git a/test/e2e/docker-compose.yml b/test/e2e/docker-compose.yml new file mode 100644 index 000000000..43a349ded --- /dev/null +++ b/test/e2e/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3' +services: + portainer: + image: portainerci/portainer:$PORTAINER_TAG + container_name: e2e-portainer + volumes: + - /var/run/docker.sock:/var/run/docker.sock + + cypress: + image: cypress/included:3.4.1 + container_name: e2e-cypress + depends_on: + - portainer + working_dir: /app + environment: + - CYPRESS_baseUrl=http://e2e-portainer:9000 + volumes: + - ./cypress:/app/cypress + - ./cypress.json:/app/cypress.json \ No newline at end of file