diff --git a/webapp/e2e/jest.config.js b/webapp/e2e/jest.config.js index 1f4b748c..a1e2040a 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: ["**/*.steps.js"], moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], testTimeout: 30000 } \ No newline at end of file diff --git a/webapp/e2e/steps/about.steps.js b/webapp/e2e/steps/about.steps.js deleted file mode 100644 index ef5e2077..00000000 --- a/webapp/e2e/steps/about.steps.js +++ /dev/null @@ -1,77 +0,0 @@ -const { defineFeature, loadFeature }=require('jest-cucumber'); -const puppeteer = require('puppeteer'); -const setDefaultOptions = require("expect-puppeteer").setDefaultOptions; -const feature = loadFeature('./features/about_features/positive_logged_user_seeing_about_screen.feature'); -let page; -let browser; - -defineFeature(feature, test => { - - beforeAll(async () => { - browser = process.env.GITHUB_ACTIONS - ? 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 }) - - await page - .goto("http://localhost:3000", { - waitUntil: "networkidle0", - }) - .catch(() => {}); - }); - - test("A logged user wants to see the about screen of the webpage", ({given,when,and,then}) => { - - let username = "t.about"; - - given("A logged user in the main menu", async () => { - await registerUserFromRootDirectory(username,page) - }); - - when("The user presses the button for deploying the lateral menu", async () => { - await expect(page).toClick("#lateralMenuButton"); - }); - - and("the user presses the button for seeing the about section (i)", async () => { - await expect(page).toClick("#aboutButton"); - }); - - then("The user is presented to the about screen", async () => { - let header = await page.$eval("h2", (element) => { - return element.innerHTML - }) - let value = header === "About" || header === "Sobre nosotros"; - expect(value).toBeTruthy(); - }); - }); - - afterAll((done) => { - done(); - }); -}); - -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]; -} 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 d0015e4c..f2629561 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 @@ -7,11 +7,12 @@ let browser; defineFeature(feature, test => { + let username = "about_pos"; 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 }) @@ -21,21 +22,19 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); - test("A logged user wants to see the about screen of the webpage", ({given,when,and,then}) => { + // Registering the user before the tests + await registerUserFromRootDirectory(username, page); - let username; - let password; - - given("A logged user in the main menu", async () => { - username = "test@email.com" - password = "password" - - await expect(page).toClick("button[data-testid='Login'"); - await expect(page).toFill("#user", username); - await expect(page).toFill("#password", password); - await expect(page).toClick("button[data-testid='Login'"); + // Logging it out + 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 () => { + await loginUserFromRootDirectory(username, page); }); when("The user presses the button for deploying the lateral menu", async () => { @@ -43,11 +42,12 @@ defineFeature(feature, test => { }); and("the user presses the button for seeing the about section (i)", async () => { + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load await expect(page).toClick("#aboutButton"); }); then("The user is presented to the about screen", async () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load let header = await page.$eval("h2", (element) => { return element.innerHTML }) @@ -60,4 +60,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/about_positive_non_logged_user_seeing_about_screen.steps.js b/webapp/e2e/steps/about_positive_non_logged_user_seeing_about_screen.steps.js index c2d02436..86d271c2 100644 --- a/webapp/e2e/steps/about_positive_non_logged_user_seeing_about_screen.steps.js +++ b/webapp/e2e/steps/about_positive_non_logged_user_seeing_about_screen.steps.js @@ -7,11 +7,10 @@ let browser; defineFeature(feature, test => { - 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 }) @@ -21,7 +20,7 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + }, 120000); test("A non-logged user wants to see the about screen of the webpage", ({given,when,and,then}) => { @@ -34,11 +33,12 @@ defineFeature(feature, test => { }); and("the user presses the button for seeing the about section (i)", async () => { + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load await expect(page).toClick("#aboutButton"); }); then("The user is presented to the about screen", async () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load let header = await page.$eval("h2", (element) => { return element.innerHTML }) diff --git a/webapp/e2e/steps/login_register_negative_bad_email_format.steps.js b/webapp/e2e/steps/login_register_negative_bad_email_format.steps.js index e8a99808..3bf0be40 100644 --- a/webapp/e2e/steps/login_register_negative_bad_email_format.steps.js +++ b/webapp/e2e/steps/login_register_negative_bad_email_format.steps.js @@ -7,11 +7,14 @@ let browser; defineFeature(feature, test => { + let username = "t.login.neg.bad.em" + let password = username + "psw" ; + 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 }) @@ -21,15 +24,13 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + + }, 120000); test("A registered user wants to log in using his credentials but with an invalid email", ({given,when,and,then}) => { - let username = "pepe" - let user = username + "email.com" // Bad formatted email - let password = "Password" given('A registered user in the root screen', async () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // 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 }) @@ -43,7 +44,7 @@ defineFeature(feature, test => { }); and('User enters in the log in screen', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load let header = await page.$eval("h2", (element) => { return element.innerHTML }) @@ -53,7 +54,7 @@ defineFeature(feature, test => { }); and('User fills the form with his proper password but writes a wrong formatted email', async() => { - await expect(page).toFill("#user", user); + await expect(page).toFill("#user", username ); await expect(page).toFill("#password", password); }); @@ -62,7 +63,7 @@ defineFeature(feature, test => { }); then('Log in screen shows an informative error message and does not allow the user to log in', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + 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 }) @@ -77,4 +78,43 @@ 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(); +} \ No newline at end of file diff --git a/webapp/e2e/steps/login_register_negative_blank_email_credentials.steps.js b/webapp/e2e/steps/login_register_negative_blank_email_credentials.steps.js index 7b7c94fb..3814f182 100644 --- a/webapp/e2e/steps/login_register_negative_blank_email_credentials.steps.js +++ b/webapp/e2e/steps/login_register_negative_blank_email_credentials.steps.js @@ -10,8 +10,8 @@ defineFeature(feature, test => { 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 }) @@ -21,15 +21,12 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + }, 120000); test("A registered user wants to log in using his credentials but leaving the email in blank", ({given,when,and,then}) => { - let username = "pepe" - let user = "" - let password = "Password" given('A registered user in the root screen', async () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // 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 }) @@ -43,7 +40,7 @@ defineFeature(feature, test => { }); and('User enters in the log in screen', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load let header = await page.$eval("h2", (element) => { return element.innerHTML }) @@ -53,8 +50,8 @@ defineFeature(feature, test => { }); and('User fills the form with his proper password but leaves the email in blank', async() => { - await expect(page).toFill("#user", user); - await expect(page).toFill("#password", password); + await expect(page).toFill("#user", ""); + await expect(page).toFill("#password", "password"); }); and('User presses the log in button', async() => { @@ -62,7 +59,7 @@ defineFeature(feature, test => { }); then('Log in screen shows an informative error message and does not allow the user to log in', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + 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 }) diff --git a/webapp/e2e/steps/login_register_negative_blank_password_credentials.steps.js b/webapp/e2e/steps/login_register_negative_blank_password_credentials.steps.js index 508ad96c..526c021c 100644 --- a/webapp/e2e/steps/login_register_negative_blank_password_credentials.steps.js +++ b/webapp/e2e/steps/login_register_negative_blank_password_credentials.steps.js @@ -7,11 +7,13 @@ let browser; defineFeature(feature, test => { + let username = "t.login.neg.blnk_psw"; + 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 }) @@ -21,15 +23,13 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + }, 120000); test("A registered user wants to log in using his credentials but leaving the password in blank", ({given,when,and,then}) => { - let username = "pepe" - let user = username + "@email.com" - let password = "" // Blank password + given('A registered user in the root screen', async () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // 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 }) @@ -43,7 +43,7 @@ defineFeature(feature, test => { }); and('User enters in the log in screen', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load let header = await page.$eval("h2", (element) => { return element.innerHTML }) @@ -53,8 +53,8 @@ defineFeature(feature, test => { }); and('User fills the form with his proper email but leaves the password in blank', async() => { - await expect(page).toFill("#user", user); - await expect(page).toFill("#password", password); + await expect(page).toFill("#user", username+"@test.com"); + await expect(page).toFill("#password", ""); }); and('User presses the log in button', async() => { @@ -62,7 +62,7 @@ defineFeature(feature, test => { }); then('Log in screen shows an informative error message and does not allow the user to log in', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + 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 }) 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 d0d12347..50db0cd4 100644 --- a/webapp/e2e/steps/login_register_negative_incorrect_credentials.steps.js +++ b/webapp/e2e/steps/login_register_negative_incorrect_credentials.steps.js @@ -8,10 +8,14 @@ let browser; defineFeature(feature, test => { + let username = "login_bad_crd" + let user = username + "@email.com"; + let password = "wrongpassword"; + 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 }) @@ -21,15 +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}) => { - let username = "pepe" - let user = username + "@pepe.com" - let password = "notPepesPassword" given('A registered user in the root screen', async () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // 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 }) @@ -43,7 +49,7 @@ defineFeature(feature, test => { }); and('User enters in the log in screen', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load let header = await page.$eval("h2", (element) => { return element.innerHTML }) @@ -62,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() => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + 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 }) @@ -77,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 diff --git a/webapp/e2e/steps/logout_positive_logged_user.steps.js b/webapp/e2e/steps/logout_positive_logged_user.steps.js index 1bd5c71b..8bc91a95 100644 --- a/webapp/e2e/steps/logout_positive_logged_user.steps.js +++ b/webapp/e2e/steps/logout_positive_logged_user.steps.js @@ -7,11 +7,12 @@ let browser; defineFeature(feature, test => { + let username = "logout_p_logged" 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 }) @@ -21,49 +22,29 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); - - test("A logged user wants to log out the webpage", ({given,when,and,then}) => { - let username = "pepe" - let user = username + "@pepe.com" - let password = "pepe" - let gameURL = "http://localhost:3000/dashboard/game"; + }, 120000); + test("A logged user wants to log out the webpage", ({given,when,and,then}) => { given('A logged user in main menu', async () => { - let header = await page.$eval("button[data-testid='Login']", (element) => { - return element.innerHTML - }) - let value = header === "Login" || "Iniciar sesión"; - - expect(value).toBeTruthy(); - - await expect(page).toClick("button[data-testid='Login'"); - await expect(page).toFill("#user", user); - await expect(page).toFill("#password", password); - await expect(page).toClick("button[data-testid='Login'"); - - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load - let newHeader = await page.$eval("h2", (element) => { - return element.innerHTML - }) - let newValue = newHeader === "Bienvenid@ " + username || header === "Welcome " + username; - expect(newValue).toBeTruthy(); + // Registering the user before the tests + await registerUserFromRootDirectory(username, page); }); when('User presses the button for deploying the lateral menu', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); + await new Promise(resolve => setTimeout(resolve, 5000)); await expect(page).toClick("#lateralMenuButton"); }); and('User presses the log out button', async() => { - await expect(page).toClick("button[data-testid='LogOut']"); + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load + await expect(page).toClick("button[data-testid='LogOut']"); }); then('The login screen shows on the user device and the user is no longer logged in', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 5000)); let header = await page.$eval("button[data-testid='Login']", (element) => { return element.innerHTML }) @@ -77,4 +58,29 @@ 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]; +} + diff --git a/webapp/e2e/steps/logout_positive_non_logged_user.steps.js b/webapp/e2e/steps/logout_positive_non_logged_user.steps.js index ff54eb98..344964ec 100644 --- a/webapp/e2e/steps/logout_positive_non_logged_user.steps.js +++ b/webapp/e2e/steps/logout_positive_non_logged_user.steps.js @@ -7,11 +7,10 @@ let browser; defineFeature(feature, test => { - 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 }) @@ -21,17 +20,12 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + }, 120000); test("A non-logged user wants to log out the webpage", ({given,when,then}) => { - let username = "pepe" - let user = username + "@pepe.com" - let password = "pepe" - - let gameURL = "http://localhost:3000/dashboard/game"; given('A non-logged user in main menu', async () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 5000)); let header = await page.$eval("button[data-testid='Login']", (element) => { return element.innerHTML }) @@ -49,7 +43,7 @@ defineFeature(feature, test => { }); then('The login screen shows on the user device', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); + 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/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 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 4a361c24..320abdb4 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 @@ -7,11 +7,10 @@ let browser; defineFeature(feature, test => { - 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 }) @@ -21,12 +20,9 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + }, 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"; @@ -35,7 +31,7 @@ defineFeature(feature, test => { }); when('Entering the endpoint via URL', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); + await new Promise(resolve => setTimeout(resolve, 5000)); await page .goto(gameURL, { waitUntil: "networkidle0", @@ -46,7 +42,7 @@ defineFeature(feature, test => { then('No new game is created and the user is redirected to the log in screen', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + 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/register_negative_blank_password.steps.js b/webapp/e2e/steps/register_negative_blank_password.steps.js index f77905d3..075599ab 100644 --- a/webapp/e2e/steps/register_negative_blank_password.steps.js +++ b/webapp/e2e/steps/register_negative_blank_password.steps.js @@ -2,17 +2,19 @@ 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 = username + "@gmail.com"; + let password = username + ".psw"; 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 }) @@ -22,23 +24,9 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + }, 120000); test("The user is not registered in the root directory of the website and tries to create an account", ({given,when,and,then}) => { - // Trying to avoid repeated users: - // Generate random bytes - let randomBytes = crypto.randomBytes(8); // 8 bytes = 64 bits - // Convert bytes to hex - let hexString = randomBytes.toString('hex'); - // Take the first 16 characters - let randomHash = hexString.substring(0, 20); - - - - let username = "test" + randomHash - let user = username + "@email.com" - let password = "password" - given("An unregistered user", async () => { }); @@ -48,7 +36,7 @@ defineFeature(feature, test => { await expect(page).toFill("input[id='user'", user); await expect(page).toFill("input[id='username'", username); await expect(page).toFill("#password", ""); // Blank password - await expect(page).toFill("input[id='field-:r5:']", password); + await expect(page).toFill("input[data-testid='repeat-password']", "test3"); }); @@ -58,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 () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 6000)); + + let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -66,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); @@ -73,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 db009b5d..afac8c0f 100644 --- a/webapp/e2e/steps/register_negative_blank_repeated_password.steps.js +++ b/webapp/e2e/steps/register_negative_blank_repeated_password.steps.js @@ -2,17 +2,20 @@ 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 = username + "@gmail.com"; + let password = username + ".psw"; 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 }) @@ -22,23 +25,9 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); - - test("The user is not registered in the root directory of the website and tries to create an account", ({given,when,and,then}) => { - // Trying to avoid repeated users: - // Generate random bytes - let randomBytes = crypto.randomBytes(8); // 8 bytes = 64 bits - // Convert bytes to hex - let hexString = randomBytes.toString('hex'); - // Take the first 16 characters - let randomHash = hexString.substring(0, 20); - + }, 120000); - - let username = "test" + randomHash - let user = username + "@email.com" - let password = "password" - + test("The user is not registered in the root directory of the website and tries to create an account", ({given,when,and,then}) => { given("An unregistered user", async () => { }); @@ -48,7 +37,7 @@ defineFeature(feature, test => { await expect(page).toFill("input[id='user'", user); await expect(page).toFill("input[id='username'", username); await expect(page).toFill("#password", password); - await expect(page).toFill("input[id='field-:r5:']", ""); // Blank password + await expect(page).toFill("input[data-testid='repeat-password']", ""); // Blank password }); @@ -58,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 () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 6000)); + + let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -73,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 e744973a..800db9e4 100644 --- a/webapp/e2e/steps/register_negative_blank_username.steps.js +++ b/webapp/e2e/steps/register_negative_blank_username.steps.js @@ -8,11 +8,14 @@ let browser; defineFeature(feature, test => { + let username = "t.reg.blk_un" + let user = username + "@gmail.com"; + let password = username + ".psw"; 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 }) @@ -22,13 +25,10 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + }, 120000); test("The user is not registered in the root directory of the website and tries to create an account", ({given,when,and,then}) => { - let username = "" // Blank username - let user = "test@email.com" - let password = "password" - + given("An unregistered user", async () => { }); @@ -36,9 +36,9 @@ defineFeature(feature, test => { when("The user fills its data in the form leaving the username field in blank", 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='username'", username); + await expect(page).toFill("input[id='username'", ""); await expect(page).toFill("#password", password); - await expect(page).toFill("input[id='field-:r5:']", password); + await expect(page).toFill("input[data-testid='repeat-password']", password); }); @@ -48,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 () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 6000)); + + let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -63,4 +65,6 @@ defineFeature(feature, test => { done(); browser.close(); }); -}); \ No newline at end of file +}); + + 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 afdb36ad..a987dfae 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 @@ -8,11 +8,15 @@ let browser; defineFeature(feature, test => { + let username = "t.reg.neg.em_aiu" + let email = username + "@gmail.com"; + let password = username + ".psw"; + 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 }) @@ -22,30 +26,26 @@ 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}) => { - // Trying to avoid repeated users: - // Generate random bytes - let randomBytes = crypto.randomBytes(8); // 8 bytes = 64 bits - // Convert bytes to hex - let hexString = randomBytes.toString('hex'); - // Take the first 16 characters - let randomHash = hexString.substring(0, 20); - let username = "test" - let user = "test" + "@email.com" - let password = "password" - given("An unregistered user", async () => { }); 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); + await expect(page).toFill("input[data-testid='repeat-password']", password); }); @@ -55,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 () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 6000)); let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -70,4 +70,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(); +} 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 0f183d8c..fc91df33 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 @@ -8,11 +8,15 @@ let browser; defineFeature(feature, test => { + let username = "t.reg.neg.un_aiu" + let user = username + "@gmail.com"; + let password = username + "psw"; + 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 }) @@ -22,23 +26,24 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + + await registerUserFromRootDirectory(username,page); + + await logOutUser(page); + + }, 120000); test("The user is not registered in the root directory of the website and tries to create an account", ({given,when,and,then}) => { - let username = "test" - let user = username + "@emailNonRepeated.com" - let password = "password" - given("An unregistered user", async () => { }); when("The user fills the data in the form using an already used username", 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'", user+"a"); 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).toFill("input[data-testid='repeat-password']", password); }); @@ -48,7 +53,9 @@ defineFeature(feature, test => { }); then("Log in screen shows an informative error message and does not allow the user to log in", async () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 6000)); + + let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -63,4 +70,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(); +} + 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 ad089f77..318bbf35 100644 --- a/webapp/e2e/steps/register_negative_wrong_email_format.steps.js +++ b/webapp/e2e/steps/register_negative_wrong_email_format.steps.js @@ -2,17 +2,19 @@ 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 = username ; + let password = username + ".psw"; 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 }) @@ -22,23 +24,9 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + }, 120000); test("The user is not registered in the root directory of the website and tries to create an account", ({given,when,and,then}) => { - // Trying to avoid repeated users: - // Generate random bytes - let randomBytes = crypto.randomBytes(8); // 8 bytes = 64 bits - // Convert bytes to hex - let hexString = randomBytes.toString('hex'); - // Take the first 16 characters - let randomHash = hexString.substring(0, 20); - - - - let username = "test" + randomHash - let user = username + "email.com" // Bad format email - let password = "password" - given("An unregistered user", async () => { }); @@ -48,7 +36,7 @@ defineFeature(feature, test => { await expect(page).toFill("input[id='user'", user); 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).toFill("input[data-testid='repeat-password']", password); }); @@ -58,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 () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // Waiting for page to fully load + await new Promise(resolve => setTimeout(resolve, 6000)); let header = await page.$eval("div[class='chakra-alert__desc css-zzks76'", (element) => { return element.innerHTML }) @@ -73,4 +61,101 @@ 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_positive_form.steps.js b/webapp/e2e/steps/register_positive_form.steps.js index 9bac60eb..3e732eee 100644 --- a/webapp/e2e/steps/register_positive_form.steps.js +++ b/webapp/e2e/steps/register_positive_form.steps.js @@ -2,7 +2,6 @@ const { defineFeature, loadFeature }=require('jest-cucumber'); const puppeteer = require('puppeteer'); const setDefaultOptions = require("expect-puppeteer").setDefaultOptions; const feature = loadFeature('./features/register_form_features/positive_register_form.feature'); -const crypto = require('crypto'); let page; let browser; @@ -25,7 +24,7 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + }, 120000); test("The user is not registered in the root directory of the website", ({given,when,and,then}) => { given("An unregistered user", async () => { @@ -37,7 +36,7 @@ defineFeature(feature, test => { await expect(page).toFill("input[id='user'", userEmail); 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).toFill("input[data-testid='repeat-password']", password); }); 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 69a57232..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 @@ -10,8 +10,8 @@ defineFeature(feature, test => { 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 }) @@ -21,17 +21,13 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + }, 120000); test("A non-logged user wants to see the rules for the game", ({given,when,then}) => { - let username = "pepe" - let user = username + "@pepe.com" - let password = "pepe" - let gameURL = "http://localhost:3000/dashboard/game"; given('A non-logged user in main menu', async () => { - await new Promise(resolve => setTimeout(resolve, 6000)); + await new Promise(resolve => setTimeout(resolve, 5000)); let header = await page.$eval("button[data-testid='Login']", (element) => { return element.innerHTML }) @@ -49,7 +45,7 @@ defineFeature(feature, test => { }); then('The user is redirected to the log in screen', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); + 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 980a9e67..2b941522 100644 --- a/webapp/e2e/steps/seeing_rules_positive.steps.js +++ b/webapp/e2e/steps/seeing_rules_positive.steps.js @@ -7,11 +7,14 @@ let browser; defineFeature(feature, test => { + let username = "t.rules.pos" + let user = username + "@email.com"; + let password = username + "psw"; 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 }) @@ -21,13 +24,15 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); - test("A logged user wants to see the rules for the game", ({given,when,and,then}) => { - let username = "pepe" - let user = username + "@pepe.com" - let password = "pepe" + // 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}) => { let gameURL = "http://localhost:3000/dashboard/game"; given('A logged user in the main menu', async () => { @@ -42,7 +47,7 @@ defineFeature(feature, test => { await expect(page).toClick("button[data-testid='Login'"); // Checking user is in main screen - await new Promise(resolve => setTimeout(resolve, 6000)); + 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 }) @@ -53,18 +58,19 @@ defineFeature(feature, test => { }); when('The user presses the button for deploying the lateral menu', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load await expect(page).toClick("#lateralMenuButton"); }); and('The user presses the button for seeing the rules', async() => { - await expect(page).toClick("button[data-testid='rules']"); + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load + await expect(page).toClick("button[data-testid='rules']"); }); then("The screen shows redirects the user to the rules' screen", async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); + 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 }) @@ -78,4 +84,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 2c5bb0bd..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 @@ -7,11 +7,10 @@ let browser; defineFeature(feature, test => { - 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 }) @@ -21,17 +20,13 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); + }, 120000); test("A non-logged user wants to see its stats", ({given,when,then}) => { - let username = "pepe" - let user = username + "@pepe.com" - let password = "pepe" - let gameURL = "http://localhost:3000/dashboard/game"; given('A non-logged user in main menu', async () => { - await new Promise(resolve => setTimeout(resolve, 6000)); // 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 }) @@ -49,7 +44,7 @@ defineFeature(feature, test => { }); then('The user is redirected to the log in screen', async() => { - await new Promise(resolve => setTimeout(resolve, 6000)); + 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 9168be4f..5d1eac41 100644 --- a/webapp/e2e/steps/seeing_stats_positive.steps.js +++ b/webapp/e2e/steps/seeing_stats_positive.steps.js @@ -7,11 +7,15 @@ let browser; defineFeature(feature, test => { + let username = "t.stats.pos" + let user = username + "@email.com"; + let password = username +"psw"; + 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 }) @@ -21,13 +25,15 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); - test("A logged user with many games wants to see its stats", ({given,when,and,then}) => { - let username = "pepe" - let user = username + "@pepe.com" - let password = "pepe" + // 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}) => { let gameURL = "http://localhost:3000/dashboard/game"; given('A logged user in the main menu with many games', async () => { @@ -59,7 +65,8 @@ defineFeature(feature, test => { }); and('The user presses the button for seeing stats', async() => { - await expect(page).toClick("button[data-testid='statistics']"); + await new Promise(resolve => setTimeout(resolve, 5000)); // Waiting for page to fully load + await expect(page).toClick("button[data-testid='statistics']"); }); @@ -78,4 +85,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 diff --git a/webapp/src/pages/Signup.jsx b/webapp/src/pages/Signup.jsx index f9d865fd..b73b1dd0 100644 --- a/webapp/src/pages/Signup.jsx +++ b/webapp/src/pages/Signup.jsx @@ -165,6 +165,7 @@ export default function Signup() {