From 1650f67a9461d5df3b6639e9d26856bcabbd91ab Mon Sep 17 00:00:00 2001 From: iyanfdezz Date: Wed, 24 Apr 2024 19:36:57 +0200 Subject: [PATCH] Ya va el e2e de classic --- webapp/e2e/features/ranking-sorting.feature | 6 -- webapp/e2e/features/ranking.feature | 6 -- webapp/e2e/features/stats.feature | 6 -- webapp/e2e/features/users-addfriend.feature | 6 -- webapp/e2e/steps/creategroup.steps.js | 71 --------------------- webapp/e2e/steps/logout.steps.js | 1 + webapp/e2e/steps/play-calculator.steps.js | 16 +++-- webapp/e2e/steps/play-classic.steps.js | 15 +++-- 8 files changed, 24 insertions(+), 103 deletions(-) delete mode 100644 webapp/e2e/features/ranking-sorting.feature delete mode 100644 webapp/e2e/features/ranking.feature delete mode 100644 webapp/e2e/features/stats.feature delete mode 100644 webapp/e2e/features/users-addfriend.feature delete mode 100644 webapp/e2e/steps/creategroup.steps.js diff --git a/webapp/e2e/features/ranking-sorting.feature b/webapp/e2e/features/ranking-sorting.feature deleted file mode 100644 index 312c77a1..00000000 --- a/webapp/e2e/features/ranking-sorting.feature +++ /dev/null @@ -1,6 +0,0 @@ -Feature: Seeing ranking and changing sorting filter - -Scenario: The user can see the Ranking page and change sorting filter - Given A logged-in user - When I click on the Ranking link and in Sort by Total Points - Then The ranking (sorted by Total Points) should be shown on screen \ No newline at end of file diff --git a/webapp/e2e/features/ranking.feature b/webapp/e2e/features/ranking.feature deleted file mode 100644 index 497c9bfc..00000000 --- a/webapp/e2e/features/ranking.feature +++ /dev/null @@ -1,6 +0,0 @@ -Feature: Seeing ranking and changing gamemode - -Scenario: The user can see the Ranking page and change gamemode - Given A logged-in user - When I click on the Ranking link and in Battery gamemode - Then The ranking of the Battery gamemode should be shown on screen \ No newline at end of file diff --git a/webapp/e2e/features/stats.feature b/webapp/e2e/features/stats.feature deleted file mode 100644 index 275b00f5..00000000 --- a/webapp/e2e/features/stats.feature +++ /dev/null @@ -1,6 +0,0 @@ -Feature: Seeing logged user's stats and changing gamemode - -Scenario: The user can see his Stats page and change gamemode - Given A logged-in user - When I click on the Stats link and in Calculator gamemode - Then The user's stats in Calculator gamemode shoud be shown on screen \ No newline at end of file diff --git a/webapp/e2e/features/users-addfriend.feature b/webapp/e2e/features/users-addfriend.feature deleted file mode 100644 index e5524cea..00000000 --- a/webapp/e2e/features/users-addfriend.feature +++ /dev/null @@ -1,6 +0,0 @@ -Feature: Adding a new friend - -Scenario: The user can add a friend - Given A logged-in user - When I click on the Users link and add a friend - Then The user should disappear from the Users page \ No newline at end of file diff --git a/webapp/e2e/steps/creategroup.steps.js b/webapp/e2e/steps/creategroup.steps.js deleted file mode 100644 index 31f57bca..00000000 --- a/webapp/e2e/steps/creategroup.steps.js +++ /dev/null @@ -1,71 +0,0 @@ -const puppeteer = require("puppeteer"); -const { defineFeature, loadFeature } = require("jest-cucumber"); -const setDefaultOptions = require("expect-puppeteer").setDefaultOptions; -const { expect } = require("expect-puppeteer"); -const feature = loadFeature("./features/creategroup.feature"); - -let page; -let browser; - -defineFeature(feature, (test) => { - beforeAll(async () => { - browser = process.env.GITHUB_ACTIONS - ? await puppeteer.launch() - : await puppeteer.launch({ headless: false, slowMo: 100 }); - page = await browser.newPage(); - //Way of setting up the timeout - setDefaultOptions({ timeout: 10000 }); - - await page - .goto("http://localhost:3000", { - waitUntil: "networkidle0", - }) - .catch(() => {}); - }); - - test("The user can create a group", ({ given, when, then }) => { - let username; - let password; - - 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 click on the Groups link and create a group", async () => { - await page.click('button[aria-label="Abrir menú"]'); - await page.click('[data-testid="home-grupos-link"]'); - await page.waitForNavigation({ waitUntil: "networkidle0" }); - - await page.waitForSelector('[name="name"]'); - await page.type('[name="name"]', "Test Group"); - await page.click("button", { text: "Crear" }); - await page.waitForTimeout(1000); - }); - - then("The Group should be shown on the My Groups page", async () => { - - await page.click('button[aria-label="Abrir menú"]'); - await page.click('[data-testid="home-misgrupos-link"]'); - await page.waitForNavigation({ waitUntil: "networkidle0" }); - - const groupExists = await page.evaluate(() => { - const groupName = "Test Group"; - const groups = Array.from(document.querySelectorAll("tbody tr td:first-child")); - return groups.some(td => td.textContent === groupName); - }); - - expect(groupExists).toBe(true); - }); - }); - - afterAll(async () => { - browser.close(); - }); -}); diff --git a/webapp/e2e/steps/logout.steps.js b/webapp/e2e/steps/logout.steps.js index 162ce898..23521cda 100644 --- a/webapp/e2e/steps/logout.steps.js +++ b/webapp/e2e/steps/logout.steps.js @@ -39,6 +39,7 @@ defineFeature(feature, (test) => { }); when("I click on the Logout link", async () => { + await page.waitForTimeout(1000); await page.waitForSelector('[data-testid="logout-link"]'); await page.click('[data-testid="logout-link"]'); await page.waitForNavigation({ waitUntil: "networkidle0" }); diff --git a/webapp/e2e/steps/play-calculator.steps.js b/webapp/e2e/steps/play-calculator.steps.js index 84b872f6..67c4017e 100644 --- a/webapp/e2e/steps/play-calculator.steps.js +++ b/webapp/e2e/steps/play-calculator.steps.js @@ -31,13 +31,20 @@ defineFeature(feature, (test) => { await page.waitForSelector("#login-password"); await page.type("#login-password", password); await page.click("button", { text: "Login" }); - await page.waitForNavigation({ waitUntil: "networkidle0" }); + + //await page.waitForNavigation({ waitUntil: "networkidle0" }); }); when("I play on Human Calculator mode and answer incorrectly", async () => { - await page.click('[data-testid="calculator"]'); - await page.waitForNavigation({ waitUntil: "networkidle0" }); + await page.waitForTimeout(1000); + await page.waitForXPath('//button[contains(text(), "Calculadora humana")]'); + const button = await page.$x('//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")]'); + const jugarButton = await page.$x('//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]'); + await jugarButton[0].click(); await page.waitForSelector('[data-testid="operation"]'); const operation = await page.evaluate(() => { @@ -55,7 +62,8 @@ defineFeature(feature, (test) => { await page.waitForSelector('[data-testid="game-over"]'); const gameOverMessage = await page.evaluate(() => { - return document.querySelector('[data-testid="game-over"]').textContent; + return document.querySelector('h2:contains("¡Juego terminado!")'); + }); expect(gameOverMessage).toContain("¡Juego terminado!"); diff --git a/webapp/e2e/steps/play-classic.steps.js b/webapp/e2e/steps/play-classic.steps.js index f46c0d19..7439b175 100644 --- a/webapp/e2e/steps/play-classic.steps.js +++ b/webapp/e2e/steps/play-classic.steps.js @@ -31,12 +31,19 @@ defineFeature(feature, (test) => { await page.waitForSelector("#login-password"); await page.type("#login-password", password); await page.click("button", { text: "Login" }); - await page.waitForNavigation({ waitUntil: "networkidle0" }); + //await page.waitForNavigation({ waitUntil: "networkidle0" }); }); when("I play on Classic mode and click on an answer", async () => { - await page.click('[data-testid="classic"]'); - await page.waitForNavigation({ waitUntil: "networkidle0" }); + await page.waitForTimeout(1000); + await page.waitForXPath('//button[contains(text(), "Clásico")]'); + const classicButton = await page.$x('//button[contains(text(), "Clásico")]'); + await classicButton[0].click(); + //await page.waitForNavigation({ waitUntil: "networkidle0" }); + + await page.waitForXPath('//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]'); + const jugarButton = await page.$x('//section[contains(@class, "chakra-modal__content")]//button[contains(text(), "Jugar")]'); + await jugarButton[0].click(); await page.waitForSelector('[data-testid="question"]'); @@ -53,7 +60,7 @@ defineFeature(feature, (test) => { const buttonColor = await button.evaluate((el) => { return window.getComputedStyle(el).getPropertyValue("background-color"); }); - if (buttonColor === "rgb(16, 255, 0)") { + if (buttonColor.includes("rgb(44, 122, 123)")) { isGreen = true; break; }