From ab11678148d5edd1cc71d2481e1e80366fcf9234 Mon Sep 17 00:00:00 2001 From: Zohaib Akhtar Kausar Date: Thu, 25 Apr 2024 00:32:15 +0200 Subject: [PATCH 1/2] Estos tests funcionan en local --- webapp/e2e/steps/history.steps.js | 9 ++++++--- webapp/e2e/steps/jugar-form.steps.js | 18 ++++++------------ webapp/e2e/steps/register-form.steps.js | 9 ++++++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/webapp/e2e/steps/history.steps.js b/webapp/e2e/steps/history.steps.js index 8098912..02054cf 100644 --- a/webapp/e2e/steps/history.steps.js +++ b/webapp/e2e/steps/history.steps.js @@ -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: 10,defaultViewport: { + width: 1024, height: 768,},}); page = await browser.newPage(); setDefaultOptions({ timeout: 200000 }); @@ -23,7 +23,7 @@ defineFeature(feature, test => { test('The user is not loged in the site', ({given,when,then}) => { given('A not loged user', async () => { - username = "yago"; + username = "yago121221"; password = "Yagooooo1"; }); @@ -48,6 +48,9 @@ defineFeature(feature, test => { 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 () => { diff --git a/webapp/e2e/steps/jugar-form.steps.js b/webapp/e2e/steps/jugar-form.steps.js index 57ba311..46039a8 100644 --- a/webapp/e2e/steps/jugar-form.steps.js +++ b/webapp/e2e/steps/jugar-form.steps.js @@ -11,21 +11,15 @@ 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: 10,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"; + username = "Zohaib1222121"; password = "Zohaib11"; }); @@ -36,6 +30,9 @@ defineFeature(feature, (test) => { 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 () => { @@ -49,9 +46,6 @@ defineFeature(feature, (test) => { 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' - }); }); then('the questions should be displayed', async () => { diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index f1e293f..3dae753 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -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: 10,defaultViewport: { + width: 1024, height: 768,},}); page = await browser.newPage(); setDefaultOptions({ timeout: 200000 }); @@ -25,7 +25,7 @@ defineFeature(feature, test => { let password; given('An unregistered user', async () => { - username = "santiago" + username = "santiago1212221" password = "Santiago1" await expect(page).toClick("a", { text: "¿No tienes una cuenta? Registrate aquí." }); }); @@ -34,6 +34,9 @@ defineFeature(feature, test => { 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 () => { From f9862ab96b5111d028dc50ab0d04b79dca218971 Mon Sep 17 00:00:00 2001 From: Zohaib Akhtar Kausar Date: Thu, 25 Apr 2024 15:38:09 +0200 Subject: [PATCH 2/2] Si dios quiere esto funcionara (tests e2e) --- .github/workflows/release.yml | 7 +++++++ users/historyservice/history-service.js | 2 +- users/userservice/user-service.js | 2 +- webapp/e2e/steps/history.steps.js | 6 +++--- webapp/e2e/steps/jugar-form.steps.js | 9 ++++----- webapp/e2e/steps/register-form.steps.js | 9 ++++----- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0dd803c..152cd2b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: diff --git a/users/historyservice/history-service.js b/users/historyservice/history-service.js index edd3360..74528f3 100644 --- a/users/historyservice/history-service.js +++ b/users/historyservice/history-service.js @@ -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); diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index 1b83340..ad0a6ca 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -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); diff --git a/webapp/e2e/steps/history.steps.js b/webapp/e2e/steps/history.steps.js index 02054cf..b9eeb01 100644 --- a/webapp/e2e/steps/history.steps.js +++ b/webapp/e2e/steps/history.steps.js @@ -13,7 +13,7 @@ defineFeature(feature, test => { beforeAll(async () => { - browser = await puppeteer.launch({ headless: "new", slowMo: 10,defaultViewport: { + browser = await puppeteer.launch({ headless: "new", slowMo: 40,defaultViewport: { width: 1024, height: 768,},}); page = await browser.newPage(); setDefaultOptions({ timeout: 200000 }); @@ -23,8 +23,8 @@ defineFeature(feature, test => { test('The user is not loged in the site', ({given,when,then}) => { given('A not loged user', async () => { - username = "yago121221"; - password = "Yagooooo1"; + username = "Avestrus1"; + password = "Avestrus1"; }); when('Press history', async () => { diff --git a/webapp/e2e/steps/jugar-form.steps.js b/webapp/e2e/steps/jugar-form.steps.js index 46039a8..31110e4 100644 --- a/webapp/e2e/steps/jugar-form.steps.js +++ b/webapp/e2e/steps/jugar-form.steps.js @@ -11,7 +11,7 @@ defineFeature(feature, (test) => { let password = ""; beforeAll(async () => { - browser = await puppeteer.launch({ headless: "new", slowMo: 10,defaultViewport: { + browser = await puppeteer.launch({ headless: "new", slowMo: 40,defaultViewport: { width: 1024, height: 768,},}); page = await browser.newPage(); setDefaultOptions({ timeout: 200000 }); @@ -19,8 +19,8 @@ defineFeature(feature, (test) => { test('User Initiates a Game', ({ given, when,and, then }) => { given('An unregistered user exists', async () => { - username = "Zohaib1222121"; - password = "Zohaib11"; + username = "Nasheeee1"; + password = "Nasheeee1"; }); when('the user enters their details on the register form and submits', async () => { @@ -37,11 +37,10 @@ defineFeature(feature, (test) => { 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; // Afirmar que el enlace o botón "Salir" debe ser visible en al menos una de las versiones - expect(isLogoutLinkVisibleMobile || isLogoutButtonVisibleDesktop).toBeTruthy(); + expect(isLogoutButtonVisibleDesktop).toBeTruthy(); }); and('the user clicks the "Play" button on the homepage', async () => { diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index 3dae753..9b6636a 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -9,7 +9,7 @@ let browser; defineFeature(feature, test => { beforeAll(async () => { - browser = await puppeteer.launch({ headless: "new", slowMo: 10,defaultViewport: { + browser = await puppeteer.launch({ headless: "new", slowMo: 40,defaultViewport: { width: 1024, height: 768,},}); page = await browser.newPage(); setDefaultOptions({ timeout: 200000 }); @@ -25,8 +25,8 @@ defineFeature(feature, test => { let password; given('An unregistered user', async () => { - username = "santiago1212221" - password = "Santiago1" + username = "Vuamosss1" + password = "Vuamosss1" await expect(page).toClick("a", { text: "¿No tienes una cuenta? Registrate aquí." }); }); @@ -41,11 +41,10 @@ defineFeature(feature, test => { 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; // Afirmar que el enlace o botón "Salir" debe ser visible en al menos una de las versiones - expect(isLogoutLinkVisibleMobile || isLogoutButtonVisibleDesktop).toBeTruthy(); + expect(isLogoutButtonVisibleDesktop).toBeTruthy(); }); },300000);