diff --git a/.env b/.env index 4eb86a8548295b0c1dacc47badd78e1fcc0c29cb..16eaa53ca39a3e51555fdd06b79fbb39653904f1 100644 --- a/.env +++ b/.env @@ -5,4 +5,10 @@ REACT_APP_API_SERVER_URL=http://127.0.0.1:80 # related to proxy-setting in package.json DANGEROUSLY_DISABLE_HOST_CHECK=true -APP_TESTS_REMOTE_WEB_DRIVER_URL=selenium__standalone-chrome \ No newline at end of file +APP_TESTS_REMOTE_WEB_DRIVER_URL=selenium__standalone-chrome + +#variables selenium +BROWSER_NAME=firefox +SL_TEST_USE_REMOTE=0 +SL_TEST_REMOTE_URL=http://selenium-hub:4444/wd/hub +SL_TEST_BASE_URL=http://localhost:3000 \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b38506f8526a00e2aa55b3a0694e3f13b09669c3..08cb070404e6973e41521e3de9815eb73f036d7f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,50 +1,49 @@ -image: docker:latest +image: docker:20.10.16 services: - - name: docker 19.03.12-dind + - name: docker:20.10.16-dind alias: docker - stages: - - build - -backend: - stage: build - services: - - docker:19.03.12-dind - script: - - docker pull registry.bht-berlin.de:443/s87777/profwebbackend:latest - - docker run --name backend_container -d -p 80:80 registry.bht-berlin.de:443/s87777/profwebbackend - - echo "docker commands success" + - test - tags: +build-job: + stage: test + script: + - echo $CI_REGISTRY_PASSWORD | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin + - docker build -t registry.bht-berlin.de:443/s87777/profwebfrontend:latest . + - docker push registry.bht-berlin.de:443/s87777/profwebfrontend + tags: - docker-privileged -build_test_frontend: - stage: build +test-job: + stage: test + image: node:latest + variables: + FF_NETWORK_PER_BUILD: 1 + REACT_APP_API_SERVER_URL: "http://backend:3001" + SL_TEST_BASE_URL: "http://frontend:3000" + SL_TEST_USE_REMOTE: "1" + SL_TEST_REMOTE_URL: "http://selenium:4444/wd/hub" + SL_TEST_BROWSER_NAME: "firefox" services: - - name: selenium/standalone-firefox + - name: registry.bht-berlin.de:443/s87777/profwebbackend:latest + alias: backend + - name: registry.bht-berlin.de:443/s87777/profwebfrontend:latest + alias: frontend + - name: selenium/standalone-firefox:latest alias: selenium - - variables: - APP_TESTS_REMOTE_WEB_DRIVER_URL: "http://selenium:4444/wd/hub" - REACT_APP_API_SERVER_URL: "http://backend:80" - - script: - - echo "install npm" - - apk update - - apk upgrade - - apk add --update nodejs npm - - echo "Starte den Build" + script: + - sleep 5 + - curl http://backend:3001 + - curl http://frontend:3000 + - curl http://frontend:3000/shopper + - curl http://selenium:4444/wd/hub/status + - echo "installing dependencies" - npm install - - echo "Install erfolgreich" - - CI=false npm run build - - echo "Build erfolgreich" - - npm start & - - echo "start test" - - npm test --host=$APP_TESTS_REMOTE_WEB_DRIVER_URL - - echo "Testing finshed" - - artifacts: - expire_in: 1 hour - paths: - - build - - node_modules/ \ No newline at end of file + - sleep 5 + - echo "starting tests" + - npm test + - echo "tests done" + dependencies: + - build-job + tags: + - docker-privileged \ No newline at end of file diff --git a/src/test/LoginTest.test.ts b/src/test/LoginTest.test.ts index 441e1c50be086dea789713ff3790a7c68eb9a6a7..420a8ba3026ae6d8e96d19b18a7cb7ceceabda8f 100644 --- a/src/test/LoginTest.test.ts +++ b/src/test/LoginTest.test.ts @@ -1,17 +1,34 @@ import { Builder, By, WebDriver, until } from "selenium-webdriver"; import assert from "assert"; -import chrome from "selenium-webdriver/chrome"; +//import chrome from "selenium-webdriver/chrome"; +import { Options as ChromeOptions } from 'selenium-webdriver/chrome'; +import { Options as FirefoxOptions } from 'selenium-webdriver/firefox'; describe("Login Test", function () { let driver:WebDriver; + const BROWSER_NAME = process.env.BROWSER_NAME!; + const SL_TEST_USE_REMOTE = process.env.SL_TEST_USE_REMOTE; + const SL_TEST_REMOTE_URL = process.env.SL_TEST_REMOTE_URL!; + const SL_TEST_BASE_URL = process.env.SL_TEST_BASE_URL!; beforeEach(async function () { - console.log("Selenium Testing Server: " + process.env.APP_TESTS_REMOTE_WEB_DRIVER_URL); - driver = await new Builder().forBrowser("chrome").usingServer(`${process.env.APP_TESTS_REMOTE_WEB_DRIVER_URL}`).setChromeOptions(new chrome.Options().headless().windowSize({width: 1920, height: 1080})).build(); + //console.log("Selenium Testing Server: " + process.env.APP_TESTS_REMOTE_WEB_DRIVER_URL); + //driver = await new Builder().forBrowser("chrome").usingServer(`${process.env.APP_TESTS_REMOTE_WEB_DRIVER_URL}`).setChromeOptions(new chrome.Options().headless().windowSize({width: 1920, height: 1080})).build(); //driver = await new Builder().forBrowser("chrome").setChromeOptions(new chrome.Options().headless()).build(); //navigate to the application - await driver.get(`http://localhost:3000`); - await driver.manage().window().maximize(); + //await driver.get(`http://localhost:3000`); + //await driver.manage().window().maximize(); + + let builder = new Builder() + .forBrowser(BROWSER_NAME) + .setChromeOptions(new ChromeOptions().windowSize({ width: 1280, height: 720 }).headless()) + .setFirefoxOptions(new FirefoxOptions().windowSize({ width: 1280, height: 720 }).headless()); + if (SL_TEST_USE_REMOTE === "1") { + builder = builder.usingServer(SL_TEST_REMOTE_URL); + } + driver = await builder.build(); + await driver.get(SL_TEST_BASE_URL) + driver.manage().window().maximize(); },10000); afterEach(async function () { diff --git a/src/test/UserManagement.test.ts b/src/test/UserManagement.test.ts index 79c8d306a52602344c76d1e55a70ea2d09e8bc5e..bfd323fc890a95dd1d533dcc3ceea89c0ebc9430 100644 --- a/src/test/UserManagement.test.ts +++ b/src/test/UserManagement.test.ts @@ -1,17 +1,32 @@ import { Builder, By, WebDriver, until } from "selenium-webdriver"; import assert from "assert"; -import chrome from "selenium-webdriver/chrome"; +//import chrome from "selenium-webdriver/chrome"; +import { Options as ChromeOptions } from 'selenium-webdriver/chrome'; +import { Options as FirefoxOptions } from 'selenium-webdriver/firefox'; describe("User Management Test", function () { - let driver: WebDriver; + let driver: WebDriver; + const BROWSER_NAME = process.env.BROWSER_NAME!; + const SL_TEST_USE_REMOTE = process.env.SL_TEST_USE_REMOTE; + const SL_TEST_REMOTE_URL = process.env.SL_TEST_REMOTE_URL!; beforeEach(async function () { - console.log("Selenium Testing Server: " + process.env.APP_TESTS_REMOTE_WEB_DRIVER_URL); - console.log("React-Rest Anbindung: " + process.env.REACT_APP_API_SERVER_URL) - driver = await new Builder().forBrowser("chrome").usingServer(`${process.env.APP_TESTS_REMOTE_WEB_DRIVER_URL}`).setChromeOptions(new chrome.Options().headless().windowSize({width: 1920, height: 1080})).build(); - await driver.get(`http://localhost:3000`); - + //console.log("Selenium Testing Server: " + process.env.APP_TESTS_REMOTE_WEB_DRIVER_URL); + //console.log("React-Rest Anbindung: " + process.env.REACT_APP_API_SERVER_URL) + //driver = await new Builder().forBrowser("chrome").usingServer(`${process.env.APP_TESTS_REMOTE_WEB_DRIVER_URL}`).setChromeOptions(new chrome.Options().headless().windowSize({width: 1920, height: 1080})).build(); + //await driver.get(`http://localhost:3000`); + //await driver.manage().window().maximize(); + let builder = new Builder() + .forBrowser(BROWSER_NAME) + .setChromeOptions(new ChromeOptions().windowSize({ width: 1280, height: 720 }).headless()) + .setFirefoxOptions(new FirefoxOptions().windowSize({ width: 1280, height: 720 }).headless()); + if (SL_TEST_USE_REMOTE === "1") { + builder = builder.usingServer(SL_TEST_REMOTE_URL); + } + driver = await builder.build(); + driver.manage().window().maximize(); + const loginButton = await driver.findElement(By.id("loginButton")); await loginButton.click(); @@ -71,41 +86,43 @@ describe("User Management Test", function () { assert.strictEqual(userMax, true, "Der User Max wurde nicht gefunden."); }, 10000); - it("edit user", async function (){ + it("edit user", async function () { const editButton = driver.findElement(By.id("editButton-Flo")); await editButton.click(); await driver.wait(until.elementLocated(By.id("editUserDialog")), 5000); const isDialogOpen = await driver.findElement(By.id("editUserDialog")).isDisplayed(); - const usernameInput = await driver.findElement(By.id("inputUsername")); - await usernameInput.clear(); + await usernameInput.clear(); await usernameInput.sendKeys("Florian"); const emailInput = await driver.findElement(By.id("inputEmail")); - await emailInput.clear(); - await emailInput.sendKeys("florian@some-host.de") + await emailInput.clear(); + await emailInput.sendKeys("florian@some-host.de"); const editNowButton = await driver.findElement(By.id("editNow")); await editNowButton.click(); await driver.wait(until.elementLocated(By.id("user-Florian")), 5000); const userFlorianAdmin = await driver.findElement(By.id("user-Florian")).isDisplayed(); assert.strictEqual(userFlorianAdmin, true, "Der User Florian wurde nicht gefunden."); - },10000); + }, 10000); - it("delete user", async function (){ + it("delete user", async function () { const deleteButton = await driver.findElement(By.id("deleteButton-Max")); await deleteButton.click(); await driver.sleep(500); // Überprüfen das "Max" nicht mehr in der Benutzerliste vorhanden ist - const isMaxDeleted = await driver.findElement(By.id("user-Max")).isDisplayed().then( - () => false, - (error:Error) => error.toString().includes("no such element"), - ); + const isMaxDeleted = await driver + .findElement(By.id("user-Max")) + .isDisplayed() + .then( + () => false, + (error: Error) => error.toString().includes("no such element") + ); assert.strictEqual(isMaxDeleted, true, "Der Benutzer 'Max' wurde nicht gelöscht."); - },10000); + }, 10000); - it("login with new account", async function (){ + it("login with new account", async function () { const addButton = driver.findElement(By.id("addUserButton")); await addButton.click(); await driver.wait(until.elementLocated(By.id("addUserDialog")), 5000); @@ -148,15 +165,13 @@ describe("User Management Test", function () { await driver.wait(until.elementLocated(By.id("logoutButton")), 5000); const isLogoutButtonOpenMax = await driver.findElement(By.id("logoutButton")).isDisplayed(); assert.strictEqual(isLogoutButtonOpenMax, true, "Der Logout Button Max wird nicht angezeigt."); - },10000); + }, 10000); - it("create User without password ERROR!", async function (){ + it("create User without password ERROR!", async function () { const addUserButton = driver.findElement(By.id("addUserButton")); await addUserButton.click(); await driver.wait(until.elementLocated(By.id("addUserDialog")), 5000); - - const inputUsername = await driver.findElement(By.id("inputUsername")); const inputMail = await driver.findElement(By.id("inputEmail")); const inputPassword = await driver.findElement(By.id("inputPassword")); @@ -170,9 +185,9 @@ describe("User Management Test", function () { await driver.wait(until.elementLocated(By.id("warningMessage")), 5000); const warningMessage = await driver.findElement(By.id("warningMessage")).isDisplayed(); assert.strictEqual(warningMessage, true, "Die Fehlermeldung wurde nicht gefunden."); - },10000); + }, 10000); - it("clean up test", async function (){ + it("clean up test", async function () { console.log("Start afterAll"); //Löschen von User Max const deleteButtonMax = await driver.findElement(By.id("deleteButton-Max")); @@ -188,8 +203,8 @@ describe("User Management Test", function () { await usernameInput.sendKeys("Flo"); const emailInput = await driver.findElement(By.id("inputEmail")); - await emailInput.clear(); - await emailInput.sendKeys("flo@some-host.de") + await emailInput.clear(); + await emailInput.sendKeys("flo@some-host.de"); const editNowButton = await driver.findElement(By.id("editNow")); await editNowButton.click(); @@ -197,5 +212,5 @@ describe("User Management Test", function () { await driver.wait(until.elementLocated(By.id("user-Flo")), 5000); const userFlorianAdmin = await driver.findElement(By.id("user-Flo")).isDisplayed(); assert.strictEqual(userFlorianAdmin, true, "Der User Flo wurde nicht gefunden."); - },10000); + }, 10000); });