diff --git a/webapp/e2e/steps/register_negative_blank_password.steps.js b/webapp/e2e/steps/register_negative_blank_password.steps.js index fe894547..077cbcb0 100644 --- a/webapp/e2e/steps/register_negative_blank_password.steps.js +++ b/webapp/e2e/steps/register_negative_blank_password.steps.js @@ -1,21 +1,15 @@ -import { registerUserFromRootDirectory}from '../e2e_utils/e2e_utils_register.js'; -import { waitForPageToLoad } from '../e2e_utils/e2e_utils_timeout.js'; -import { logOutUser } from '../e2e_utils/e2e_utils_logout.js'; -import { loginUserFromRootDirectory } from '../e2e_utils/e2e_utils_login.js' - const { defineFeature, loadFeature }=require('jest-cucumber'); const puppeteer = require('puppeteer'); const setDefaultOptions = require("expect-puppeteer").setDefaultOptions; const feature = loadFeature('./features/register_form_features/negative_register_blank_password.feature'); -const crypto = require('crypto'); let page; let browser; defineFeature(feature, test => { let username = "t.reg.neg.blk_ps" - let user; - let password; + let user = username + "@gmail.com"; + let password = username + ".psw"; beforeAll(async () => { browser = process.env.GITHUB_ACTIONS @@ -52,7 +46,9 @@ 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, 6000)); + + let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -60,6 +56,9 @@ defineFeature(feature, test => { || header === "Invalid email format or credentials (username or email) already in use"; expect(value).toBeTruthy(); + await new Promise(resolve => setTimeout(resolve, 6000)); + + }); }, 600000); @@ -67,4 +66,105 @@ defineFeature(feature, test => { done(); browser.close(); }); -}); \ No newline at end of file +}); + + + + + +/** + * Note: e2e Testing purposes only! + * Auxiliar function for logging out an user from any directory of the user. + * Beware if the user is playing a game when logging out + * It also ensures the task has been performed successfully. + * + * @param {*} page The website + */ +async function logOutUser(page) { + // Logging out + await expect(page).toClick("#lateralMenuButton"); + await expect(page).toClick("button[data-testid='LogOut']"); + + // Checking for the log out to be sucessful + await new Promise(resolve => setTimeout(resolve, 6000)); + + + let header = await page.$eval("button[data-testid='Login']", (element) => { + return element.innerHTML + }) + let value = header === "Login" || "Iniciar sesión"; + + expect(value).toBeTruthy(); +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function for login an user using its credentials from the root directory of the website. +* It also ensures the task has been performed successfully. +* +* @param username The username for the user. Currently we are using codes for each test case. +* @param email The email for the user. If none is defined, the username (a code) + '@gmail.com' is used +* @param password The password for the user. If none is defined, the username (a code) + '.ps' is used +* Beware of constraits for the user password. +* @param page The website +*/ +async function loginUserFromRootDirectory(username, email = username + "@gmail.com", password = username + ".ps", page) { + + // 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, 6000)); // 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(); + +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function for registering a new user from the root directory of the website. +* It also ensures the task has been performed successfully. +* +* @param {*} username The username for the new user. Currently we are using codes for each test case. +* @param {*} page The website +* @returns An array with the credentials of the user created [email, username] +*/ +async function registerUserFromRootDirectory(username, page) { + // Credentials for the new user + let email = username + "@email.com" + let password = username + "ps" + + // Registeing 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, 6000)); // 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]; +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function that times out the tests for some time, so the page can be fully loaded. +* @param {*} timeout_ms Amount of ms to wait. +*/ +async function waitForPageToLoad(timeout_ms = 6000) { + await new Promise(resolve => setTimeout(resolve, timeout_ms)); +} + diff --git a/webapp/e2e/steps/register_negative_blank_repeated_password.steps.js b/webapp/e2e/steps/register_negative_blank_repeated_password.steps.js index 460dd138..b1fa64a1 100644 --- a/webapp/e2e/steps/register_negative_blank_repeated_password.steps.js +++ b/webapp/e2e/steps/register_negative_blank_repeated_password.steps.js @@ -1,21 +1,16 @@ -import { registerUserFromRootDirectory}from '../e2e_utils/e2e_utils_register.js'; -import { waitForPageToLoad } from '../e2e_utils/e2e_utils_timeout.js'; -import { logOutUser } from '../e2e_utils/e2e_utils_logout.js'; -import { loginUserFromRootDirectory } from '../e2e_utils/e2e_utils_login.js' - const { defineFeature, loadFeature }=require('jest-cucumber'); const puppeteer = require('puppeteer'); const setDefaultOptions = require("expect-puppeteer").setDefaultOptions; const feature = loadFeature('./features/register_form_features/negative_register_blank_repeated_password.feature'); -const crypto = require('crypto'); + let page; let browser; defineFeature(feature, test => { let username = "t.reg.neg.bl_r_ps" - let user; - let password; + let user = username + "@gmail.com"; + let password = username + ".psw"; beforeAll(async () => { browser = process.env.GITHUB_ACTIONS @@ -52,7 +47,9 @@ 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, 6000)); + + let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -67,4 +64,106 @@ defineFeature(feature, test => { done(); browser.close(); }); -}); \ No newline at end of file +}); + + + + + +/** + * Note: e2e Testing purposes only! + * Auxiliar function for logging out an user from any directory of the user. + * Beware if the user is playing a game when logging out + * It also ensures the task has been performed successfully. + * + * @param {*} page The website + */ +async function logOutUser(page) { + // Logging out + await expect(page).toClick("#lateralMenuButton"); + await expect(page).toClick("button[data-testid='LogOut']"); + + // Checking for the log out to be sucessful + await new Promise(resolve => setTimeout(resolve, 6000)); + + + let header = await page.$eval("button[data-testid='Login']", (element) => { + return element.innerHTML + }) + let value = header === "Login" || "Iniciar sesión"; + + expect(value).toBeTruthy(); +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function for login an user using its credentials from the root directory of the website. +* It also ensures the task has been performed successfully. +* +* @param username The username for the user. Currently we are using codes for each test case. +* @param email The email for the user. If none is defined, the username (a code) + '@gmail.com' is used +* @param password The password for the user. If none is defined, the username (a code) + '.ps' is used +* Beware of constraits for the user password. +* @param page The website +*/ +async function loginUserFromRootDirectory(username, email = username + "@gmail.com", password = username + ".ps", page) { + + // 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, 6000)); // 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(); + +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function for registering a new user from the root directory of the website. +* It also ensures the task has been performed successfully. +* +* @param {*} username The username for the new user. Currently we are using codes for each test case. +* @param {*} page The website +* @returns An array with the credentials of the user created [email, username] +*/ +async function registerUserFromRootDirectory(username, page) { + // Credentials for the new user + let email = username + "@email.com" + let password = username + "ps" + + // Registeing 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, 6000)); // 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]; +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function that times out the tests for some time, so the page can be fully loaded. +* @param {*} timeout_ms Amount of ms to wait. +*/ +async function waitForPageToLoad(timeout_ms = 6000) { + await new Promise(resolve => setTimeout(resolve, timeout_ms)); + +} + diff --git a/webapp/e2e/steps/register_negative_blank_username.steps.js b/webapp/e2e/steps/register_negative_blank_username.steps.js index 2ae7fc69..03a869e1 100644 --- a/webapp/e2e/steps/register_negative_blank_username.steps.js +++ b/webapp/e2e/steps/register_negative_blank_username.steps.js @@ -1,8 +1,3 @@ -import { registerUserFromRootDirectory}from '../e2e_utils/e2e_utils_register.js'; -import { waitForPageToLoad } from '../e2e_utils/e2e_utils_timeout.js'; -import { logOutUser } from '../e2e_utils/e2e_utils_logout.js'; -import { loginUserFromRootDirectory } from '../e2e_utils/e2e_utils_login.js' - const { defineFeature, loadFeature }=require('jest-cucumber'); const puppeteer = require('puppeteer'); const setDefaultOptions = require("expect-puppeteer").setDefaultOptions; @@ -14,9 +9,8 @@ let browser; defineFeature(feature, test => { let username = "t.reg.blk_un" - let user; - let password; - + let user = username + "@gmail.com"; + let password = username + ".psw"; beforeAll(async () => { browser = process.env.GITHUB_ACTIONS @@ -54,7 +48,9 @@ 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, 6000)); + + let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -69,4 +65,104 @@ defineFeature(feature, test => { done(); browser.close(); }); -}); \ No newline at end of file +}); + + + +/** + * Note: e2e Testing purposes only! + * Auxiliar function for logging out an user from any directory of the user. + * Beware if the user is playing a game when logging out + * It also ensures the task has been performed successfully. + * + * @param {*} page The website + */ +async function logOutUser(page) { + // Logging out + await expect(page).toClick("#lateralMenuButton"); + await expect(page).toClick("button[data-testid='LogOut']"); + + // Checking for the log out to be sucessful + await new Promise(resolve => setTimeout(resolve, 6000)); + + + let header = await page.$eval("button[data-testid='Login']", (element) => { + return element.innerHTML + }) + let value = header === "Login" || "Iniciar sesión"; + + expect(value).toBeTruthy(); +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function for login an user using its credentials from the root directory of the website. +* It also ensures the task has been performed successfully. +* +* @param username The username for the user. Currently we are using codes for each test case. +* @param email The email for the user. If none is defined, the username (a code) + '@gmail.com' is used +* @param password The password for the user. If none is defined, the username (a code) + '.ps' is used +* Beware of constraits for the user password. +* @param page The website +*/ +async function loginUserFromRootDirectory(username, email = username + "@gmail.com", password = username + ".ps", page) { + + // 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, 6000)); // 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(); + +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function for registering a new user from the root directory of the website. +* It also ensures the task has been performed successfully. +* +* @param {*} username The username for the new user. Currently we are using codes for each test case. +* @param {*} page The website +* @returns An array with the credentials of the user created [email, username] +*/ +async function registerUserFromRootDirectory(username, page) { + // Credentials for the new user + let email = username + "@email.com" + let password = username + "ps" + + // Registeing 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, 6000)); // 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]; +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function that times out the tests for some time, so the page can be fully loaded. +* @param {*} timeout_ms Amount of ms to wait. +*/ +async function waitForPageToLoad(timeout_ms = 6000) { + await new Promise(resolve => setTimeout(resolve, timeout_ms)); + +} + diff --git a/webapp/e2e/steps/register_negative_email_already_in_use_form.steps.js b/webapp/e2e/steps/register_negative_email_already_in_use_form.steps.js index 4b2d2f5f..ec1876f1 100644 --- a/webapp/e2e/steps/register_negative_email_already_in_use_form.steps.js +++ b/webapp/e2e/steps/register_negative_email_already_in_use_form.steps.js @@ -1,8 +1,3 @@ -import { registerUserFromRootDirectory}from '../e2e_utils/e2e_utils_register.js'; -import { waitForPageToLoad } from '../e2e_utils/e2e_utils_timeout.js'; -import { logOutUser } from '../e2e_utils/e2e_utils_logout.js'; -import { loginUserFromRootDirectory } from '../e2e_utils/e2e_utils_login.js' - const { defineFeature, loadFeature }=require('jest-cucumber'); const puppeteer = require('puppeteer'); const setDefaultOptions = require("expect-puppeteer").setDefaultOptions; @@ -14,8 +9,8 @@ let browser; defineFeature(feature, test => { let username = "t.reg.neg.em_aiu" - let user; - let password; + let email = username + "@gmail.com"; + let password = username + ".psw"; beforeAll(async () => { @@ -31,6 +26,13 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); + + // Registering the user before the tests + await registerUserFromRootDirectory(username, page); + + // Logging it out + await logOutUser(page) + }, 120000); test("The user is not registered in the root directory of the website", ({given,when,and,then}) => { @@ -40,7 +42,7 @@ defineFeature(feature, test => { when("the user fills the data in the form using an already used email", async () => { await expect(page).toClick("span[class='chakra-link css-1bicqx'"); - await expect(page).toFill("input[id='user'", user); + 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); @@ -53,7 +55,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, 6000)); let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -68,4 +70,103 @@ defineFeature(feature, test => { done(); browser.close(); }); -}); \ No newline at end of file +}); + + + + +/** + * Note: e2e Testing purposes only! + * Auxiliar function for logging out an user from any directory of the user. + * Beware if the user is playing a game when logging out + * It also ensures the task has been performed successfully. + * + * @param {*} page The website + */ +async function logOutUser(page) { + // Logging out + await expect(page).toClick("#lateralMenuButton"); + await expect(page).toClick("button[data-testid='LogOut']"); + + // Checking for the log out to be sucessful + waitForPageToLoad(); + let header = await page.$eval("button[data-testid='Login']", (element) => { + return element.innerHTML + }) + let value = header === "Login" || "Iniciar sesión"; + + expect(value).toBeTruthy(); +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function for login an user using its credentials from the root directory of the website. +* It also ensures the task has been performed successfully. +* +* @param username The username for the user. Currently we are using codes for each test case. +* @param email The email for the user. If none is defined, the username (a code) + '@gmail.com' is used +* @param password The password for the user. If none is defined, the username (a code) + '.ps' is used +* Beware of constraits for the user password. +* @param page The website +*/ +async function loginUserFromRootDirectory(username, email = username + "@gmail.com", password = username + ".ps", page) { + + // 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, 6000)); // 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(); + +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function for registering a new user from the root directory of the website. +* It also ensures the task has been performed successfully. +* +* @param {*} username The username for the new user. Currently we are using codes for each test case. +* @param {*} page The website +* @returns An array with the credentials of the user created [email, username] +*/ +async function registerUserFromRootDirectory(username, page) { + // Credentials for the new user + let email = username + "@email.com" + let password = username + "ps" + + // Registeing 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, 6000)); // 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]; +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function that times out the tests for some time, so the page can be fully loaded. +* @param {*} timeout_ms Amount of ms to wait. +*/ +async function waitForPageToLoad(timeout_ms = 6000) { + await new Promise(resolve => setTimeout(resolve, timeout_ms)); + +} + diff --git a/webapp/e2e/steps/register_negative_username_already_in_use_form.steps.js b/webapp/e2e/steps/register_negative_username_already_in_use_form.steps.js index cda4f9d6..21b213eb 100644 --- a/webapp/e2e/steps/register_negative_username_already_in_use_form.steps.js +++ b/webapp/e2e/steps/register_negative_username_already_in_use_form.steps.js @@ -1,8 +1,3 @@ -import { registerUserFromRootDirectory}from '../e2e_utils/e2e_utils_register.js'; -import { waitForPageToLoad } from '../e2e_utils/e2e_utils_timeout.js'; -import { logOutUser } from '../e2e_utils/e2e_utils_logout.js'; -import { loginUserFromRootDirectory } from '../e2e_utils/e2e_utils_login.js' - const { defineFeature, loadFeature }=require('jest-cucumber'); const puppeteer = require('puppeteer'); const setDefaultOptions = require("expect-puppeteer").setDefaultOptions; @@ -14,8 +9,8 @@ let browser; defineFeature(feature, test => { let username = "t.reg.neg.un_aiu" - let user; - let password; + let user = username + "@gmail.com"; + let password = username + ".psw"; beforeAll(async () => { @@ -53,7 +48,9 @@ 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, 6000)); + + let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -68,4 +65,104 @@ defineFeature(feature, test => { done(); browser.close(); }); -}); \ No newline at end of file +}); + + + +/** + * Note: e2e Testing purposes only! + * Auxiliar function for logging out an user from any directory of the user. + * Beware if the user is playing a game when logging out + * It also ensures the task has been performed successfully. + * + * @param {*} page The website + */ +async function logOutUser(page) { + // Logging out + await expect(page).toClick("#lateralMenuButton"); + await expect(page).toClick("button[data-testid='LogOut']"); + + // Checking for the log out to be sucessful + await new Promise(resolve => setTimeout(resolve, 6000)); + + + let header = await page.$eval("button[data-testid='Login']", (element) => { + return element.innerHTML + }) + let value = header === "Login" || "Iniciar sesión"; + + expect(value).toBeTruthy(); +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function for login an user using its credentials from the root directory of the website. +* It also ensures the task has been performed successfully. +* +* @param username The username for the user. Currently we are using codes for each test case. +* @param email The email for the user. If none is defined, the username (a code) + '@gmail.com' is used +* @param password The password for the user. If none is defined, the username (a code) + '.ps' is used +* Beware of constraits for the user password. +* @param page The website +*/ +async function loginUserFromRootDirectory(username, email = username + "@gmail.com", password = username + ".ps", page) { + + // 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, 6000)); // 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(); + +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function for registering a new user from the root directory of the website. +* It also ensures the task has been performed successfully. +* +* @param {*} username The username for the new user. Currently we are using codes for each test case. +* @param {*} page The website +* @returns An array with the credentials of the user created [email, username] +*/ +async function registerUserFromRootDirectory(username, page) { + // Credentials for the new user + let email = username + "@email.com" + let password = username + "ps" + + // Registeing 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, 6000)); // 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]; +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function that times out the tests for some time, so the page can be fully loaded. +* @param {*} timeout_ms Amount of ms to wait. +*/ +async function waitForPageToLoad(timeout_ms = 6000) { + await new Promise(resolve => setTimeout(resolve, timeout_ms)); + +} + diff --git a/webapp/e2e/steps/register_negative_wrong_email_format.steps.js b/webapp/e2e/steps/register_negative_wrong_email_format.steps.js index ee10f30b..fd799f4e 100644 --- a/webapp/e2e/steps/register_negative_wrong_email_format.steps.js +++ b/webapp/e2e/steps/register_negative_wrong_email_format.steps.js @@ -1,21 +1,15 @@ -import { registerUserFromRootDirectory}from '../e2e_utils/e2e_utils_register.js'; -import { waitForPageToLoad } from '../e2e_utils/e2e_utils_timeout.js'; -import { logOutUser } from '../e2e_utils/e2e_utils_logout.js'; -import { loginUserFromRootDirectory } from '../e2e_utils/e2e_utils_login.js' - const { defineFeature, loadFeature }=require('jest-cucumber'); const puppeteer = require('puppeteer'); const setDefaultOptions = require("expect-puppeteer").setDefaultOptions; const feature = loadFeature('./features/register_form_features/negative_register_wrong_email_format.feature'); -const crypto = require('crypto'); let page; let browser; defineFeature(feature, test => { - let username = "t.reg.neg.wr_em" - let user; - let password; + let username = "t.reg.neg.wr_em"; + let user = username + "@gmail.com"; + let password = username + ".psw"; beforeAll(async () => { browser = process.env.GITHUB_ACTIONS @@ -52,7 +46,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, 6000)); let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -68,9 +62,70 @@ defineFeature(feature, test => { browser.close(); }); }); +/** + * Note: e2e Testing purposes only! + * Auxiliar function for logging out an user from any directory of the user. + * Beware if the user is playing a game when logging out + * It also ensures the task has been performed successfully. + * + * @param {*} page The website + */ +async function logOutUser(page) { + // Logging out + await expect(page).toClick("#lateralMenuButton"); + await expect(page).toClick("button[data-testid='LogOut']"); + + // Checking for the log out to be sucessful + await new Promise(resolve => setTimeout(resolve, 6000)); + + + let header = await page.$eval("button[data-testid='Login']", (element) => { + return element.innerHTML + }) + let value = header === "Login" || "Iniciar sesión"; + + expect(value).toBeTruthy(); +} + +/** +* Note: e2e Testing purposes only! +* Auxiliar function for login an user using its credentials from the root directory of the website. +* It also ensures the task has been performed successfully. +* +* @param username The username for the user. Currently we are using codes for each test case. +* @param email The email for the user. If none is defined, the username (a code) + '@gmail.com' is used +* @param password The password for the user. If none is defined, the username (a code) + '.ps' is used +* Beware of constraits for the user password. +* @param page The website +*/ +async function loginUserFromRootDirectory(username, email = username + "@gmail.com", password = username + ".ps", page) { + + // 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, 6000)); // 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(); +} -async function registerUserFromRootDirectory(username) { +/** +* Note: e2e Testing purposes only! +* Auxiliar function for registering a new user from the root directory of the website. +* It also ensures the task has been performed successfully. +* +* @param {*} username The username for the new user. Currently we are using codes for each test case. +* @param {*} page The website +* @returns An array with the credentials of the user created [email, username] +*/ +async function registerUserFromRootDirectory(username, page) { // Credentials for the new user let email = username + "@email.com" let password = username + "ps" @@ -94,4 +149,13 @@ async function registerUserFromRootDirectory(username) { return [email, password]; } -modules.export ={registerUserFromRootDirectory}; \ No newline at end of file +/** +* Note: e2e Testing purposes only! +* Auxiliar function that times out the tests for some time, so the page can be fully loaded. +* @param {*} timeout_ms Amount of ms to wait. +*/ +async function waitForPageToLoad(timeout_ms = 6000) { + await new Promise(resolve => setTimeout(resolve, timeout_ms)); + +} +