Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bendecidos tests e2e #88

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ jobs:
- run: npm --prefix questionservice install
- run: npm --prefix gatewayservice install
- run: npm --prefix webapp install

- run: npm --prefix gatewayservice start
- run: npm --prefix questionservice start
- run: npm --prefix users/authservice start
- run: npm --prefix users/historyservice start
- run: npm --prefix users/userservice start

- run: npm --prefix webapp run build
- run: npm --prefix webapp run test:e2e
docker-push-webapp:
Expand Down
2 changes: 1 addition & 1 deletion users/historyservice/history-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const port = 8004;
app.use(bodyParser.json());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb';
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/historydb';
mongoose.connect(mongoUri);


Expand Down
2 changes: 1 addition & 1 deletion users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const port = 8001;
app.use(bodyParser.json());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/historydb';
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb';
mongoose.connect(mongoUri);


Expand Down
54 changes: 27 additions & 27 deletions webapp/e2e/steps/history.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ defineFeature(feature, test => {

beforeAll(async () => {

browser = await puppeteer.launch({ headless: "new", slowMo: 50,defaultViewport: {
width: 1024, height: 768,}, });
browser = await puppeteer.launch({ headless: "new", slowMo: 40,defaultViewport: {
width: 1024, height: 768,},});
page = await browser.newPage();
setDefaultOptions({ timeout: 200000 });

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

given('A not loged user', async () => {
// username = "yago";
// password = "Yagooooo1";
username = "Avestrus1";
password = "Avestrus1";
});

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

then('Redirected to login', async () => {
// await expect(page).toMatchElement('button[name="entrarPage"]');
await expect(page).toMatchElement('button[name="entrarPage"]');
});
},300000);

test('The user register in the site so he can see history', ({given,when,then}) => {

given('A unregistered user, fill the register', async () => {
// 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.waitForNavigation({
// waitUntil: 'networkidle0'
// });
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.waitForNavigation({
waitUntil: 'networkidle0'
});
});

when('I press history', async () => {
// await page.waitForSelector('[data-testid="historial-button-navbar"]', {
// visible: true,
// });
// await page.click('[data-testid="historial-button-navbar"]');
await page.waitForSelector('[data-testid="historial-button-navbar"]', {
visible: true,
});
await page.click('[data-testid="historial-button-navbar"]');
});

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

Expand Down
62 changes: 26 additions & 36 deletions webapp/e2e/steps/jugar-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,54 @@ defineFeature(feature, (test) => {
let password = "";

beforeAll(async () => {
browser = await puppeteer.launch({
headless: "new",
slowMo: 50,
defaultViewport: {
width: 1024,
height: 768,
},
});
browser = await puppeteer.launch({ headless: "new", slowMo: 40,defaultViewport: {
width: 1024, height: 768,},});
page = await browser.newPage();
setDefaultOptions({ timeout: 200000 });
}, 300000);

test('User Initiates a Game', ({ given, when,and, then }) => {
given('An unregistered user exists', async () => {
// username = "Zohaib";
// password = "Zohaib11";
username = "Nasheeee1";
password = "Nasheeee1";
});

when('the user enters their details on the register form and submits', async () => {
// await page.goto("http://localhost:3000/sign-up", {
// waitUntil: "networkidle0",
// });
// 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.waitForNavigation({
// waitUntil: 'networkidle0'
// });
await page.goto("http://localhost:3000/sign-up", {
waitUntil: "networkidle0",
});
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.waitForNavigation({
waitUntil: 'networkidle0'
});
});

and('the user is redirected to the homepage and logged in automatically', async () => {
// // Utiliza data-testid para verificar la presencia de botones o enlaces
// const isLogoutLinkVisibleMobile = await page.$eval('[data-testid="Salir-button-navbar"]', el => el.textContent.includes('Salir'));
// const isLogoutButtonVisibleDesktop = await page.$('[data-testid="Salir-button-navbar-large"]') !== null;
// Utiliza data-testid para verificar la presencia de botones o enlaces
const isLogoutButtonVisibleDesktop = await page.$('[data-testid="Salir-button-navbar-large"]') !== null;

// // Afirmar que el enlace o botón "Salir" debe ser visible en al menos una de las versiones
// expect(isLogoutLinkVisibleMobile || isLogoutButtonVisibleDesktop).toBeTruthy();
// Afirmar que el enlace o botón "Salir" debe ser visible en al menos una de las versiones
expect(isLogoutButtonVisibleDesktop).toBeTruthy();
});

and('the user clicks the "Play" button on the homepage', async () => {
// await expect(page).toClick('[data-testid="jugar-button-home"]');
// await page.waitForNavigation({
// waitUntil: 'networkidle0'
// });
await expect(page).toClick('[data-testid="jugar-button-home"]');
});

then('the questions should be displayed', async () => {

// const questionText = await page.$eval('.quiz-header h2', el => el.textContent);
// expect(questionText).toBeTruthy();
const questionText = await page.$eval('.quiz-header h2', el => el.textContent);
expect(questionText).toBeTruthy();

// // // Opcionalmente, puedes verificar el número de la pregunta actual vs. el total
// const questionIndicatorText = await page.$eval('.quiz-header div', el => el.textContent);
// expect(questionIndicatorText).toMatch(/Pregunta \d+ de \d+/);
// // Opcionalmente, puedes verificar el número de la pregunta actual vs. el total
const questionIndicatorText = await page.$eval('.quiz-header div', el => el.textContent);
expect(questionIndicatorText).toMatch(/Pregunta \d+ de \d+/);

// // // Verificar que las opciones de respuesta se muestran
// const answersCount = await page.$$eval('.answers-list li', answers => answers.length);
// expect(answersCount).toBe(4);
// // Verificar que las opciones de respuesta se muestran
const answersCount = await page.$$eval('.answers-list li', answers => answers.length);
expect(answersCount).toBe(4);

});

Expand Down
29 changes: 14 additions & 15 deletions webapp/e2e/steps/register-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ let browser;
defineFeature(feature, test => {

beforeAll(async () => {
browser = await puppeteer.launch({ headless: "new", slowMo: 50,defaultViewport: {
width: 1024, height: 768,}, });
browser = await puppeteer.launch({ headless: "new", slowMo: 40,defaultViewport: {
width: 1024, height: 768,},});
page = await browser.newPage();
setDefaultOptions({ timeout: 200000 });

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

given('An unregistered user', async () => {
// username = "santiago"
// password = "Santiago1"
// await expect(page).toClick("a", { text: "¿No tienes una cuenta? Registrate aquí." });
username = "Vuamosss1"
password = "Vuamosss1"
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[name="registrarsePage"]');
// await page.waitForNavigation({
// waitUntil: 'networkidle0'
// });
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.waitForNavigation({
waitUntil: 'networkidle0'
});
});

then('The user is registered and logged', async () => {
// Utiliza data-testid para verificar la presencia de botones o enlaces
// const isLogoutLinkVisibleMobile = await page.$eval('[data-testid="Salir-button-navbar"]', el => el.textContent.includes('Salir'));
// const isLogoutButtonVisibleDesktop = await page.$('[data-testid="Salir-button-navbar-large"]') !== null;
const isLogoutButtonVisibleDesktop = await page.$('[data-testid="Salir-button-navbar-large"]') !== null;

// // Afirmar que el enlace o botón "Salir" debe ser visible en al menos una de las versiones
// expect(isLogoutLinkVisibleMobile || isLogoutButtonVisibleDesktop).toBeTruthy();
// Afirmar que el enlace o botón "Salir" debe ser visible en al menos una de las versiones
expect(isLogoutButtonVisibleDesktop).toBeTruthy();
});
},300000);

Expand Down