From e805271da1f9577fa45858a7924d0681ce68c420 Mon Sep 17 00:00:00 2001 From: kdaud Date: Wed, 6 Nov 2024 06:09:10 +0300 Subject: [PATCH] Fix tests for erpnext-openmrs flows --- e2e/tests/keycloak-odoo-flows.spec.ts | 2 +- e2e/tests/keycloak-openmrs-flows.spec.ts | 42 ++++++++--------- e2e/tests/keycloak-superset-flows.spec.ts | 56 +++++++++++------------ package.json | 2 +- playwright.config.ts | 4 +- 5 files changed, 54 insertions(+), 52 deletions(-) diff --git a/e2e/tests/keycloak-odoo-flows.spec.ts b/e2e/tests/keycloak-odoo-flows.spec.ts index 9cec60a..3383afe 100644 --- a/e2e/tests/keycloak-odoo-flows.spec.ts +++ b/e2e/tests/keycloak-odoo-flows.spec.ts @@ -34,7 +34,7 @@ test('Logging out from Odoo logs out the user from Keycloak.', async ({ page }) // verify await page.goto(`${KEYCLOAK_URL}/admin/master/console`); await keycloak.navigateToClients(); - await keycloak.selectOpenMRSId(); + await keycloak.selectOdooId(); await keycloak.selectSessions(); await expect(page.locator('h1.pf-c-title:nth-child(2)')).toHaveText(/no sessions/i); await expect(page.locator('.pf-c-empty-state__body')).toHaveText(/there are currently no active sessions for this client/i); diff --git a/e2e/tests/keycloak-openmrs-flows.spec.ts b/e2e/tests/keycloak-openmrs-flows.spec.ts index 1ed33fb..2763937 100644 --- a/e2e/tests/keycloak-openmrs-flows.spec.ts +++ b/e2e/tests/keycloak-openmrs-flows.spec.ts @@ -14,6 +14,27 @@ test.beforeEach(async ({ page }) => { await expect(page.locator('div:nth-child(1)>a')).toHaveText(/home/i); }); +test('Logging out from OpenMRS logs out the user from Keycloak.', async ({ page }) => { + // setup + await keycloak.open(); + await keycloak.navigateToClients(); + await keycloak.selectOpenMRSId(); + await keycloak.selectSessions(); + await expect(page.locator('td:nth-child(1) a').nth(0)).toHaveText(/jdoe/i); + + // replay + await openmrs.logout(); + + // verify + await page.goto(`${KEYCLOAK_URL}/admin/master/console`); + await keycloak.navigateToClients(); + await keycloak.selectOpenMRSId(); + await keycloak.selectSessions(); + await expect(page.locator('h1.pf-c-title:nth-child(2)')).toHaveText(/no sessions/i); + await expect(page.locator('.pf-c-empty-state__body')).toHaveText(/there are currently no active sessions for this client/i); + await page.goto(`${O3_URL}/openmrs/spa/home/`); + await expect(page).toHaveURL(/.*login/); +}); test('Creating an OpenMRS role creates the corresponding Keycloak role.', async ({ page }) => { // setup await page.goto(`${O3_URL}/openmrs/admin/users/role.list`); @@ -131,27 +152,6 @@ test('A (non-synced) role created from within Keycloak gets deleted in the subse await openmrs.logout(); }); -test('Logging out from OpenMRS logs out the user from Keycloak.', async ({ page }) => { - // setup - await keycloak.open(); - await keycloak.navigateToClients(); - await keycloak.selectOpenMRSId(); - await keycloak.selectSessions(); - await expect(page.locator('td:nth-child(1) a').nth(0)).toHaveText(/jdoe/i); - - // replay - await openmrs.logout(); - - // verify - await page.goto(`${KEYCLOAK_URL}/admin/master/console`); - await keycloak.navigateToClients(); - await keycloak.selectOpenMRSId(); - await keycloak.selectSessions(); - await expect(page.locator('h1.pf-c-title:nth-child(2)')).toHaveText(/no sessions/i); - await expect(page.locator('.pf-c-empty-state__body')).toHaveText(/there are currently no active sessions for this client/i); - await page.goto(`${O3_URL}/openmrs/spa/home/`); - await expect(page).toHaveURL(/.*login/); -}); test.afterEach(async ({ page }) => { await page.close(); diff --git a/e2e/tests/keycloak-superset-flows.spec.ts b/e2e/tests/keycloak-superset-flows.spec.ts index 630343c..7b16da8 100644 --- a/e2e/tests/keycloak-superset-flows.spec.ts +++ b/e2e/tests/keycloak-superset-flows.spec.ts @@ -14,6 +14,34 @@ test.beforeEach(async ({ page }) => { superset = new Superset(page); }); +test('Logging out from Superset logs out the user from Keycloak.', async ({ page }) => { + // setup + await superset.open(); + await openmrs.enterLoginCredentials(); + await expect(page).toHaveURL(/.*superset/); + await expect(page.locator('#app div.header')).toHaveText(/home/i); + await keycloak.open(); + await keycloak.navigateToClients(); + await keycloak.selectSupersetId(); + await keycloak.selectSessions(); + await expect(page.locator('td:nth-child(1) a').nth(0)).toHaveText(/jdoe/i); + + // replay + await superset.logout(); + await keycloak.confirmLogout(); + await expect(page).toHaveURL(/.*login/); + + // verify + await page.goto(`${KEYCLOAK_URL}/admin/master/console`); + await keycloak.navigateToClients(); + await keycloak.selectSupersetId(); + await keycloak.selectSessions(); + await expect(page.locator('h1.pf-c-title:nth-child(2)')).toHaveText(/no sessions/i); + await expect(page.locator('.pf-c-empty-state__body')).toHaveText(/there are currently no active sessions for this client/i); + await page.goto(`${SUPERSET_URL}/superset/welcome`); + await expect(page).toHaveURL(/.*login/); +}); + test('Creating a Superset role creates the corresponding Keycloak role.', async ({ page }) => { // setup await openmrs.login(); @@ -111,34 +139,6 @@ test('A synced role deleted from within Keycloak gets recreated in the subsequen await superset.logout(); }); -test('Logging out from Superset logs out the user from Keycloak.', async ({ page }) => { - // setup - await superset.open(); - await openmrs.enterLoginCredentials(); - await expect(page).toHaveURL(/.*superset/); - await expect(page.locator('#app div.header')).toHaveText(/home/i); - await keycloak.open(); - await keycloak.navigateToClients(); - await keycloak.selectSupersetId(); - await keycloak.selectSessions(); - await expect(page.locator('td:nth-child(1) a').nth(0)).toHaveText(/jdoe/i); - - // replay - await superset.logout(); - await keycloak.confirmLogout(); - await expect(page).toHaveURL(/.*login/); - - // verify - await page.goto(`${KEYCLOAK_URL}/admin/master/console`); - await keycloak.navigateToClients(); - await keycloak.selectSupersetId(); - await keycloak.selectSessions(); - await expect(page.locator('h1.pf-c-title:nth-child(2)')).toHaveText(/no sessions/i); - await expect(page.locator('.pf-c-empty-state__body')).toHaveText(/there are currently no active sessions for this client/i); - await page.goto(`${SUPERSET_URL}/superset/welcome`); - await expect(page).toHaveURL(/.*login/); -}); - test.afterEach(async ({ page }) => { await page.close(); }); diff --git a/package.json b/package.json index 7c98608..d702b36 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "!playwright-report/" ], "scripts": { - "ozone-pro": "npx playwright test", + "ozone-pro": "npx playwright test erpnext", "ozone-foss": "npx playwright test odoo-openmrs erpnext-openmrs openmrs-senaite", "openmrs-distro-his": "npx playwright test odoo-openmrs openmrs-senaite" }, diff --git a/playwright.config.ts b/playwright.config.ts index d4222e6..244cb81 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -24,7 +24,9 @@ const config: PlaywrightTestConfig = { name: 'chromium', use: { ...devices['Desktop Chromium'], - viewport: { width: 1920, height: 1080 } + viewport: { width: 1920, height: 1080 }, + video: 'retain-on-failure', + screenshot: 'only-on-failure' }, },