From c7f8ac226233513e52474bb298296aefa76c2537 Mon Sep 17 00:00:00 2001 From: jesQM Date: Sun, 26 Apr 2020 13:30:54 +0200 Subject: [PATCH 01/24] Start cucumber tests --- e2e/step-definitions/login.steps.js | 34 ++++++--- jest-puppeteer.config.js | 2 +- package-lock.json | 109 +++++++++++++++++++++++----- package.json | 2 + 4 files changed, 117 insertions(+), 30 deletions(-) diff --git a/e2e/step-definitions/login.steps.js b/e2e/step-definitions/login.steps.js index 149078c..7a516fa 100644 --- a/e2e/step-definitions/login.steps.js +++ b/e2e/step-definitions/login.steps.js @@ -1,28 +1,40 @@ const {defineFeature, loadFeature}=require('jest-cucumber'); const feature = loadFeature('./e2e/features/login.feature'); //const podUtils = require('../../src/scripts/podUtils'); -const actions = require('../support/actions'); -const selectors = require('../support/selectors'); +//const actions = require('../support/actions'); +//const selectors = require('../support/selectors'); + +console.log("Start!"); +jest.setTimeout(30000); defineFeature((feature, test) => { - test('Edit profile info', ({ given, when, then }) => { - + beforeEach(async () => { + console.log("Before each"); jest.setTimeout(30000); + await page.goto('http://localhost:3000/#/home') + }) + + test('Edit profile info', ({ given, when, then }) => { + + console.log("Test start") + //jest.setTimeout(30000); + + /*beforeEach(async () => { + console.log("Before each") + await setTimeout(() => {alert("waited")}, 10000) + await page.goto('http://localhost:3000/#/home'); + });*/ - beforeEach(async () => { - await page.goto('http://localhost:3000/#/profile'); - }); - given('An already registered user on the profile page', () => { - + }); - + when('I click the edit profile button', async () => { //await expect(page).toClick('button', { text: 'Edit profile' , setTimeout: 30000}) }); - + then('The edit profile page appears', async () => { //await expect(page).toMatchElement('h1', { text: 'Edit profile info'}) }); diff --git a/jest-puppeteer.config.js b/jest-puppeteer.config.js index 57a7bbc..febd52b 100644 --- a/jest-puppeteer.config.js +++ b/jest-puppeteer.config.js @@ -2,7 +2,7 @@ module.exports = { server: { command: `npm start`, port: 3000, - launchTimeout: 10000, + launchTimeout: 100000, debug: true }, }; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f8745b3..7331aec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8912,6 +8912,11 @@ "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==" }, + "immediate": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", + "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=" + }, "immer": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/immer/-/immer-1.10.0.tgz", @@ -10989,6 +10994,51 @@ "object.assign": "^4.1.0" } }, + "jszip": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.4.0.tgz", + "integrity": "sha512-gZAOYuPl4EhPTXT0GjhI3o+ZAz3su6EhLrKUoAivcKqyqC7laS5JEv4XWZND9BgcDcF83vI85yGbDmDR6UhrIg==", + "requires": { + "lie": "~3.3.0", + "pako": "~1.0.2", + "readable-stream": "~2.3.6", + "set-immediate-shim": "~1.0.1" + }, + "dependencies": { + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "requires": { + "safe-buffer": "~5.1.0" + } + } + } + }, "killable": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/killable/-/killable-1.0.1.tgz", @@ -11088,6 +11138,14 @@ "type-check": "~0.3.2" } }, + "lie": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", + "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", + "requires": { + "immediate": "~3.0.5" + } + }, "lines-and-columns": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz", @@ -15535,6 +15593,34 @@ "resolved": "https://registry.npmjs.org/select-hose/-/select-hose-2.0.0.tgz", "integrity": "sha1-Yl2GWPhlr0Psliv8N2o3NZpJlMo=" }, + "selenium-webdriver": { + "version": "4.0.0-alpha.7", + "resolved": "https://registry.npmjs.org/selenium-webdriver/-/selenium-webdriver-4.0.0-alpha.7.tgz", + "integrity": "sha512-D4qnTsyTr91jT8f7MfN+OwY0IlU5+5FmlO5xlgRUV6hDEV8JyYx2NerdTEqDDkNq7RZDYc4VoPALk8l578RBHw==", + "requires": { + "jszip": "^3.2.2", + "rimraf": "^2.7.1", + "tmp": "0.0.30" + }, + "dependencies": { + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "requires": { + "glob": "^7.1.3" + } + }, + "tmp": { + "version": "0.0.30", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.30.tgz", + "integrity": "sha1-ckGdSovn1s51FI/YsyTlk6cRwu0=", + "requires": { + "os-tmpdir": "~1.0.1" + } + } + } + }, "selfsigned": { "version": "1.10.7", "resolved": "https://registry.npmjs.org/selfsigned/-/selfsigned-1.10.7.tgz", @@ -15690,6 +15776,11 @@ "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" }, + "set-immediate-shim": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz", + "integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E=" + }, "set-value": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.1.tgz", @@ -19603,24 +19694,6 @@ "dev": true, "requires": { "@babel/runtime-corejs3": "^7.8.3" - }, - "dependencies": { - "@babel/runtime-corejs3": { - "version": "7.9.2", - "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.9.2.tgz", - "integrity": "sha512-HHxmgxbIzOfFlZ+tdeRKtaxWOMUoCG5Mu3wKeUmOxjYrwb3AAHgnmtCUbPPK11/raIWLIBK250t8E2BPO0p7jA==", - "dev": true, - "requires": { - "core-js-pure": "^3.0.0", - "regenerator-runtime": "^0.13.4" - } - }, - "regenerator-runtime": { - "version": "0.13.5", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz", - "integrity": "sha512-ZS5w8CpKFinUzOwW3c83oPeVXoNsrLsaCoLtJvAClH135j/R77RuymhiSErhm2lKcwSCIpmvIWSbDkIfAqKQlA==", - "dev": true - } } }, "xtend": { diff --git a/package.json b/package.json index 6d0fe69..6a953ee 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "react-router-dom": "^5.1.2", "react-scripts": "^3.4.0", "react-toastify": "^5.5.0", + "selenium-webdriver": "^4.0.0-alpha.7", "shx": "0.3.2", "solid-acl-utils": "github:otto-aa/solid-acl-utils", "solid-auth-client": "^2.4.1", @@ -46,6 +47,7 @@ }, "scripts": { "start": "react-scripts start", + "nothing": "", "build": "react-scripts build", "test": "react-scripts test --coverage", "test:e2e": "jest -c e2e/jest.config.js", From 000c9f8f103362c949dab7610bee40e42ab379ec Mon Sep 17 00:00:00 2001 From: jesQM Date: Mon, 27 Apr 2020 10:50:29 +0200 Subject: [PATCH 02/24] 2 Basic tests done --- e2e/features/basicFunctionality.feature | 12 ++++ .../basicFunctionality.steps.js | 70 +++++++++++++++++++ e2e/step-definitions/login.js | 62 ++++++++++++++++ e2e/step-definitions/login.steps.js | 42 ----------- src/components/navBar/navBar.js | 2 +- .../routeCreation/RouteCreationForm.js | 1 + 6 files changed, 146 insertions(+), 43 deletions(-) create mode 100644 e2e/features/basicFunctionality.feature create mode 100644 e2e/step-definitions/basicFunctionality.steps.js create mode 100644 e2e/step-definitions/login.js delete mode 100644 e2e/step-definitions/login.steps.js diff --git a/e2e/features/basicFunctionality.feature b/e2e/features/basicFunctionality.feature new file mode 100644 index 0000000..3cc5148 --- /dev/null +++ b/e2e/features/basicFunctionality.feature @@ -0,0 +1,12 @@ +Feature: Access the application + +Scenario: Access the main view of the App + Given A new unregistered user + When Accessing the App + Then The carousel loads + + +Scenario: Change App Language + Given A user in the main view + When Pressing the change language button + Then Language should change diff --git a/e2e/step-definitions/basicFunctionality.steps.js b/e2e/step-definitions/basicFunctionality.steps.js new file mode 100644 index 0000000..35619ab --- /dev/null +++ b/e2e/step-definitions/basicFunctionality.steps.js @@ -0,0 +1,70 @@ +const {defineFeature, loadFeature}=require('jest-cucumber'); +const feature = loadFeature('./e2e/features/basicFunctionality.feature'); +const expect = require('expect-puppeteer'); +const puppeteer = require('puppeteer'); + +jest.setTimeout(400000); +function delay(time) { + return new Promise(function (resolve) { + setTimeout(resolve, time) + }); +} + +defineFeature(feature, test => { + + beforeEach(async () => { + delay(10000); + console.log("Before each"); + //Open browser + const browser = await puppeteer.launch({ + //headless let watch the chrome window interacting with the application + headless: false, + defaultViewport: null + }); + page = await browser.newPage(); + await page.goto('http://localhost:3000'); + }) + + test('Access the main view of the App', ({ given, when, then }) => { + + + given('A new unregistered user', async () => { + // Default case, already unregistered + }); + + when('Accessing the App', async () => { + await page.waitForSelector('div[id="root"]'); // wait to load + }); + + then('The carousel loads', async () => { + await page.waitForSelector('div[id="root"]'); + await expect(page).toMatchElement('div[id="root"]'); + + await page.waitForSelector('div[id="container"]'); + await expect(page).toMatchElement('div[id="container"]'); + + await page.waitForFunction('document.querySelector("body").innerText.includes("Bienvenido")'); + }); + }); + + test('Change App Language', ({ given, when, then }) => { + + + given('A user in the main view', async () => { + await page.waitForSelector('div[id="root"]'); // wait to load + }); + + when('Pressing the change language button', async () => { + await page.waitForSelector('[id="dropdown-item-button"]'); + await page.click('[id="dropdown-item-button"]'); + + await page.waitForFunction('document.querySelector("body").innerText.includes("Inglés")'); + await page.click('button.dropdown-item'); + }); + + then('Language should change', async () => { + await page.waitForSelector('div[id="root"]'); + await page.waitForFunction('document.querySelector("body").innerText.includes("Welcome")'); + }); + }); +}); \ No newline at end of file diff --git a/e2e/step-definitions/login.js b/e2e/step-definitions/login.js new file mode 100644 index 0000000..56032b4 --- /dev/null +++ b/e2e/step-definitions/login.js @@ -0,0 +1,62 @@ +const {defineFeature, loadFeature}=require('jest-cucumber'); +const feature = loadFeature('./e2e/features/login.feature'); +const expect = require('expect-puppeteer'); +const puppeteer = require('puppeteer'); +//const podUtils = require('../../src/scripts/podUtils'); +//const actions = require('../support/actions'); +//const selectors = require('../support/selectors'); + +console.log("Start!"); +jest.setTimeout(400000); + +function delay(time) { + return new Promise(function (resolve) { + setTimeout(resolve, time) + }); +} + +defineFeature(feature, test => { + + beforeEach(async () => { + /*delay(10000); + console.log("Before each"); + //Open browser + const browser = await puppeteer.launch({ + //headless let watch the chrome window interacting with the application + headless: false, + defaultViewport: null + }); + page = await browser.newPage(); + await page.goto('http://localhost:3000/viade_en3a#/routes/add'); +*/ + + // Log in + + }) + + test('Edit profile info', ({ given, when, then }) => { + + console.log("Test start") + //jest.setTimeout(30000); + + given('An already registered user on the profile page', async () => { + delay(10000); + await page.goto('http://localhost:3000/viade_en3a#/routes/add'); + delay(20000); + console.log("post Delay"); + await expect(page).toFill('input[id="routeNameInput"]', "Ruta Cucumber-Puppeteer"); + await page.click('//*[@id="responsive-navbar-nav"]/div[1]/div[1]/a'); + + await page.waitForSelector('#profileNavButton'); + await page.click('#profileNavButton'); + }); + + when('I click the edit profile button', async () => { + //await expect(page).toClick('button', { text: 'Edit profile' , setTimeout: 30000}) + }); + + then('The edit profile page appears', async () => { + //await expect(page).toMatchElement('h1', { text: 'Edit profile info'}) + }); + }); +}); \ No newline at end of file diff --git a/e2e/step-definitions/login.steps.js b/e2e/step-definitions/login.steps.js deleted file mode 100644 index 7a516fa..0000000 --- a/e2e/step-definitions/login.steps.js +++ /dev/null @@ -1,42 +0,0 @@ -const {defineFeature, loadFeature}=require('jest-cucumber'); -const feature = loadFeature('./e2e/features/login.feature'); -//const podUtils = require('../../src/scripts/podUtils'); -//const actions = require('../support/actions'); -//const selectors = require('../support/selectors'); - -console.log("Start!"); -jest.setTimeout(30000); - -defineFeature((feature, test) => { - - beforeEach(async () => { - console.log("Before each"); - jest.setTimeout(30000); - await page.goto('http://localhost:3000/#/home') - }) - - test('Edit profile info', ({ given, when, then }) => { - - console.log("Test start") - //jest.setTimeout(30000); - - /*beforeEach(async () => { - console.log("Before each") - await setTimeout(() => {alert("waited")}, 10000) - await page.goto('http://localhost:3000/#/home'); - });*/ - - - given('An already registered user on the profile page', () => { - - }); - - when('I click the edit profile button', async () => { - //await expect(page).toClick('button', { text: 'Edit profile' , setTimeout: 30000}) - }); - - then('The edit profile page appears', async () => { - //await expect(page).toMatchElement('h1', { text: 'Edit profile info'}) - }); - }); -}); \ No newline at end of file diff --git a/src/components/navBar/navBar.js b/src/components/navBar/navBar.js index b5b1914..bb3ef56 100644 --- a/src/components/navBar/navBar.js +++ b/src/components/navBar/navBar.js @@ -57,7 +57,7 @@ function MyNavBar(props) {