From e445f414a4c85c294518ed9dd728c39e2b900db0 Mon Sep 17 00:00:00 2001 From: "Dario G. Mori" Date: Sun, 5 May 2024 18:11:48 +0200 Subject: [PATCH] fix: about_positive_logged_user_seeing_about_screen.steps.js --- webapp/e2e/jest.config.js | 2 +- ...e_logged_user_seeing_about_screen.steps.js | 82 +++++++++++++++---- .../steps/playing_full_game_positive.steps.js | 3 +- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/webapp/e2e/jest.config.js b/webapp/e2e/jest.config.js index 1f4b748c..461bc936 100644 --- a/webapp/e2e/jest.config.js +++ b/webapp/e2e/jest.config.js @@ -1,5 +1,5 @@ module.exports = { - testMatch: ["**/playing_full_game_pos*.steps.js","**/about.steps.js", "**/login_positive.steps.js"], + testMatch: ["**/playing_full_game_pos*.steps.js","**/about.steps.js", "**/login_positive.steps.js","**/about_positive_logged_user_seeing_about_screen.steps.js"], moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], testTimeout: 30000 } \ No newline at end of file diff --git a/webapp/e2e/steps/about_positive_logged_user_seeing_about_screen.steps.js b/webapp/e2e/steps/about_positive_logged_user_seeing_about_screen.steps.js index 975b6439..848384f9 100644 --- a/webapp/e2e/steps/about_positive_logged_user_seeing_about_screen.steps.js +++ b/webapp/e2e/steps/about_positive_logged_user_seeing_about_screen.steps.js @@ -1,8 +1,3 @@ - -const {registerUserFromRootDirectory} = require('../e2e_utils/e2e_utils_register.js'); -const {waitForPageToLoad} = require('../e2e_utils/e2e_utils_timeout.js'); -const {logOutUser} = require('../e2e_utils/e2e_utils_logout.js'); -const {loginUserFromRootDirectory} = require('../e2e_utils/e2e_utils_login.js'); const { defineFeature, loadFeature }=require('jest-cucumber'); const puppeteer = require('puppeteer'); const setDefaultOptions = require("expect-puppeteer").setDefaultOptions; @@ -13,13 +8,11 @@ let browser; defineFeature(feature, test => { let username = "t.about.pos"; - let email; - let password; beforeAll(async () => { browser = process.env.GITHUB_ACTIONS - ? await puppeteer.launch() - : await puppeteer.launch({ headless: false, slowMo: 100 }); + ? await puppeteer.launch({ ignoreHTTPSErrors: true}) + : await puppeteer.launch({ headless: false, slowMo: 100, ignoreHTTPSErrors: true }); page = await browser.newPage(); //Way of setting up the timeout setDefaultOptions({ timeout: 10000 }) @@ -31,19 +24,17 @@ defineFeature(feature, test => { .catch(() => {}); // Registering the user before the tests - let credentials = registerUserFromRootDirectory(username, page); - email = credentials[0]; - username = credentials[1]; + await registerUserFromRootDirectory(username, page); // Logging it out - logOutUser(page); + await logOutUser(page); }, 120000); test("A logged user wants to see the about screen of the webpage", ({given,when,and,then}) => { given("A logged user in the main menu", async () => { - loginUserFromRootDirectory(username, email, password, page); + await loginUserFromRootDirectory(username, page); }); when("The user presses the button for deploying the lateral menu", async () => { @@ -55,7 +46,7 @@ defineFeature(feature, test => { }); then("The user is presented to the about screen", async () => { - waitForPageToLoad(); + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load let header = await page.$eval("h2", (element) => { return element.innerHTML }) @@ -68,4 +59,63 @@ defineFeature(feature, test => { done(); browser.close(); }); -}); \ No newline at end of file +}); +async function registerUserFromRootDirectory(username, page) { + // Credentials for the new user + let email = username + "@email.com" + let password = username + "psw" + + // Registering process + await expect(page).toClick("span[class='chakra-link css-1bicqx'"); + await expect(page).toFill("input[id='user'", email); + await expect(page).toFill("input[id='username'", username); + await expect(page).toFill("#password", password); + await expect(page).toFill("input[id='field-:r5:']", password); + await expect(page).toClick("button[data-testid='Sign up'"); + + // Checking for the process to be correct + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load + let header = await page.$eval("h2", (element) => { + return element.innerHTML + }) + let value = header === "Bienvenid@ " + username || header === "Welcome " + username; + expect(value).toBeTruthy(); + + return [email, password]; +} + +async function logOutUser(page) { + // Logging out + await expect(page).toClick("#lateralMenuButton"); + await new Promise(resolve => setTimeout(resolve, 5000)); + await expect(page).toClick("button[data-testid='LogOut']"); + + // Checking for the log out to be sucessful + await new Promise(resolve => setTimeout(resolve, 5000)); + let header = await page.$eval("button[data-testid='Login']", (element) => { + return element.innerHTML + }) + let value = header === "Login" || "Iniciar sesiĆ³n"; + + expect(value).toBeTruthy(); +} +async function loginUserFromRootDirectory(username, page) { + // Credentials for the new user + let email = username + "@email.com" + let password = username + "psw" + + // login process + await expect(page).toClick("button[data-testid='Login'"); + await expect(page).toFill("#user", email); + await expect(page).toFill("#password", password); + await expect(page).toClick("button[data-testid='Login'"); + + // Checking for the process to be correct + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load + let header = await page.$eval("h2", (element) => { + return element.innerHTML + }) + let value = header === "Bienvenid@ " + username || header === "Welcome " + username; + expect(value).toBeTruthy(); + +} \ No newline at end of file diff --git a/webapp/e2e/steps/playing_full_game_positive.steps.js b/webapp/e2e/steps/playing_full_game_positive.steps.js index 0b1dfa57..b0eedbb0 100644 --- a/webapp/e2e/steps/playing_full_game_positive.steps.js +++ b/webapp/e2e/steps/playing_full_game_positive.steps.js @@ -370,7 +370,8 @@ async function loginUserFromRootDirectory(username, page) { } async function logOutUser(page) { // Logging out - await expect(page).toClick("#lateralMenuButton"); + await expect(page).toClick("#lateralMenuButton"); + await new Promise(resolve => setTimeout(resolve, 5000)); await expect(page).toClick("button[data-testid='LogOut']"); // Checking for the log out to be sucessful