Skip to content

Commit

Permalink
Arreglados los tests de integración
Browse files Browse the repository at this point in the history
  • Loading branch information
CANCI0 committed Apr 2, 2024
1 parent 7bb11d0 commit f96d642
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
57 changes: 32 additions & 25 deletions webapp/e2e/steps/register-form.steps.js
Original file line number Diff line number Diff line change
@@ -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", {
Expand All @@ -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()
})
});

});
afterAll(async () => {
browser.close();
});
});
2 changes: 2 additions & 0 deletions webapp/src/components/Register/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const AddUser = () => {
</FormLabel>
<Input
id="register-username"
name="username"
type="text"
placeholder="Nombre de usuario"
value={username}
Expand All @@ -92,6 +93,7 @@ const AddUser = () => {
</FormLabel>
<Input
id="register-password"
name="password"
type="password"
placeholder="Contraseña"
value={password}
Expand Down

0 comments on commit f96d642

Please sign in to comment.