Skip to content

Commit

Permalink
OZ-686: Log out of each component after every test (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaud authored Oct 14, 2024
1 parent 56dd2e4 commit dc799b2
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 44 deletions.
3 changes: 2 additions & 1 deletion e2e/tests/erpnext-openmrs-flows.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';
import { O3_URL, ERPNEXT_URL } from '../utils/configs/globalSetup';
import { ERPNext } from '../utils/functions/erpnext';
import { OpenMRS, patientName } from '../utils/functions/openmrs';
import { O3_URL, ERPNEXT_URL } from '../utils/configs/globalSetup';

let openmrs: OpenMRS;
let erpnext: ERPNext;
Expand Down Expand Up @@ -215,5 +215,6 @@ test('Ordering a drug for an OpenMRS patient within a visit creates the correspo

test.afterEach(async ({ page }) => {
await erpnext.deleteCustomer();
await openmrs.logout();
await page.close();
});
10 changes: 2 additions & 8 deletions e2e/tests/keycloak-odoo-flows.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from '@playwright/test';
import { KEYCLOAK_URL, ODOO_URL } from '../utils/configs/globalSetup';
import { Odoo } from '../utils/functions/odoo';
import { OpenMRS } from '../utils/functions/openmrs';
import { Keycloak } from '../utils/functions/keycloak';
import { KEYCLOAK_URL, ODOO_URL } from '../utils/configs/globalSetup';

let odoo: Odoo;
let openmrs: OpenMRS;
Expand All @@ -27,13 +27,7 @@ test('Logging out from Odoo logs out the user from Keycloak.', async ({ page })
await expect(page.locator('td:nth-child(1) a').nth(0)).toHaveText(/jdoe/i);

// replay
await page.goto(`${ODOO_URL}`);
await expect(page.locator('.o_user_menu>a')).toBeVisible();
await page.locator('.o_user_menu>a').click();
await expect(page.getByRole('menuitem', { name: /log out/i })).toBeVisible();
await page.getByRole('menuitem', { name: /log out/i }).click();
await keycloak.confirmLogout();
await expect(page).toHaveURL(/.*login/);
await odoo.logout();

// verify
await page.goto(`${KEYCLOAK_URL}/admin/master/console`);
Expand Down
14 changes: 6 additions & 8 deletions e2e/tests/keycloak-openmrs-flows.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';
import { O3_URL, KEYCLOAK_URL } from '../utils/configs/globalSetup';
import { Keycloak, randomKeycloakRoleName } from '../utils/functions/keycloak';
import { OpenMRS, delay, randomOpenMRSRoleName } from '../utils/functions/openmrs';
import { O3_URL, KEYCLOAK_URL } from '../utils/configs/globalSetup';

let openmrs: OpenMRS;
let keycloak: Keycloak;
Expand Down Expand Up @@ -36,6 +36,7 @@ test('Creating an OpenMRS role creates the corresponding Keycloak role.', async
await expect(page.getByText('Application: Has Super User Privileges')).toBeTruthy();
await expect(page.getByText('Application: Administers System')).toBeTruthy();
await openmrs.deleteRole();
await openmrs.logout();
});

test('Updating a synced OpenMRS role updates the corresponding Keycloak role.', async ({ page }) => {
Expand Down Expand Up @@ -72,6 +73,7 @@ test('Updating a synced OpenMRS role updates the corresponding Keycloak role.',
await expect(page.getByText('Application: Registers Patients')).toBeTruthy();
await expect(page.getByText('Application: Writes Clinical Notes')).toBeTruthy();
await openmrs.deleteRole();
await openmrs.logout();
});

test('Deleting a synced OpenMRS role deletes the corresponding Keycloak role.', async ({ page }) => {
Expand Down Expand Up @@ -103,6 +105,7 @@ test('Deleting a synced OpenMRS role deletes the corresponding Keycloak role.',
await keycloak.selectRoles();
await keycloak.searchOpenMRSRole();
await expect(page.getByText(`${randomOpenMRSRoleName.roleName}`)).not.toBeVisible();
await openmrs.logout();
});

test('A (non-synced) role created from within Keycloak gets deleted in the subsequent polling cycle.', async ({ page }) => {
Expand All @@ -125,6 +128,7 @@ test('A (non-synced) role created from within Keycloak gets deleted in the subse
await page.getByPlaceholder('Search role by name').fill(`${randomKeycloakRoleName.roleName}`);
await page.getByRole('button', { name: 'Search' }).press('Enter');
await expect(page.getByText(`${randomKeycloakRoleName.roleName}`)).not.toBeVisible();
await openmrs.logout();
});

test('Logging out from OpenMRS logs out the user from Keycloak.', async ({ page }) => {
Expand All @@ -136,13 +140,7 @@ test('Logging out from OpenMRS logs out the user from Keycloak.', async ({ page
await expect(page.locator('td:nth-child(1) a').nth(0)).toHaveText(/jdoe/i);

// replay
await page.goto(`${O3_URL}`);
await expect(page.getByLabel(/my account/i)).toBeVisible();
await page.getByLabel(/my account/i).click();
await expect(page.getByRole('button', { name: /logout/i })).toBeVisible();
await page.getByRole('button', { name: /logout/i }).click();
await keycloak.confirmLogout();
await expect(page).toHaveURL(/.*login/);
await openmrs.logout();

// verify
await page.goto(`${KEYCLOAK_URL}/admin/master/console`);
Expand Down
12 changes: 3 additions & 9 deletions e2e/tests/keycloak-senaite-flows.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from '@playwright/test';
import { KEYCLOAK_URL, SENAITE_URL } from '../utils/configs/globalSetup';
import { Keycloak } from '../utils/functions/keycloak';
import { OpenMRS } from '../utils/functions/openmrs';
import { SENAITE } from '../utils/functions/senaite';
import { KEYCLOAK_URL, SENAITE_URL } from '../utils/configs/globalSetup';

let openmrs: OpenMRS;
let senaite: SENAITE;
Expand All @@ -27,13 +27,7 @@ test('Logging out from SENAITE logs out the user from Keycloak.', async ({ page
await expect(page.locator('td:nth-child(1) a').nth(0)).toHaveText(/jdoe/i);

// replay
await page.goto(`${SENAITE_URL}`);
await expect(page.locator('#navbarUserDropdown')).toBeVisible();
await page.locator('#navbarUserDropdown').click();
await expect(page.getByRole('link', { name: /log out/i })).toBeVisible();
await page.getByRole('link', { name: /log out/i }).click();
await keycloak.confirmLogout();
await expect(page.locator('#username')).toBeVisible();
await senaite.logout();

// verify
await page.goto(`${KEYCLOAK_URL}/admin/master/console`);
Expand All @@ -43,7 +37,7 @@ test('Logging out from SENAITE logs out the user from Keycloak.', async ({ page
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(`${SENAITE_URL}/senaite-dashboard`);
await expect(page).toHaveURL(/.*login/);
await expect(page.locator('#username')).toBeVisible();
});

test.afterEach(async ({ page }) => {
Expand Down
13 changes: 6 additions & 7 deletions e2e/tests/keycloak-superset-flows.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from '@playwright/test';
import { KEYCLOAK_URL, SUPERSET_URL } from '../utils/configs/globalSetup';
import { Keycloak } from '../utils/functions/keycloak';
import { OpenMRS, delay } from '../utils/functions/openmrs';
import { Superset, randomSupersetRoleName} from '../utils/functions/superset';
import { KEYCLOAK_URL, SUPERSET_URL } from '../utils/configs/globalSetup';

let openmrs: OpenMRS;
let keycloak: Keycloak;
Expand Down Expand Up @@ -30,6 +30,7 @@ test('Creating a Superset role creates the corresponding Keycloak role.', async
await keycloak.searchSupersetRole();
await expect(page.locator('tbody:nth-child(2) td:nth-child(1) a')).toHaveText(`${randomSupersetRoleName.roleName}`);
await superset.deleteRole();
await superset.logout();
});

test('Updating a synced Superset role updates the corresponding Keycloak role.', async ({ page }) => {
Expand All @@ -56,6 +57,7 @@ test('Updating a synced Superset role updates the corresponding Keycloak role.',
await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).not.toBeVisible();
await expect(page.getByText(`${randomSupersetRoleName.updatedRoleName}`)).toBeVisible();
await superset.deleteUpdatedRole();
await superset.logout();
});

test('Deleting a synced Superset role deletes the corresponding Keycloak role.', async ({ page }) => {
Expand All @@ -81,6 +83,7 @@ test('Deleting a synced Superset role deletes the corresponding Keycloak role.',
await keycloak.selectRoles();
await keycloak.searchSupersetRole();
await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).not.toBeVisible();
await superset.logout();
});

test('A synced role deleted from within Keycloak gets recreated in the subsequent polling cycle.', async ({ page }) => {
Expand All @@ -105,6 +108,7 @@ test('A synced role deleted from within Keycloak gets recreated in the subsequen
await keycloak.searchSupersetRole();
await expect(page.locator('tbody:nth-child(2) td:nth-child(1) a')).toHaveText(`${randomSupersetRoleName.roleName}`);
await superset.deleteRole();
await superset.logout();
});

test('Logging out from Superset logs out the user from Keycloak.', async ({ page }) => {
Expand All @@ -120,12 +124,7 @@ test('Logging out from Superset logs out the user from Keycloak.', async ({ page
await expect(page.locator('td:nth-child(1) a').nth(0)).toHaveText(/jdoe/i);

// replay
await page.goto(`${SUPERSET_URL}`);
await page.getByRole('button', { name: /settings/i }).click();
await expect(page.getByRole('link', { name: /logout/i })).toBeVisible();
await page.getByRole('link', { name: /logout/i }).click();
await keycloak.confirmLogout();
await expect(page).toHaveURL(/.*login/);
await superset.logout();

// verify
await page.goto(`${KEYCLOAK_URL}/admin/master/console`);
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/odoo-openmrs-flows.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';
import { O3_URL, ODOO_URL } from '../utils/configs/globalSetup';
import { Odoo } from '../utils/functions/odoo';
import { OpenMRS, patientName } from '../utils/functions/openmrs';
import { O3_URL, ODOO_URL } from '../utils/configs/globalSetup';

let odoo: Odoo;
let openmrs: OpenMRS;
Expand Down Expand Up @@ -226,6 +226,8 @@ test('Discontinuing a synced OpenMRS lab order for an Odoo customer with a singl
});

test.afterEach(async ({ page }) => {
await odoo.logout();
await openmrs.voidPatient();
await openmrs.logout();
await page.close();
});
5 changes: 4 additions & 1 deletion e2e/tests/odoo-superset-flows.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from '@playwright/test';
import { O3_URL, SUPERSET_URL } from '../utils/configs/globalSetup';
import { Odoo } from '../utils/functions/odoo';
import { Superset } from '../utils/functions/superset';
import { OpenMRS, patientName } from '../utils/functions/openmrs';
import { O3_URL, SUPERSET_URL } from '../utils/configs/globalSetup';

let odoo: Odoo;
let openmrs: OpenMRS;
Expand Down Expand Up @@ -114,6 +114,9 @@ test(`A (synced) sale order line in Odoo generates an entry in Superset's sale_o
});

test.afterEach(async ({ page }) => {
await superset.logout();
await odoo.logout();
await openmrs.voidPatient();
await openmrs.logout();
await page.close();
});
4 changes: 3 additions & 1 deletion e2e/tests/openmrs-senaite-flows.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';
import { O3_URL, SENAITE_URL } from '../utils/configs/globalSetup';
import { OpenMRS, patientName } from '../utils/functions/openmrs';
import { SENAITE } from '../utils/functions/senaite';
import { O3_URL, SENAITE_URL } from '../utils/configs/globalSetup';

let openmrs: OpenMRS;
let senaite: SENAITE;
Expand Down Expand Up @@ -124,6 +124,8 @@ test('Published free text lab results from SENAITE are viewable in the OpenMRS l
});

test.afterEach(async ({ page }) => {
await senaite.logout();
await openmrs.voidPatient();
await openmrs.logout();
await page.close();
});
4 changes: 3 additions & 1 deletion e2e/tests/openmrs-superset-flows.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';
import { O3_URL, SUPERSET_URL } from '../utils/configs/globalSetup';
import { OpenMRS, patientName } from '../utils/functions/openmrs';
import { Superset } from '../utils/functions/superset';
import { O3_URL, SUPERSET_URL } from '../utils/configs/globalSetup';

let openmrs: OpenMRS;
let superset: Superset;
Expand Down Expand Up @@ -496,5 +496,7 @@ test(`Cancelling an OpenMRS appointment updates the appointment in Superset's ap
});

test.afterEach(async ({ page }) => {
await openmrs.logout();
await superset.logout();
await page.close();
});
2 changes: 1 addition & 1 deletion e2e/utils/functions/erpnext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Page, expect } from '@playwright/test';
import { delay, patientName } from './openmrs';
import { ERPNEXT_URL } from '../configs/globalSetup';
import { delay, patientName } from './openmrs';

export class ERPNext {
constructor(readonly page: Page) {}
Expand Down
2 changes: 1 addition & 1 deletion e2e/utils/functions/keycloak.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Page, expect } from '@playwright/test';
import { randomSupersetRoleName } from './superset';
import { KEYCLOAK_URL } from '../configs/globalSetup';
import { randomSupersetRoleName } from './superset';
import { delay, randomOpenMRSRoleName } from './openmrs';

export var randomKeycloakRoleName = {
Expand Down
14 changes: 13 additions & 1 deletion e2e/utils/functions/odoo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, Page } from '@playwright/test';
import { delay, patientName } from './openmrs';
import { ODOO_URL } from '../configs/globalSetup';
import { Keycloak } from './keycloak';
import { delay, patientName } from './openmrs';

export class Odoo {
constructor(readonly page: Page) {}
Expand Down Expand Up @@ -53,4 +54,15 @@ export class Odoo {
await expect(this.page.locator('td.o_data_cell:nth-child(9)')).toHaveText('2.00');
await expect(this.page.locator('td.o_data_cell:nth-child(11)')).toHaveText('$ 16.00');
}

async logout() {
await this.page.goto(`${ODOO_URL}`);
await expect(this.page.locator('.o_user_menu>a')).toBeVisible();
await this.page.locator('.o_user_menu>a').click();
await expect(this.page.getByRole('menuitem', { name: /log out/i })).toBeVisible();
await this.page.getByRole('menuitem', { name: /log out/i }).click();
let keycloak = new Keycloak(this.page);
await keycloak.confirmLogout();
await expect(this.page).toHaveURL(/.*login/);
}
}
16 changes: 14 additions & 2 deletions e2e/utils/functions/openmrs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Page, expect } from '@playwright/test';
import { O3_URL } from '../configs/globalSetup';
import { Keycloak } from './keycloak';

export var patientName = {
firstName : '',
Expand Down Expand Up @@ -350,14 +351,14 @@ export class OpenMRS {
await this.page.getByRole('button', { name: 'Actions', exact: true }).click();
await this.page.getByRole('menuitem', { name: 'Edit patient details' }).click();
await delay(4000);
await expect(this.page.getByLabel('First Name')).toBeVisible();
await this.page.getByLabel('First Name').clear();
await this.page.getByLabel('First Name').type(`${patientName.updatedFirstName}`);
await delay(4000);
await delay(2000);
await this.page.locator('label').filter({ hasText: 'Female' }).locator('span').first().click();
await this.page.getByRole('button', { name: 'Update Patient' }).click();
await expect(this.page.getByText('Patient Details Updated')).toBeVisible();
patientName.firstName = `${patientName.updatedFirstName}`;
await this.page.getByRole('button', { name: 'Close', exact: true }).click();
await delay(5000);
}

Expand Down Expand Up @@ -419,4 +420,15 @@ export class OpenMRS {
await expect(this.page.getByText(`${randomOpenMRSRoleName.roleName} deleted`)).toBeVisible();
await this.page.getByRole('link', { name: 'Log out' }).click();
}

async logout() {
await this.page.goto(`${O3_URL}`);
await expect(this.page.getByLabel(/my account/i)).toBeVisible();
await this.page.getByLabel(/my account/i).click();
await expect(this.page.getByRole('button', { name: /logout/i })).toBeVisible();
await this.page.getByRole('button', { name: /logout/i }).click();
let keycloak = new Keycloak(this.page);
await keycloak.confirmLogout();
await expect(this.page).toHaveURL(/.*login/);
}
}
14 changes: 13 additions & 1 deletion e2e/utils/functions/senaite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, Page } from '@playwright/test';
import { delay, patientName } from './openmrs';
import { SENAITE_URL } from '../configs/globalSetup';
import { delay, patientName } from './openmrs';
import { Keycloak } from './keycloak';

export class SENAITE {
constructor(readonly page: Page) {}
Expand Down Expand Up @@ -54,4 +55,15 @@ export class SENAITE {
await expect(this.page.locator('table tbody tr.contentrow.state-published.parent td.contentcell.State span span')).toHaveText('Published');
await delay(30000);
}

async logout() {
await this.page.goto(`${SENAITE_URL}`);
await expect(this.page.locator('#navbarUserDropdown')).toBeVisible();
await this.page.locator('#navbarUserDropdown').click();
await expect(this.page.getByRole('link', { name: /log out/i })).toBeVisible();
await this.page.getByRole('link', { name: /log out/i }).click();
let keycloak = new Keycloak(this.page);
await keycloak.confirmLogout();
await expect(this.page.locator('#username')).toBeVisible();
}
}
13 changes: 12 additions & 1 deletion e2e/utils/functions/superset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Page, expect } from '@playwright/test';
import { delay } from './openmrs';
import { SUPERSET_URL } from '../configs/globalSetup';
import { delay } from './openmrs';
import { Keycloak } from './keycloak';

export var randomSupersetRoleName = {
roleName : `${(Math.random() + 1).toString(36).substring(2)}`,
Expand Down Expand Up @@ -98,4 +99,14 @@ export class Superset {
await expect(this.page.getByText(`Deleted Row`)).toBeVisible();
await expect(this.page.getByText(`${randomSupersetRoleName.updatedRoleName}`)).not.toBeVisible();
}

async logout() {
await this.page.goto(`${SUPERSET_URL}`);
await this.page.getByRole('button', { name: /settings/i }).click();
await expect(this.page.getByRole('link', { name: /logout/i })).toBeVisible();
await this.page.getByRole('link', { name: /logout/i }).click();
let keycloak = new Keycloak(this.page);
await keycloak.confirmLogout();
await expect(this.page).toHaveURL(/.*login/);
}
}

0 comments on commit dc799b2

Please sign in to comment.