diff --git a/.env b/.env index 3d1b53c..9e2ac72 100644 --- a/.env +++ b/.env @@ -36,5 +36,5 @@ ODOO_USERNAME=admin ODOO_PASSWORD=admin # OpenELIS test user credentials -OpenELIS_USERNAME=admin -OpenELIS_PASSWORD=adminADMIN! +OPENELIS_USERNAME=admin +OPENELIS_PASSWORD=adminADMIN! diff --git a/e2e/tests/bahmni-openelis-flows.spec.ts b/e2e/tests/bahmni-openelis-flows.spec.ts new file mode 100644 index 0000000..34ffe5f --- /dev/null +++ b/e2e/tests/bahmni-openelis-flows.spec.ts @@ -0,0 +1,130 @@ +import { test, expect } from '@playwright/test'; +import { Odoo } from '../utils/functions/odoo'; +import { Bahmni, patientName } from '../utils/functions/bahmni'; +import { OpenELIS } from '../utils/functions/openelis'; +import { BAHMNI_URL, OPENELIS_URL } from '../utils/configs/globalSetup'; + +let bahmni: Bahmni; +let openelis: OpenELIS; + +test.beforeEach(async ({ page }) => { + bahmni = new Bahmni(page); + openelis = new OpenELIS(page); + + await bahmni.login(); + await expect(page.getByText(/registration/i)).toBeVisible(); + await expect(page.getByText(/linical/i)).toBeVisible(); + await expect(page.getByText(/admin/i)).toBeVisible(); + await expect(page.getByText(/appointment scheduling/i)).toBeVisible(); + await expect(page.getByText(/patient documents/i)).toBeVisible(); +}); + +test('Ordering a lab test for a Bahmni patient creates the corresponding OpenElis client with an analysis request.', async ({ page }) => { + // setup + await bahmni.registerPatient(); + + // replay + await bahmni.goToHomePage(); + await bahmni.goToLabSamples(); + await bahmni.createLabOrder(); + await page.locator('#dashboard-link span.patient-name').click(); + await expect(page.locator('#Lab-Orders').getByText('Malaria')) .toBeVisible(); + + // verify + await openelis.open(); + await expect(page).toHaveURL(/.*openelis/); + await openelis.searchClient(); + + const clientSelector = await page.locator("#todaySamplesToCollectListContainer-slick-grid div.slick-cell.l1.r1"); + await expect(clientSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`); + + //await page.locator('#todaySamplesToCollectListContainer-slick-grid div.slick-viewport div.slick-cell.l6.r6.cell-title a').click(); + //const labTest = await page.locator('#tests_1'); + //await expect(page.locator('#tests_1')).toBe('Malaria'); +}); + + +test('Editing the details of an Bahmni patient with a synced lab order edits the corresponding OpenELIS client details.', async ({ page }) => { + // setup + await bahmni.registerPatient(); + await bahmni.goToHomePage(); + await bahmni.goToLabSamples(); + await bahmni.createLabOrder(); + await page.locator('#dashboard-link span.patient-name').click(); + await expect(page.locator('#Lab-Orders').getByText('Malaria')) .toBeVisible(); + await openelis.open(); + await expect(page).toHaveURL(/.*openelis/); + await openelis.searchClient(); + const clientSelector = await page.locator("#todaySamplesToCollectListContainer-slick-grid div.slick-cell.l1.r1"); + await expect(clientSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`); + + // replay + await page.goto(`${BAHMNI_URL}`); + await bahmni.updatePatientDetails(); + + // verify + await openelis.open(); + await openelis.searchClient(); + await expect(clientSelector).toHaveText(`${patientName.updatedGivenName}` + ' ' + `${patientName.familyName}`); +}); + + +test('Revising a synced Bahmni lab order edits the corresponding OpenELIS client analysis request.', async ({ page }) => { + // setup + await bahmni.registerPatient(); + await bahmni.goToHomePage(); + await bahmni.goToLabSamples(); + await bahmni.createLabOrder(); + await page.locator('#dashboard-link span.patient-name').click(); + await expect(page.locator('#Lab-Orders').getByText('Malaria')) .toBeVisible(); + await openelis.open(); + await expect(page).toHaveURL(/.*openelis/); + await openelis.searchClient(); + const clientSelector = await page.locator("#todaySamplesToCollectListContainer-slick-grid div.slick-cell.l1.r1"); + await expect(clientSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`); + + // replay + await page.goto(`${BAHMNI_URL}`); + await bahmni.goToLabSamples(); + await bahmni.reviseLabOrder(); + + // verify + await openelis.open(); + await openelis.searchClient(); + await expect(clientSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`); + + await page.locator('#todaySamplesToCollectListContainer-slick-grid div.slick-viewport div.slick-cell.l6.r6.cell-title a').click(); + //const labTest = await page.locator('#tests_1'); + //await expect(page.locator('#tests_1')).toBe('Malaria'); +}); + +test('Voiding a synced OpenMRS lab order cancels the corresponding OpenElis analysis request.', async ({ page }) => { + // setup + await bahmni.registerPatient(); + await bahmni.goToHomePage(); + await bahmni.goToLabSamples(); + await bahmni.createLabOrder(); + await page.locator('#dashboard-link span.patient-name').click(); + await expect(page.locator('#Lab-Orders').getByText('Malaria')) .toBeVisible(); + await openelis.open(); + await expect(page).toHaveURL(/.*openelis/); + await page.locator('#menu_labDashboard').click(); + await page.locator('input[type=text]').nth(1).type(`${patientName.familyName}`); + const clientSelector = await page.locator("#todaySamplesToCollectListContainer-slick-grid div.slick-cell.l1.r1"); + await expect(clientSelector).toHaveText(`${patientName.givenName + ' ' + patientName.familyName}`); + + // replay + await page.goto(`${BAHMNI_URL}`); + await bahmni.goToLabSamples(); + await bahmni.discontinueLabOrder(); + + // verify + await openelis.open(); + await openelis.searchClient(); + //await expect(page.getByText(`${patientName.givenName + ' ' + patientName.familyName}`)).not.toBeVisible(); +}); + +test.afterEach(async ({ page }) => { + await bahmni.voidPatient(); + await page.close(); +}); diff --git a/e2e/utils/configs/globalSetup.ts b/e2e/utils/configs/globalSetup.ts index 181e0b0..e8770b0 100644 --- a/e2e/utils/configs/globalSetup.ts +++ b/e2e/utils/configs/globalSetup.ts @@ -13,6 +13,7 @@ dotenv.config(); export const BAHMNI_URL = `${process.env.TEST_ENVIRONMENT}` == 'uat' ? `${process.env.BAHMNI_URL_UAT}` : `${process.env.BAHMNI_URL_DEV}`; export const ODOO_URL = `${process.env.TEST_ENVIRONMENT}` == 'uat' ? `${process.env.ODOO_URL_UAT}` : `${process.env.ODOO_URL_DEV}`; +export const OPENELIS_URL = `${process.env.TEST_ENVIRONMENT}` == 'uat' ? `${process.env.OPENELIS_URL_UAT}` : `${process.env.OPENELIS_URL_DEV}`; async function globalSetup() { const requestContext = await request.newContext(); diff --git a/e2e/utils/functions/bahmni.ts b/e2e/utils/functions/bahmni.ts index 9b39f4e..01fc988 100644 --- a/e2e/utils/functions/bahmni.ts +++ b/e2e/utils/functions/bahmni.ts @@ -7,6 +7,8 @@ export var patientName = { updatedGivenName: '', } +export const delay = (mills) => new Promise(resolve => setTimeout(resolve, mills)); + export class Bahmni { constructor(readonly page: Page) {} @@ -48,10 +50,12 @@ export class Bahmni { await this.page.locator('#name').fill(`${patientName.familyName}`); await this.page.locator('form[name="searchByNameForm"]').getByRole('button', { name: 'Search' }).click(); await this.page.locator('#view-content td:nth-child(1) a').click(); + await delay(2000) await this.page.locator('#givenName').clear(); await this.page.locator('#givenName').fill(`${patientName.updatedGivenName}`); await this.page.getByRole('button', { name: 'Save' }).click(); patientName.givenName = `${patientName.updatedGivenName}`; + await delay(3000); }; async voidPatient() { @@ -76,6 +80,7 @@ export class Bahmni { await this.page.getByText('Blood', { exact: true }).click(); await this.page.getByText('Malaria').click(); await this.saveOrder(); + await delay(5000); } async reviseLabOrder() { @@ -92,7 +97,7 @@ export class Bahmni { } async goToHomePage() { - await this.page.goto(`${BAHMNI_URL}/bahmni/home/`); + await this.page.goto(`${BAHMNI_URL}/bahmni/home`); await expect(this.page).toHaveURL(/.*home/); } diff --git a/e2e/utils/functions/openelis.ts b/e2e/utils/functions/openelis.ts new file mode 100644 index 0000000..10603e6 --- /dev/null +++ b/e2e/utils/functions/openelis.ts @@ -0,0 +1,19 @@ +import { Page } from '@playwright/test'; +import { OPENELIS_URL } from '../configs/globalSetup'; +import { patientName } from './bahmni'; + +export class OpenELIS { + constructor(readonly page: Page) {} + + async open() { + await this.page.goto(`${OPENELIS_URL}`); + await this.page.locator("input[name='loginName']").fill(`${process.env.OPENELIS_USERNAME}`); + await this.page.locator("input[name='password']").fill(`${process.env.OPENELIS_PASSWORD}`); + await this.page.locator('#submitButton').click(); + } + + async searchClient() { + await this.page.locator('#menu_labDashboard').click(); + await this.page.locator('input[type=text]').nth(1).type(`${patientName.familyName}`); + } +} diff --git a/package.json b/package.json index c52ced8..951ecbc 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "license": "MPL-2.0", "description": "These are end-to-end automated tests covering Bahmni distro C2C workflows", "scripts": { - "e2e-tests-c2c": "npx playwright test" + "e2e-tests-c2c": "npx playwright test openelis" }, "keywords": [], "devDependencies": { diff --git a/playwright.config.ts b/playwright.config.ts index 23720b1..f7c1c56 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -25,7 +25,9 @@ const config: PlaywrightTestConfig = { ...devices['Desktop Chromium'], launchOptions: { slowMo: 500 - } + }, + video: 'retain-on-failure', + screenshot: 'only-on-failure' }, }, ],