From 5dfdc7e975a253931be7efc3b629cd771ffe70ee Mon Sep 17 00:00:00 2001 From: samshara Date: Wed, 27 Nov 2024 18:17:01 +0545 Subject: [PATCH] fix: add redirecting to field report listing page in playwright tests --- .github/workflows/playwright.yml | 2 +- packages/e2e-tests/.env.example | 2 +- packages/e2e-tests/tests/auth.setup.ts | 4 ++-- .../e2e-tests/tests/earlyWarning/earlyWarning.spec.ts | 2 ++ .../epidemic-field-report/epidemic-field-report.spec.ts | 5 ++--- .../e2e-tests/tests/field-report/fieldReport.spec.ts | 5 ++--- packages/e2e-tests/tests/loginLogout.spec.ts | 9 ++++----- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index f82711e7ef..d1805ba07a 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -2,7 +2,7 @@ name: Playwright env: PLAYWRIGHT_APP_BASE_URL: ${{ vars.PLAYWRIGHT_APP_BASE_URL }} - PLAYWRIGHT_USER_NAME: ${{ secrets.PLAYWRIGHT_USER_NAME }} + PLAYWRIGHT_USER_EMAIL: ${{ secrets.PLAYWRIGHT_USER_EMAIL }} PLAYWRIGHT_USER_PASSWORD: ${{ secrets.PLAYWRIGHT_USER_PASSWORD }} on: diff --git a/packages/e2e-tests/.env.example b/packages/e2e-tests/.env.example index 2752beba08..ccd2132df6 100644 --- a/packages/e2e-tests/.env.example +++ b/packages/e2e-tests/.env.example @@ -1,6 +1,6 @@ # Base URL for the application where Playwright will run tests PLAYWRIGHT_APP_BASE_URL= # User name of the test user for Playwright -PLAYWRIGHT_USER_NAME= +PLAYWRIGHT_USER_EMAIL= # Password of the test user for Playwright PLAYWRIGHT_USER_PASSWORD= diff --git a/packages/e2e-tests/tests/auth.setup.ts b/packages/e2e-tests/tests/auth.setup.ts index 468afed2a7..0837112bbd 100644 --- a/packages/e2e-tests/tests/auth.setup.ts +++ b/packages/e2e-tests/tests/auth.setup.ts @@ -4,12 +4,12 @@ const authFile = 'playwright/.auth/user.json'; setup('authenticate', async ({ page }) => { if ( - process.env.PLAYWRIGHT_USER_NAME && + process.env.PLAYWRIGHT_USER_EMAIL && process.env.PLAYWRIGHT_USER_PASSWORD ) { await login( page, - process.env.PLAYWRIGHT_USER_NAME, + process.env.PLAYWRIGHT_USER_EMAIL, process.env.PLAYWRIGHT_USER_PASSWORD, ); } diff --git a/packages/e2e-tests/tests/earlyWarning/earlyWarning.spec.ts b/packages/e2e-tests/tests/earlyWarning/earlyWarning.spec.ts index b7b08bb49d..04fa1af229 100644 --- a/packages/e2e-tests/tests/earlyWarning/earlyWarning.spec.ts +++ b/packages/e2e-tests/tests/earlyWarning/earlyWarning.spec.ts @@ -265,6 +265,8 @@ test.describe('Field Report', () => { .filter({ hasText: visibiltyOptTwo }) .click(); await page.getByRole('button', { name: 'Submit' }).click(); + // Wait for redirection to field reports listing page + await page.waitForURL(/\/field-reports\/\d+/); await expect(page.locator('h1')).toContainText( `${newtitle} - ${title}`, ); diff --git a/packages/e2e-tests/tests/epidemic-field-report/epidemic-field-report.spec.ts b/packages/e2e-tests/tests/epidemic-field-report/epidemic-field-report.spec.ts index 6289e0f235..96458a7842 100644 --- a/packages/e2e-tests/tests/epidemic-field-report/epidemic-field-report.spec.ts +++ b/packages/e2e-tests/tests/epidemic-field-report/epidemic-field-report.spec.ts @@ -252,9 +252,8 @@ test.describe('Field report flow', async () => { .filter({ hasText: visibiltyOptTwo }) .click(); await page.getByRole('button', { name: 'Submit' }).click(); - await expect(page.locator('body')).toContainText( - 'Field report updated, redirecting...', - ); + // Wait for redirection to field reports listing page + await page.waitForURL(/\/field-reports\/\d+/); // Title Assertion await expect(page.locator('h1')).toContainText( `${newtitle} - ${title}`, diff --git a/packages/e2e-tests/tests/field-report/fieldReport.spec.ts b/packages/e2e-tests/tests/field-report/fieldReport.spec.ts index ed194bf2e8..61f790ef2f 100644 --- a/packages/e2e-tests/tests/field-report/fieldReport.spec.ts +++ b/packages/e2e-tests/tests/field-report/fieldReport.spec.ts @@ -266,9 +266,8 @@ test.describe('Field Report', () => { .filter({ hasText: visibiltyOptTwo }) .click(); await page.getByRole('button', { name: 'Submit' }).click(); - await expect(page.locator('body')).toContainText( - 'Field report updated, redirecting...', - ); + // Wait for redirection to field reports listing page + await page.waitForURL(/\/field-reports\/\d+/); // Title Assertion await expect(page.locator('h1')).toContainText( `${newtitle} - ${title}`, diff --git a/packages/e2e-tests/tests/loginLogout.spec.ts b/packages/e2e-tests/tests/loginLogout.spec.ts index 0d300c5ecc..88c7272f5a 100644 --- a/packages/e2e-tests/tests/loginLogout.spec.ts +++ b/packages/e2e-tests/tests/loginLogout.spec.ts @@ -3,7 +3,7 @@ import { login } from '#utils/auth'; test('should login', async ({ page }) => { await login( page, - process.env.PLAYWRIGHT_USER_NAME, + process.env.PLAYWRIGHT_USER_EMAIL, process.env.PLAYWRIGHT_USER_PASSWORD, ); await page.waitForURL('/'); @@ -15,13 +15,12 @@ test('should login', async ({ page }) => { test('should logout', async ({ page }) => { await login( page, - process.env.PLAYWRIGHT_USER_NAME, + process.env.PLAYWRIGHT_USER_EMAIL, process.env.PLAYWRIGHT_USER_PASSWORD, ); await page.waitForURL('/'); - await page - .getByRole('button', { name: process.env.PLAYWRIGHT_USER_NAME }) - .click(); + const name = process.env.PLAYWRIGHT_USER_EMAIL.match(/^[^@]+(?=@)/); + await page.getByRole('button', { name: name[0] }).click(); await page.getByRole('button', { name: 'Logout' }).click(); await page.getByRole('button', { name: 'Ok' }).click(); await expect(page.getByRole('navigation')).toContainText('Login');