Skip to content

Commit

Permalink
Arreglo de tests e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
Verzidee committed Apr 7, 2024
1 parent f27f58a commit 65ab122
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 35 deletions.
File renamed without changes.
35 changes: 20 additions & 15 deletions webapp/e2e/steps/history.steps.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/register-form.feature');
const feature = loadFeature('./features/history-form.feature');

let page;
let browser;

defineFeature(feature, test => {

let username = "usuario"
let username = "usuario12"
let password = "contraseña"

beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 100 });
: await puppeteer.launch({ headless: false, slowMo: 100,defaultViewport: {
width: 1024, // Asegurando que el ancho sea mayor a 960px
height: 768,
}, });
page = await browser.newPage();
setDefaultOptions({ timeout: 10000 });

await page.goto("http://localhost:3000/register", {
await page.goto("http://localhost:3000/sign-up", {
waitUntil: "networkidle0",
}).catch(() => {});

//Registrar al user
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Registrarse' });
await expect(page).toClick('button[name="registrarsePage"]');

await page.goto("http://localhost:3000/", {
await page.goto("http://localhost:3000/login", {
waitUntil: "networkidle0",
}).catch(() => {});

Expand All @@ -36,15 +39,17 @@ defineFeature(feature, test => {
test('The user is not loged in the site', ({given,when,then}) => {

given('A not loged user', async () => {

});

when('Press history', async () => {
await expect(page).toClick('button', { text: 'Historial' });
await page.goto("http://localhost:3000/historial", {
waitUntil: "networkidle0",
}).catch(() => {});
});

then('Redirected to login', async () => {
await expect(page).toMatchElement('div', { text: 'Entrar' });
await expect(page).toMatchElement('button',{ text: 'Entrar' });
});
})

Expand All @@ -56,19 +61,19 @@ defineFeature(feature, test => {
}).catch(() => {});
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Entrar' });
await expect(page).toClick('button[name="entrarPage"]');
});

when('I press history', async () => {
await expect(page).toClick('button', { text: 'Historial' });
await expect(page).toClick('a', { text: 'Historial' });
});

then('I see my history', async () => {
await expect(page).toMatchElement('h1', { text: 'HISTORIAL' });
await expect(page).toMatch('Número de Partidas:');
await expect(page).toMatch('Número de Preguntas Jugadas:');
await expect(page).toMatch('Número de acertadas:');
await expect(page).toMatch('Número de falladas:');
await expect(page).toMatchElement('p', { text: 'Número de Partidas:' });
await expect(page).toMatchElement('p', { text: 'Número de Preguntas Jugadas:' });
await expect(page).toMatchElement('p', { text: 'Número de acertadas:' });
await expect(page).toMatchElement('p', { text: 'Número de falladas:' });
});
})

Expand Down
24 changes: 17 additions & 7 deletions webapp/e2e/steps/jugar-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,42 @@ let page;
let browser;

defineFeature(feature, (test) => {
let username;
let password;
let username = "usuario13"
let password = "contraseña"

beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 100 });
: await puppeteer.launch({ headless: false, slowMo: 100,defaultViewport: {
width: 1024, // Asegurando que el ancho sea mayor a 960px
height: 768,
}, });
page = await browser.newPage();
setDefaultOptions({ timeout: 10000 });

await page.goto("http://localhost:3000/login", {
await page.goto("http://localhost:3000/sign-up", {
waitUntil: "networkidle0",
}).catch(() => {});

//Registrar al user

await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button[name="registrarsePage"]');

await page.waitForTimeout(1500);
}, 60000);

test('User Initiates a Game', ({ given, when, then }) => {

given('a registered user exists', async () => {
username = "zohaib"
password = "zohaib"
await expect(page).toClick('button',{text: "Entrar"});
});

when('the user enters their details on the login form and submits', async () => {
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Entrar' })
await expect(page).toClick('button[name="entrarPage"]');
});

when('the user clicks the "Play" button on the homepage', async () => {
Expand Down
19 changes: 12 additions & 7 deletions webapp/e2e/steps/login-form.steps.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/register-form.feature');
const feature = loadFeature('./features/login-form.feature');

let page;
let browser;

defineFeature(feature, test => {

let username = "usuario"
let username = "usuario11"
let password = "contraseña"

beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 100 });
: await puppeteer.launch({ headless: false, slowMo: 100,defaultViewport: {
width: 1024, // Asegurando que el ancho sea mayor a 960px
height: 768,
}, });
page = await browser.newPage();
setDefaultOptions({ timeout: 10000 });

await page.goto("http://localhost:3000/register", {
await page.goto("http://localhost:3000/sign-up", {
waitUntil: "networkidle0",
}).catch(() => {});

//Registrar al user

await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Registrarse' })
await expect(page).toClick('button[name="registrarsePage"]');

await page.waitForTimeout(1500);

}, 60000);

Expand All @@ -38,12 +43,12 @@ defineFeature(feature, test => {
});

when('Presses submit', async () => {
await expect(page).toClick('button', { text: 'Entrar' });
await expect(page).toClick('button[name="entrarPage"]');
});


then('The user is redirected', async () => {
await expect(page).toMatchElement("div", { text: "Inicio de sesión exitoso" });
await expect(page).toMatchElement("p", { text: "¿A que estás esperando?" });
});
})

Expand Down
9 changes: 6 additions & 3 deletions webapp/e2e/steps/register-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ defineFeature(feature, test => {
beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 100 });
: await puppeteer.launch({ headless: false, slowMo: 100,defaultViewport: {
width: 1024, // Asegurando que el ancho sea mayor a 960px
height: 768,
}, });
page = await browser.newPage();
setDefaultOptions({ timeout: 10000 });

Expand All @@ -26,15 +29,15 @@ defineFeature(feature, test => {
let password;

given('An unregistered user', async () => {
username = "ProbandoV1"
username = "ProbandoV12"
password = "pabloasw"
await expect(page).toClick("a", { text: "¿No tienes una cuenta? Registrate aquí." });
});

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: 'Registrarse' })
await expect(page).toClick('button[name="registrarsePage"]');
});

then('A confirmation message should be shown in the screen', async () => {
Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/test-environment-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function startServer() {
authservice = await require("../../users/authservice/auth-service");
historyservice = await require("../../users/historyservice/history-service");
gatewayservice = await require("../../gatewayservice/gateway-service");
questionservice = await requiree("../../questionservice/question-service");
questionservice = await require("../../questionservice/question-service");
}

startServer();
2 changes: 1 addition & 1 deletion webapp/src/components/pages/AddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const AddUser = () => {
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<Button variant="contained" color="primary" onClick={addUser} sx={{ mt: 3, mb: 2 }}>
<Button name="registrarsePage" variant="contained" color="primary" onClick={addUser} sx={{ mt: 3, mb: 2 }}>
Registrarse
</Button>
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="Usuario añadido correctamente" />
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const Login = () => {
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<Button variant="contained" color="primary" onClick={loginUser} sx={{ mt: 3, mb: 2 }}>
<Button name="entrarPage" variant="contained" color="primary" onClick={loginUser} sx={{ mt: 3, mb: 2 }}>
Entrar
</Button>
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message={loginSuccess ? "Inicio de sesión exitoso" : `Error: ${error}`} />
Expand Down

0 comments on commit 65ab122

Please sign in to comment.