From 383141ae574ed307860159ac49ef453373b89b83 Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Fri, 26 Apr 2024 17:04:43 +0200 Subject: [PATCH] A ver si ye de esta --- webapp/e2e/steps/play-battery.steps.js | 20 ++++---- webapp/e2e/steps/play-calculator.steps.js | 56 +++++++++++++++++------ 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/webapp/e2e/steps/play-battery.steps.js b/webapp/e2e/steps/play-battery.steps.js index e1645087..40cbb338 100644 --- a/webapp/e2e/steps/play-battery.steps.js +++ b/webapp/e2e/steps/play-battery.steps.js @@ -59,17 +59,9 @@ defineFeature(feature, (test) => { let firstquestion; test("The user can answer a question on Battery mode", ({ given, when, then }) => { given("A logged-in user", async () => { - username = "testuser"; - password = "Testpassword1"; - await page.waitForSelector("#login-username"); - await page.type("#login-username", username); - await page.waitForSelector("#login-password"); - await page.type("#login-password", password); - await page.click("button", { text: "Login" }); - //await page.waitForNavigation({ waitUntil: "networkidle0" }); - }); - - when("I play on Battery mode and click on an answer", async () => { + localStorage.setItem("username","testuser"); + localStorage.setItem("token","abcdefg"); + await page.waitForTimeout(1000); await page.waitForXPath('//button[contains(text(), "BaterĂ­a de sabios")]'); const button = await page.$x('//button[contains(text(), "BaterĂ­a de sabios")]'); @@ -80,6 +72,12 @@ defineFeature(feature, (test) => { const jugarButton = await page.$x('//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]'); await jugarButton[0].click(); + //await page.waitForNavigation({ waitUntil: "networkidle0" }); + }); + + when("I play on Battery mode and click on an answer", async () => { + + await page.waitForSelector('[data-testid="question"]'); firstquestion = await page.evaluate(element => diff --git a/webapp/e2e/steps/play-calculator.steps.js b/webapp/e2e/steps/play-calculator.steps.js index e175ae33..9d0637e5 100644 --- a/webapp/e2e/steps/play-calculator.steps.js +++ b/webapp/e2e/steps/play-calculator.steps.js @@ -16,7 +16,7 @@ defineFeature(feature, (test) => { page = await browser.newPage(); setDefaultOptions({ timeout: 10000 }); - await page.goto("http://localhost:3000", { + await page.goto("http://localhost:3000/home/calculadora", { waitUntil: "networkidle0", }); @@ -31,31 +31,50 @@ defineFeature(feature, (test) => { "Access-Control-Allow-Headers": "*", }, }); + } else if (req.url().includes("/questions")) { + req.respond({ + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + }, + contentType: "application/json", + body: JSON.stringify([ + { + pregunta: "Test question", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + { + pregunta: "Test question 2", + respuestas: [ + "Test answer 1", + "Test answer 2", + "Test answer 3", + "Test correct answer", + ], + correcta: "Test correct answer", + }, + ]), + }); } else { req.continue(); } }); }); - let username; - let password; test("The user can answer a question on Human Calculator mode", ({ given, when, then, }) => { given("A logged-in user", async () => { - username = "testuser"; - password = "Testpassword1"; - await page.waitForSelector("#login-username"); - await page.type("#login-username", username); - await page.waitForSelector("#login-password"); - await page.type("#login-password", password); - await page.click("button", { text: "Login" }); - - //await page.waitForNavigation({ waitUntil: "networkidle0" }); - }); + localStorage.setItem("username","testuser"); + localStorage.setItem("token","abcdefg"); - when("I play on Human Calculator mode and answer incorrectly", async () => { await page.waitForTimeout(1000); await page.waitForXPath( '//button[contains(text(), "Calculadora humana")]' @@ -64,7 +83,6 @@ defineFeature(feature, (test) => { '//button[contains(text(), "Calculadora humana")]' ); await button[0].click(); - //await page.waitForNavigation({ waitUntil: "networkidle0" }); await page.waitForXPath( '//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]' @@ -73,6 +91,14 @@ defineFeature(feature, (test) => { '//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]' ); await jugarButton[0].click(); + //await page.waitForNavigation({ waitUntil: "networkidle0" }); + }); + + when("I play on Human Calculator mode and answer incorrectly", async () => { + + //await page.waitForNavigation({ waitUntil: "networkidle0" }); + + await page.waitForSelector('[data-testid="operation"]'); const answer = -999;