diff --git a/webapp/e2e/jest.config.js b/webapp/e2e/jest.config.js index 9efab019..e4673362 100644 --- a/webapp/e2e/jest.config.js +++ b/webapp/e2e/jest.config.js @@ -1,6 +1,5 @@ module.exports = { - testMatch: ["**/playing_full_game_pos*.steps.js","**/login_register_negative_bad_email_format.steps.js","**/login_register_negative_blank_email_credentials.steps.js", "**/login_positive.steps.js","**/about_positive_logged_user_seeing_about_screen.steps.js" - ,"**/about_positive_non_logged_user_seeing_about_screen.steps.js","**/login_register_negative_blank_password_credentials.steps.js","**/register*.steps.js"], + testMatch: ["**/playing*.steps.js","**/login*.steps.js","**/about*.steps.js","**/register*.steps.js","**/seeing*.steps.js"], moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], testTimeout: 30000 } \ No newline at end of file diff --git a/webapp/e2e/steps/playing_game_negative_non_logged_user.steps.js b/webapp/e2e/steps/playing_game_negative_non_logged_user.steps.js index 02fa571b..f1674fd7 100644 --- a/webapp/e2e/steps/playing_game_negative_non_logged_user.steps.js +++ b/webapp/e2e/steps/playing_game_negative_non_logged_user.steps.js @@ -12,11 +12,6 @@ let browser; defineFeature(feature, test => { - let username = "t.play.neg" - let user; - let password; - - beforeAll(async () => { browser = process.env.GITHUB_ACTIONS ? await puppeteer.launch({ ignoreHTTPSErrors: true }) @@ -33,9 +28,6 @@ defineFeature(feature, test => { }, 120000); test("A non-logged user wants to play a new game", ({given,when,then}) => { - let username = "pepe" - let user = username + "@pepe.com" - let password = "pepe" let gameURL = "http://localhost:3000/dashboard/game"; @@ -44,7 +36,7 @@ defineFeature(feature, test => { }); when('Entering the endpoint via URL', async() => { - waitForPageToLoad(); + await new Promise(resolve => setTimeout(resolve, 5000)); await page .goto(gameURL, { waitUntil: "networkidle0", @@ -55,7 +47,7 @@ defineFeature(feature, test => { then('No new game is created and the user is redirected to the log in screen', async() => { - waitForPageToLoad(); + await new Promise(resolve => setTimeout(resolve, 5000)); let header = await page.$eval("button[data-testid='Login']", (element) => { return element.innerHTML }) diff --git a/webapp/e2e/steps/seeing_rules_negative_non_logged_user.steps.js b/webapp/e2e/steps/seeing_rules_negative_non_logged_user.steps.js index b7754271..2e36fe78 100644 --- a/webapp/e2e/steps/seeing_rules_negative_non_logged_user.steps.js +++ b/webapp/e2e/steps/seeing_rules_negative_non_logged_user.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; @@ -12,10 +7,6 @@ let browser; defineFeature(feature, test => { - let username = "t.rules.neg" - let user; - let password; - beforeAll(async () => { browser = process.env.GITHUB_ACTIONS @@ -36,7 +27,7 @@ defineFeature(feature, test => { let gameURL = "http://localhost:3000/dashboard/game"; given('A non-logged user in main menu', async () => { - waitForPageToLoad(); + await new Promise(resolve => setTimeout(resolve, 5000)); let header = await page.$eval("button[data-testid='Login']", (element) => { return element.innerHTML }) @@ -54,7 +45,7 @@ defineFeature(feature, test => { }); then('The user is redirected to the log in screen', async() => { - waitForPageToLoad(); + await new Promise(resolve => setTimeout(resolve, 5000)); let header = await page.$eval("h2[class='chakra-heading css-79qjat']", (element) => { return element.innerHTML }) diff --git a/webapp/e2e/steps/seeing_rules_positive.steps.js b/webapp/e2e/steps/seeing_rules_positive.steps.js index f73ef6d3..18fec061 100644 --- a/webapp/e2e/steps/seeing_rules_positive.steps.js +++ b/webapp/e2e/steps/seeing_rules_positive.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; @@ -29,6 +24,12 @@ 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 logged user wants to see the rules for the game", ({given,when,and,then}) => { @@ -46,7 +47,7 @@ defineFeature(feature, test => { await expect(page).toClick("button[data-testid='Login'"); // Checking user is in main screen - waitForPageToLoad(); + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load let header = await page.$eval("h2[class='chakra-heading css-79qjat']", (element) => { return element.innerHTML }) @@ -57,7 +58,7 @@ defineFeature(feature, test => { }); when('The user presses the button for deploying the lateral menu', async() => { - waitForPageToLoad(); + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load await expect(page).toClick("#lateralMenuButton"); }); @@ -68,7 +69,7 @@ defineFeature(feature, test => { }); then("The screen shows redirects the user to the rules' screen", async() => { - waitForPageToLoad(); + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load let header = await page.$eval("h2[class='chakra-heading css-79qjat']", (element) => { return element.innerHTML }) @@ -82,4 +83,44 @@ 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 diff --git a/webapp/e2e/steps/seeing_stats_negative_non_logged_user.steps.js b/webapp/e2e/steps/seeing_stats_negative_non_logged_user.steps.js index 28c723c5..456d9f0c 100644 --- a/webapp/e2e/steps/seeing_stats_negative_non_logged_user.steps.js +++ b/webapp/e2e/steps/seeing_stats_negative_non_logged_user.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; @@ -12,11 +7,6 @@ let browser; defineFeature(feature, test => { - let username = "t.stats.neg" - let user; - let password; - - beforeAll(async () => { browser = process.env.GITHUB_ACTIONS ? await puppeteer.launch({ ignoreHTTPSErrors: true }) @@ -36,7 +26,7 @@ defineFeature(feature, test => { let gameURL = "http://localhost:3000/dashboard/game"; given('A non-logged user in main menu', async () => { - waitForPageToLoad(); // Waiting for page to fully load + 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 }) @@ -54,7 +44,7 @@ defineFeature(feature, test => { }); then('The user is redirected to 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[class='chakra-heading css-79qjat']", (element) => { return element.innerHTML }) diff --git a/webapp/e2e/steps/seeing_stats_positive.steps.js b/webapp/e2e/steps/seeing_stats_positive.steps.js index 75fe405e..87c83dd0 100644 --- a/webapp/e2e/steps/seeing_stats_positive.steps.js +++ b/webapp/e2e/steps/seeing_stats_positive.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; @@ -30,6 +25,12 @@ 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 logged user with many games wants to see its stats", ({given,when,and,then}) => { @@ -83,4 +84,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