From f96d642d837794d12563e4d253c9f68161428110 Mon Sep 17 00:00:00 2001 From: CANCI0 Date: Tue, 2 Apr 2024 19:41:13 +0200 Subject: [PATCH] =?UTF-8?q?Arreglados=20los=20tests=20de=20integraci=C3=B3?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/e2e/steps/register-form.steps.js | 57 ++++++++++++---------- webapp/src/components/Register/Register.js | 2 + 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index c10cba1f..c386d99a 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -1,20 +1,20 @@ -const puppeteer = require('puppeteer'); -const { defineFeature, loadFeature }=require('jest-cucumber'); -const setDefaultOptions = require('expect-puppeteer').setDefaultOptions -const feature = loadFeature('./features/register-form.feature'); +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/register-form.feature"); let page; let browser; -defineFeature(feature, test => { - +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 }) + setDefaultOptions({ timeout: 10000 }); await page .goto("http://localhost:3000", { @@ -23,30 +23,37 @@ defineFeature(feature, test => { .catch(() => {}); }); - test('The user is not registered in the site', ({given,when,then}) => { - + test("The user is not registered in the site", ({ given, when, then }) => { let username; let password; - given('An unregistered user', async () => { - username = "pablo" - password = "pabloasw" - await expect(page).toClick("button", { text: "¿No tienes cuenta? Regístrate." }); + given("An unregistered user", async () => { + username = "pablo"; + password = "pabloasw"; + await expect(page).toClick("a", { text: "Regístrate" }); }); - when('I fill the data in the form and press submit', async () => { - await expect(page).toFill('input[name="username"]', username); - await expect(page).toFill('input[name="password"]', password); - await expect(page).toClick('button', { text: 'Add User' }) + when("I fill the data in the form and press submit", async () => { + username = "testuser"; + password = "testpassword"; + await page.waitForSelector('#register-username'); + await page.type('#register-username', username); + await page.waitForSelector('#register-password'); + await page.type('#register-password', password); + await page.waitForSelector('#register-pass2'); + await page.type('#register-pass2', password); + await page.click("button", { text: "Registrarse" }); }); - then('A confirmation message should be shown in the screen', async () => { - await expect(page).toMatchElement("div", { text: "User added successfully" }); + then("A confirmation message should be shown in the screen", async () => { + //await page.waitForNavigation({ waitUntil: "networkidle0" }); + const url = page.url(); + expect(url).toContain("/home"); + browser.close(); }); - }) - - afterAll(async ()=>{ - browser.close() - }) + }); -}); \ No newline at end of file + afterAll(async () => { + browser.close(); + }); +}); diff --git a/webapp/src/components/Register/Register.js b/webapp/src/components/Register/Register.js index a0f893d4..27b327d8 100644 --- a/webapp/src/components/Register/Register.js +++ b/webapp/src/components/Register/Register.js @@ -80,6 +80,7 @@ const AddUser = () => { {