From 13d23d40aea1c0828628f7ebad8f97b0c003f400 Mon Sep 17 00:00:00 2001 From: "Dario G. Mori" Date: Sun, 5 May 2024 20:05:16 +0200 Subject: [PATCH] fix: login register negative --- ...er_negative_incorrect_credentials.steps.js | 56 +++++++++++++++++-- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/webapp/e2e/steps/login_register_negative_incorrect_credentials.steps.js b/webapp/e2e/steps/login_register_negative_incorrect_credentials.steps.js index 962bad69..66b941fc 100644 --- a/webapp/e2e/steps/login_register_negative_incorrect_credentials.steps.js +++ b/webapp/e2e/steps/login_register_negative_incorrect_credentials.steps.js @@ -1,5 +1,3 @@ -import { waitForPageToLoad } from '../e2e_utils/e2e_utils_timeout.js'; - const { defineFeature, loadFeature }=require('jest-cucumber'); const puppeteer = require('puppeteer'); const setDefaultOptions = require("expect-puppeteer").setDefaultOptions; @@ -27,12 +25,17 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); + // Registering the user before the tests + await registerUserFromRootDirectory(username, page); + + // Logging it out + await logOutUser(page); }, 120000); test("A registered user wants to log in using his credentials but they do not match any registered user", ({given,when,and,then}) => { given('A registered user in the root screen', async () => { - waitForPageToLoad(); + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load let header = await page.$eval("button[data-testid='Login']", (element) => { return element.innerHTML }) @@ -46,7 +49,7 @@ defineFeature(feature, test => { }); and('User enters in the log in 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 }) @@ -65,7 +68,7 @@ defineFeature(feature, test => { }); then('Log in screen shows an informative error message and does not allow the user to log in', async() => { - waitForPageToLoad(); + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -80,4 +83,45 @@ 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)); // Waiting for page to fully load + 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(); +} \ No newline at end of file