diff --git a/e2e/tests/keycloak-openmrs-flows.spec.ts b/e2e/tests/keycloak-openmrs-flows.spec.ts index a86b3ef3..6e11b48a 100644 --- a/e2e/tests/keycloak-openmrs-flows.spec.ts +++ b/e2e/tests/keycloak-openmrs-flows.spec.ts @@ -1,191 +1,183 @@ import { test, expect } from '@playwright/test'; -import { HomePage, delay, randomKeycloakRoleName } from '../utils/functions/testBase'; -import { randomOpenMRSRoleName, randomSupersetRoleName } from '../utils/functions/testBase'; +import { Keycloak, randomKeycloakRoleName } from '../utils/functions/keycloak'; +import { OpenMRS, delay, randomOpenMRSRoleName } from '../utils/functions/openmrs'; +import { Superset, randomSupersetRoleName} from '../utils/functions/superset'; import { O3_URL, KEYCLOAK_URL } from '../utils/configs/globalSetup'; -let homePage: HomePage; +let openmrs: OpenMRS; +let keycloak: Keycloak; +let superset: Superset; test.beforeEach(async ({ page }) => { - homePage = new HomePage(page); + openmrs = new OpenMRS(page); + keycloak = new Keycloak(page); + superset = new Superset(page); + + await openmrs.login(); + await expect(page).toHaveURL(/.*home/); }); test('Creating an OpenMRS role creates the corresponding Keycloak role.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); await page.goto(`${O3_URL}/openmrs/admin/users/role.list`); - await homePage.addOpenMRSRole(); + await openmrs.addRole(); // verify - await homePage.goToKeycloak(); + await keycloak.open(); await expect(page).toHaveURL(/.*console/); - await homePage.goToClients(); - await homePage.selectOpenMRSId() + await keycloak.goToClients(); + await keycloak.selectOpenMRSId() await expect(page.getByText(`${randomOpenMRSRoleName.roleName}`)).toBeVisible(); await expect(page.getByText('Role for e2e test').first()).toBeVisible(); - await homePage.goToClientAttributes(); + await keycloak.goToClientAttributes(); await expect(page.getByText('Organizational: Registration Clerk')).toBeTruthy(); await expect(page.getByText('Application: Edits Existing Encounters')).toBeTruthy(); await expect(page.getByText('Application: Uses Patient Summary')).toBeTruthy(); await expect(page.getByText('Application: Has Super User Privileges')).toBeTruthy(); await expect(page.getByText('Application: Administers System')).toBeTruthy(); - await homePage.deleteOpenMRSRole(); + await openmrs.deleteRole(); }); test('Updating a synced OpenMRS role updates the corresponding Keycloak role.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); await page.goto(`${O3_URL}/openmrs/admin/users/role.list`); - await homePage.addOpenMRSRole(); - await homePage.goToKeycloak(); + await openmrs.addRole(); + await keycloak.open(); await expect(page).toHaveURL(/.*console/); - await homePage.goToClients(); - await homePage.selectOpenMRSId(); + await keycloak.goToClients(); + await keycloak.selectOpenMRSId(); await expect(page.getByText(`${randomOpenMRSRoleName.roleName}`)).toBeVisible(); await expect(page.getByText('Role for e2e test').first()).toBeVisible(); - await homePage.goToClientAttributes(); + await keycloak.goToClientAttributes(); await expect(page.getByText('Application: Enters Vitals')).toBeTruthy(); await expect(page.getByText('Application: Edits Existing Encounters')).toBeTruthy(); await expect(page.getByText('Application: Uses Patient Summary')).toBeTruthy(); await expect(page.getByText('Organizational: Registration Clerk')).toBeTruthy(); await expect(page.getByText('Application: Records Allergies')).toBeTruthy(); await page.goto(`${O3_URL}/openmrs/admin/users/role.list`); - await homePage.updateOpenMRSRole(); + await openmrs.updateRole(); // verify await page.goto(`${KEYCLOAK_URL}/admin/master/console`); - await homePage.goToClients(); - await homePage.selectOpenMRSId(); - await homePage.goToClientAttributes(); + await keycloak.goToClients(); + await keycloak.selectOpenMRSId(); + await keycloak.goToClientAttributes(); await expect(page.getByText('Updated role description')).toBeTruthy(); await page.getByTestId('attributesTab').click(); await expect(page.getByText('Application: Registers Patients')).toBeTruthy(); await expect(page.getByText('Application: Writes Clinical Notes')).toBeTruthy(); - await homePage.deleteOpenMRSRole(); + await openmrs.deleteRole(); }); test('Deleting a synced OpenMRS role deletes the corresponding Keycloak role.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); await page.goto(`${O3_URL}/openmrs/admin/users/role.list`); - await homePage.addOpenMRSRole(); - await homePage.goToKeycloak(); + await openmrs.addRole(); + await keycloak.open(); await expect(page).toHaveURL(/.*console/); - await homePage.goToClients(); - await homePage.selectOpenMRSId(); + await keycloak.goToClients(); + await keycloak.selectOpenMRSId(); await expect(page.getByText(`${randomOpenMRSRoleName.roleName}`)).toBeVisible(); await expect(page.getByText('Role for e2e test').first()).toBeVisible(); - await homePage.goToClientAttributes(); + await keycloak.goToClientAttributes(); await expect(page.getByText('Application: Enters Vitals')).toBeTruthy(); await expect(page.getByText('Application: Edits Existing Encounters')).toBeTruthy(); await expect(page.getByText('Application: Uses Patient Summary')).toBeTruthy(); await expect(page.getByText('Organizational: Registration Clerk')).toBeTruthy(); await expect(page.getByText('Application: Records Allergies')).toBeTruthy(); - await homePage.deleteOpenMRSRole(); + await openmrs.deleteRole(); // verify await page.goto(`${KEYCLOAK_URL}/admin/master/console`); - await homePage.goToClients(); - await homePage.selectOpenMRSId(); + await keycloak.goToClients(); + await keycloak.selectOpenMRSId(); const roleName = await page.locator('table tbody tr:nth-child(1) td:nth-child(1) a'); await expect(roleName).not.toHaveText(`${randomOpenMRSRoleName.roleName}`); }); test('Creating a Superset role creates the corresponding Keycloak role.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.goToSuperset(); - await homePage.addSupersetRole(); + await superset.open(); + await superset.addRole(); // verify - await homePage.goToKeycloak(); - await homePage.goToClients(); - await homePage.selectSupersetId(); + await keycloak.open(); + await keycloak.goToClients(); + await keycloak.selectSupersetId(); await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible(); - await homePage.deleteSupersetRole(); + await superset.deleteRole(); }); test('Updating a synced Superset role updates the corresponding Keycloak role.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.goToSuperset(); - await homePage.addSupersetRole(); - await homePage.goToKeycloak(); - await homePage.goToClients(); - await homePage.selectSupersetId(); + await superset.open(); + await superset.addRole(); + await keycloak.open(); + await keycloak.goToClients(); + await keycloak.selectSupersetId(); await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible(); await expect(page.getByText('')).toBeTruthy(); - await homePage.updateSupersetRole(); + await superset.updateRole(); // verify await page.goto(`${KEYCLOAK_URL}/admin/master/console`); - await homePage.goToClients(); - await homePage.selectSupersetId(); + await keycloak.goToClients(); + await keycloak.selectSupersetId(); await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).not.toBeVisible(); await expect(page.getByText(`${randomSupersetRoleName.updatedRoleName}`)).toBeVisible(); - await homePage.deleteUpdatedSupersetRole(); + await superset.deleteUpdatedRole(); }); test('Deleting a synced Superset role deletes the corresponding Keycloak role.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.goToSuperset(); - await homePage.addSupersetRole(); - await homePage.goToKeycloak(); - await homePage.goToClients(); - await homePage.selectSupersetId(); + await superset.open(); + await superset.addRole(); + await keycloak.open(); + await keycloak.goToClients(); + await keycloak.selectSupersetId(); await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible(); - await homePage.deleteSupersetRole(); + await superset.deleteRole(); await delay(30000); // verify await page.goto(`${KEYCLOAK_URL}/admin/master/console`); - await homePage.goToClients(); - await homePage.selectSupersetId(); + await keycloak.goToClients(); + await keycloak.selectSupersetId(); await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).not.toBeVisible(); }); test('A synced role deleted from within Keycloak gets recreated in the subsequent polling cycle.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.goToSuperset(); - await homePage.addSupersetRole(); + await superset.open(); + await superset.addRole(); // verify - await homePage.goToKeycloak(); - await homePage.goToClients(); - await homePage.selectSupersetId(); + await keycloak.open(); + await keycloak.goToClients(); + await keycloak.selectSupersetId(); await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible(); - await homePage.deleteSyncedSupersetRoleInKeycloak(); + await keycloak.deleteSyncedRole(); await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).not.toBeVisible(); await delay(30000); await page.getByLabel('Manage').getByRole('link', { name: 'Clients' }).click(); - await homePage.selectSupersetId(); + await keycloak.selectSupersetId(); await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible(); - await homePage.deleteSupersetRole(); + await superset.deleteRole(); }); test('A (non-synced) role created from within Keycloak gets deleted in the subsequent polling cycle.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.goToKeycloak(); - await homePage.goToClients(); - await homePage.selectOpenMRSId(); - await homePage.createRoleInKeycloak(); + await keycloak.open(); + await keycloak.goToClients(); + await keycloak.selectOpenMRSId(); + await keycloak.createRole(); // verify await page.getByRole('link', { name: 'Client details' }).click(); await expect(page.getByText(`${randomKeycloakRoleName.roleName}`)).toBeVisible(); await delay(30000); await page.getByLabel('Manage').getByRole('link', { name: 'Clients' }).click(); - await homePage.selectOpenMRSId(); + await keycloak.selectOpenMRSId(); await expect(page.getByText(`${randomKeycloakRoleName.roleName}`)).not.toBeVisible(); }); diff --git a/e2e/tests/odoo-openmrs-flows.spec.ts b/e2e/tests/odoo-openmrs-flows.spec.ts index b098bb40..d01e2218 100644 --- a/e2e/tests/odoo-openmrs-flows.spec.ts +++ b/e2e/tests/odoo-openmrs-flows.spec.ts @@ -1,29 +1,32 @@ import { test, expect } from '@playwright/test'; -import { HomePage } from '../utils/functions/testBase'; -import { patientName } from '../utils/functions/testBase'; +import { Odoo } from '../utils/functions/odoo'; +import { OpenMRS, patientName } from '../utils/functions/openmrs'; import { O3_URL, ODOO_URL } from '../utils/configs/globalSetup'; -let homePage: HomePage; +let openmrs: OpenMRS; +let odoo: Odoo; test.beforeEach(async ({ page }) => { - homePage = new HomePage(page); + openmrs = new OpenMRS(page); + odoo = new Odoo(page); + + await openmrs.login(); + await expect(page).toHaveURL(/.*home/); + await openmrs.createPatient(); + await openmrs.startPatientVisit(); }); test('Ordering a lab test for an OpenMRS patient creates the corresponding Odoo customer with a filled quotation.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.goToLabOrderForm(); + await openmrs.goToLabOrderForm(); await page.getByRole('button', { name: 'Add', exact: true }).click(); await page.locator('#tab select').selectOption('857AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); - await homePage.saveLabOrder(); + await openmrs.saveLabOrder(); // verify - await homePage.goToOdoo(); + await odoo.open(); await expect(page).toHaveURL(/.*web/); - await homePage.searchCustomerInOdoo(); + await odoo.searchCustomer(); const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent(); await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy(); @@ -33,28 +36,24 @@ test('Ordering a lab test for an OpenMRS patient creates the corresponding Odoo test('Editing the details of an OpenMRS patient with a synced lab order edits the corresponding Odoo customer details.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.goToLabOrderForm(); + await openmrs.goToLabOrderForm(); await page.getByRole('button', { name: 'Add', exact: true }).click(); await page.locator('#tab select').selectOption('857AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); - await homePage.saveLabOrder(); - await homePage.goToOdoo(); + await openmrs.saveLabOrder(); + await odoo.open(); await expect(page).toHaveURL(/.*web/); - await homePage.searchCustomerInOdoo(); + await odoo.searchCustomer(); const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent(); await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy(); const quotation = await page.locator("table tbody td.o_data_cell:nth-child(8)").textContent(); await expect(quotation?.includes("Quotation")).toBeTruthy(); await page.goto(`${O3_URL}`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.updatePatientDetails(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.updatePatientDetails(); // verify await page.goto(`${ODOO_URL}`); - await homePage.searchCustomerInOdoo(); + await odoo.searchCustomer(); const updatedCustomer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)"); await expect(updatedCustomer).toHaveText(`${patientName.updatedFirstName}` + ' ' + `${patientName.givenName}`); await expect(quotation?.includes("Quotation")).toBeTruthy(); @@ -62,16 +61,12 @@ test('Editing the details of an OpenMRS patient with a synced lab order edits th test('Ordering a drug for an OpenMRS patient creates the corresponding Odoo customer with a filled quotation.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.makeDrugOrder(); + await openmrs.createDrugOrder(); // verify - await homePage.goToOdoo(); + await odoo.open(); await expect(page).toHaveURL(/.*web/); - await homePage.searchCustomerInOdoo(); + await odoo.searchCustomer(); const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent(); await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy(); @@ -81,25 +76,21 @@ test('Ordering a drug for an OpenMRS patient creates the corresponding Odoo cust test('Editing the details of an OpenMRS patient with a synced drug order edits the corresponding Odoo customer details.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.makeDrugOrder(); - await homePage.goToOdoo(); + await openmrs.createDrugOrder(); + await odoo.open(); await expect(page).toHaveURL(/.*web/); - await homePage.searchCustomerInOdoo(); + await odoo.searchCustomer(); const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent(); await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy(); const quotation = await page.locator("table tbody td.o_data_cell:nth-child(8)").textContent(); await expect(quotation?.includes("Quotation")).toBeTruthy(); await page.goto(`${O3_URL}`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.updatePatientDetails(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.updatePatientDetails(); // verify await page.goto(`${ODOO_URL}`); - await homePage.searchCustomerInOdoo(); + await odoo.searchCustomer(); const updatedCustomer = await page.locator("table tbody td.o_data_cell:nth-child(4)"); await expect(updatedCustomer).toHaveText(`${patientName.updatedFirstName}` + ' ' + `${patientName.givenName }`); @@ -108,14 +99,10 @@ test('Editing the details of an OpenMRS patient with a synced drug order edits t test('Revising a synced OpenMRS drug order edits the corresponding Odoo quotation line.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.makeDrugOrder(); - await homePage.goToOdoo(); + await openmrs.createDrugOrder(); + await odoo.open(); await expect(page).toHaveURL(/.*web/); - await homePage.searchCustomerInOdoo(); + await odoo.searchCustomer(); const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent(); await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy(); await page.getByRole('cell', { name: `${patientName.firstName + ' ' + patientName.givenName}` }).click(); @@ -123,12 +110,12 @@ test('Revising a synced OpenMRS drug order edits the corresponding Odoo quotatio await expect(drugOrderItem).toContainText('4.0 Tablet'); await expect(drugOrderItem).toContainText('Twice daily - 5 Days'); await page.goto(`${O3_URL}`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.editDrugOrder(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.editDrugOrder(); // verify await page.goto(`${ODOO_URL}`); - await homePage.searchCustomerInOdoo(); + await odoo.searchCustomer(); await page.getByRole('cell', { name: `${patientName.firstName + ' ' + patientName.givenName}` }).click(); await expect(drugOrderItem).toContainText('8.0 Tablet'); await expect(drugOrderItem).toContainText('Thrice daily - 6 Days'); @@ -136,14 +123,10 @@ test('Revising a synced OpenMRS drug order edits the corresponding Odoo quotatio test('Discontinuing a synced OpenMRS drug order removes the corresponding Odoo quotation line.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.makeDrugOrder(); - await homePage.goToOdoo(); + await openmrs.createDrugOrder(); + await odoo.open(); await expect(page).toHaveURL(/.*web/); - await homePage.searchCustomerInOdoo(); + await odoo.searchCustomer(); const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent(); await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy(); const quotation = await page.locator("table tbody td.o_data_cell:nth-child(8)"); @@ -152,12 +135,12 @@ test('Discontinuing a synced OpenMRS drug order removes the corresponding Odoo q const drugOrderItem = await page.locator("table tbody td.o_data_cell:nth-child(2) span:nth-child(1) span"); await expect(drugOrderItem).toHaveText('Aspirin 325mg'); await page.goto(`${O3_URL}`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.discontinueDrugOrder(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.discontinueDrugOrder(); // verify await page.goto(`${ODOO_URL}`); - await homePage.searchCustomerInOdoo(); + await odoo.searchCustomer(); await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy(); await expect(quotation).toHaveText('Cancelled'); await page.getByRole('cell', { name: `${patientName.firstName + ' ' + patientName.givenName}` }).click(); @@ -167,16 +150,12 @@ test('Discontinuing a synced OpenMRS drug order removes the corresponding Odoo q test('Ordering a drug with a free text medication dosage for an OpenMRS patient creates the corresponding Odoo customer with a filled quotation.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.prescribeFreeTextMedicationDosage(); + await openmrs.createDrugOrderWithFreeTextDosage(); // verify - await homePage.goToOdoo(); + await odoo.open(); await expect(page).toHaveURL(/.*web/); - await homePage.searchCustomerInOdoo(); + await odoo.searchCustomer(); const customer = await page.locator("tr.o_data_row:nth-child(1) td:nth-child(4)").textContent(); await expect(customer?.includes(`${patientName.firstName + ' ' + patientName.givenName}`)).toBeTruthy(); @@ -185,6 +164,6 @@ test('Ordering a drug with a free text medication dosage for an OpenMRS patient }); test.afterEach(async ({ page }) => { - await homePage.deletePatient(); + await openmrs.deletePatient(); await page.close(); }); diff --git a/e2e/tests/openmrs-senaite-flows.spec.ts b/e2e/tests/openmrs-senaite-flows.spec.ts index 011eebc2..c909f5c5 100644 --- a/e2e/tests/openmrs-senaite-flows.spec.ts +++ b/e2e/tests/openmrs-senaite-flows.spec.ts @@ -1,72 +1,67 @@ import { test, expect } from '@playwright/test'; -import { HomePage } from '../utils/functions/testBase'; -import { patientName } from '../utils/functions/testBase'; +import { OpenMRS, patientName } from '../utils/functions/openmrs'; +import { SENAITE } from '../utils/functions/senaite'; import { O3_URL } from '../utils/configs/globalSetup'; -let homePage: HomePage; +let openmrs: OpenMRS; +let senaite: SENAITE; test.beforeEach(async ({ page }) => { - homePage = new HomePage(page); + openmrs = new OpenMRS(page); + senaite = new SENAITE(page); + + await openmrs.login(); + await expect(page).toHaveURL(/.*home/); + await openmrs.createPatient(); + await openmrs.startPatientVisit(); }); test('Ordering a lab test for an OpenMRS patient creates the corresponding SENAITE client with an analysis request.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.goToLabOrderForm(); + await openmrs.goToLabOrderForm(); await page.getByRole('button', { name: 'Add', exact: true }).click(); await page.locator('#tab select').selectOption('857AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); - await homePage.saveLabOrder(); + await openmrs.saveLabOrder(); // verify - await homePage.goToSENAITE(); + await senaite.open(); await expect(page).toHaveURL(/.*senaite/); - await homePage.searchClientInSENAITE(); + await senaite.searchClient(); const client = await page.locator('table tbody tr:nth-child(1) td.contentcell.title div span a'); await expect(client).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`); }); test('Editing the details of an OpenMRS patient with a synced lab order edits the corresponding SENAITE client details.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.goToLabOrderForm(); + await openmrs.goToLabOrderForm(); await page.getByRole('button', { name: 'Add', exact: true }).click(); await page.locator('#tab select').selectOption('857AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); - await homePage.saveLabOrder(); - await homePage.goToSENAITE(); + await openmrs.saveLabOrder(); + await senaite.open(); await expect(page).toHaveURL(/.*senaite/); - await homePage.searchClientInSENAITE(); + await senaite.searchClient(); const client = await page.locator('table tbody tr:nth-child(1) td.contentcell.title div span a'); await expect(client).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`); await page.goto(`${O3_URL}`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.updatePatientDetails(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.updatePatientDetails(); // verify - await homePage.goToSENAITE(); - await homePage.searchClientInSENAITE(); + await senaite.open(); + await senaite.searchClient(); await expect(client).toContainText(`${patientName.updatedFirstName}` + ' ' + `${patientName.givenName }`); }); test('Editing a synced OpenMRS lab order edits the corresponding SENAITE analysis request.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.goToLabOrderForm(); + await openmrs.goToLabOrderForm(); await page.getByRole('button', { name: 'Add', exact: true }).click(); await page.locator('#tab select').selectOption('857AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); - await homePage.saveLabOrder(); - await homePage.goToSENAITE(); + await openmrs.saveLabOrder(); + await senaite.open(); await expect(page).toHaveURL(/.*senaite/); - await homePage.searchClientInSENAITE(); + await senaite.searchClient(); const client = await page.locator('table tbody tr:nth-child(1) td.contentcell.title div'); await expect(client).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`); await page.locator('table tbody tr:nth-child(1) td.contentcell.title div').click(); @@ -74,12 +69,12 @@ test('Editing a synced OpenMRS lab order edits the corresponding SENAITE analysi const analysisRequest = await page.locator('#sampleheader-standard-fields tr:nth-child(1) td:nth-child(6)'); await expect(analysisRequest).toHaveText('Blood urea nitrogen Template'); await page.goto(`${O3_URL}`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.updateLabOrder(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.updateLabOrder(); // verify - await homePage.goToSENAITE(); - await homePage.searchClientInSENAITE(); + await senaite.open(); + await senaite.searchClient(); await expect(client).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`); await page.locator('table tbody tr:nth-child(1) td.contentcell.title div').click(); @@ -89,17 +84,13 @@ test('Editing a synced OpenMRS lab order edits the corresponding SENAITE analysi test('Voiding a synced OpenMRS lab order cancels the corresponding SENAITE analysis request.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.goToLabOrderForm(); + await openmrs.goToLabOrderForm(); await page.getByRole('button', { name: 'Add', exact: true }).click(); await page.locator('#tab select').selectOption('857AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); - await homePage.saveLabOrder(); - await homePage.goToSENAITE(); + await openmrs.saveLabOrder(); + await senaite.open(); await expect(page).toHaveURL(/.*senaite/); - await homePage.searchClientInSENAITE(); + await senaite.searchClient(); const client = await page.locator('table tbody tr:nth-child(1) td.contentcell.title div'); await expect(client).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`); await page.locator('table tbody tr:nth-child(1) td.contentcell.title div').click(); @@ -107,37 +98,33 @@ test('Voiding a synced OpenMRS lab order cancels the corresponding SENAITE analy const analysisRequest = await page.locator('#sampleheader-standard-fields tr:nth-child(1) td:nth-child(6)'); await expect(analysisRequest).toHaveText('Blood urea nitrogen Template'); await page.goto(`${O3_URL}`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.voidEncounter(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.voidEncounter(); // verify - await homePage.goToSENAITE(); - await homePage.searchClientInSENAITE(); + await senaite.open(); + await senaite.searchClient(); await expect(client).not.toHaveText(`${patientName.firstName + ' ' + patientName.givenName}`); }); test('Published coded lab results from SENAITE are viewable in the OpenMRS lab results viewer.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.goToLabOrderForm(); + await openmrs.goToLabOrderForm(); await page.getByRole('button', { name: 'Add', exact: true }).click(); await page.locator('#tab select').selectOption('1325AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); - await homePage.saveLabOrder(); - await homePage.goToSENAITE(); + await openmrs.saveLabOrder(); + await senaite.open(); await expect(page).toHaveURL(/.*senaite/); - await homePage.searchClientInSENAITE(); - await homePage.createPartition(); + await senaite.searchClient(); + await senaite.createPartition(); await page.getByRole('combobox', { name: 'Result' }).selectOption('664AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); - await homePage.publishLabResults(); + await senaite.publishLabResults(); const reviewState = await page.locator('table tbody tr.contentrow.state-published.parent td.contentcell.State span span').textContent(); await expect(reviewState?.includes('Published')).toBeTruthy(); // verify await page.goto(`${O3_URL}`); - await homePage.viewTestResults(); + await openmrs.viewTestResults(); const testName = await page.locator('div:nth-child(2) >div> div.cds--data-table-container td:nth-child(1)').first(); await expect(testName).toContainText('Hepatitis C test - qualitative'); @@ -147,26 +134,22 @@ test('Published coded lab results from SENAITE are viewable in the OpenMRS lab r test('Published numeric lab results from SENAITE are viewable in the OpenMRS lab results viewer.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.goToLabOrderForm(); + await openmrs.goToLabOrderForm(); await page.getByRole('button', { name: 'Add', exact: true }).click(); await page.locator('#tab select').selectOption('655AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); - await homePage.saveLabOrder(); - await homePage.goToSENAITE(); + await openmrs.saveLabOrder(); + await senaite.open(); await expect(page).toHaveURL(/.*senaite/); - await homePage.searchClientInSENAITE(); - await homePage.createPartition(); + await senaite.searchClient(); + await senaite.createPartition(); await page.locator('tr:nth-child(1) td.contentcell.Result div span input').fill('64'); - await homePage.publishLabResults(); + await senaite.publishLabResults(); const reviewState = await page.locator('table tbody tr.contentrow.state-published.parent td.contentcell.State span span').textContent(); await expect(reviewState?.includes('Published')).toBeTruthy(); // verify await page.goto(`${O3_URL}`); - await homePage.viewTestResults(); + await openmrs.viewTestResults(); const testName = await page.locator('div:nth-child(2) >div> div.cds--data-table-container td:nth-child(1)').first(); await expect(testName).toContainText('Total bilirubin'); @@ -176,26 +159,22 @@ test('Published numeric lab results from SENAITE are viewable in the OpenMRS lab test('Published free text lab results from SENAITE are viewable in the OpenMRS lab results viewer.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - await homePage.goToLabOrderForm(); + await openmrs.goToLabOrderForm(); await page.getByRole('button', { name: 'Add', exact: true }).click(); await page.locator('#tab select').selectOption('161447AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); - await homePage.saveLabOrder(); - await homePage.goToSENAITE(); + await openmrs.saveLabOrder(); + await senaite.open(); await expect(page).toHaveURL(/.*senaite/); - await homePage.searchClientInSENAITE(); - await homePage.createPartition(); + await senaite.searchClient(); + await senaite.createPartition(); await page.locator('div:nth-child(4) div table tbody tr td.contentcell.Result div span input').fill('Test result: Normal'); - await homePage.publishLabResults(); + await senaite.publishLabResults(); const reviewState = await page.locator('table tbody tr.contentrow.state-published.parent td.contentcell.State span span').textContent(); await expect(reviewState?.includes('Published')).toBeTruthy(); // verify await page.goto(`${O3_URL}`); - await homePage.viewTestResults(); + await openmrs.viewTestResults(); const testName = await page.locator('div:nth-child(2) >div> div.cds--data-table-container td:nth-child(1)').first(); await expect(testName).toHaveText('Stool microscopy with concentration'); @@ -204,6 +183,6 @@ test('Published free text lab results from SENAITE are viewable in the OpenMRS l }); test.afterEach(async ({ page }) => { - await homePage.deletePatient(); + await openmrs.deletePatient(); await page.close(); }); diff --git a/e2e/tests/openmrs-superset-flows.spec.ts b/e2e/tests/openmrs-superset-flows.spec.ts index d9aebb87..06524ae8 100644 --- a/e2e/tests/openmrs-superset-flows.spec.ts +++ b/e2e/tests/openmrs-superset-flows.spec.ts @@ -1,49 +1,52 @@ import { test, expect } from '@playwright/test'; -import { HomePage } from '../utils/functions/testBase'; -import { patientName } from '../utils/functions/testBase'; +import { OpenMRS, patientName } from '../utils/functions/openmrs'; +import { Superset } from '../utils/functions/superset'; import { O3_URL, SUPERSET_URL } from '../utils/configs/globalSetup'; -let homePage: HomePage; +let openmrs: OpenMRS; +let superset: Superset; test.beforeEach(async ({ page }) => { - homePage = new HomePage(page); + openmrs = new OpenMRS(page); + superset = new Superset(page); + + await openmrs.login(); + await expect(page).toHaveURL(/.*home/); }); test('Creating an OpenMRS patient creates the patient in Superset patients table.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.goToSuperset(); + await superset.open(); await expect(page).toHaveURL(/.*superset/); - await homePage.selectDBSchema(); - await homePage.clearSQLEditor(); + await superset.selectDBSchema(); + await superset.clearSQLEditor(); let patientsCountQuery = `SELECT COUNT (*) FROM patients;` await page.getByRole('textbox').first().fill(patientsCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const initialNumberOfPatients = await page.locator('div.virtual-table-cell').textContent(); let initialPatientsCount = Number(initialNumberOfPatients); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.goto(`${O3_URL}`); - await homePage.createPatient(); - await homePage.searchOpenMRSPatientID(); + await openmrs.createPatient(); + await openmrs.searchPatientId(); const patientIdentifier = await page.locator('#demographics section p:nth-child(2)').textContent(); // verify await page.goto(`${SUPERSET_URL}/superset/sqllab`); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.getByRole('textbox').first().fill(patientsCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const updatedNumberOfPatients = await page.locator('div.virtual-table-cell').textContent(); let updatedPatientsCount = Number(updatedNumberOfPatients); await expect(updatedPatientsCount).toBe(initialPatientsCount + 1); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let patientQuery = `SELECT * FROM patients WHERE identifiers like 'OpenMRS ID: ${patientIdentifier}';`; await page.getByRole('textbox').fill(patientQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let patientGivenName = await page.getByText(`${patientName.firstName}`); let patientFamilyName = await page.getByText(`${patientName.givenName}`); let patientGender = await page.getByText('M', { exact: true }); @@ -52,44 +55,42 @@ test('Creating an OpenMRS patient creates the patient in Superset patients table await expect(patientFamilyName).toContainText(`${patientName.givenName}`); await expect(patientGender).toHaveText('M'); await page.getByRole('tab', { name: 'Results' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); }); test('Creating an OpenMRS visit creates the visit in Superset visits table.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.goToSuperset(); + await openmrs.createPatient(); + await superset.open(); await expect(page).toHaveURL(/.*superset/); - await homePage.selectDBSchema(); - await homePage.clearSQLEditor(); + await superset.selectDBSchema(); + await superset.clearSQLEditor(); let visitsCountQuery = `SELECT COUNT (*) FROM visits;` await page.getByRole('textbox').first().fill(visitsCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const initialNumberOfVisits = await page.locator('div.virtual-table-cell').textContent(); let initialVisitsCount = Number(initialNumberOfVisits); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.goto(`${O3_URL}`); - await homePage.startPatientVisit(); - const patient_uuid = await homePage.getPatientUUID(); + await openmrs.startPatientVisit(); + const patient_uuid = await openmrs.getPatientUuid(); // verify await page.goto(`${SUPERSET_URL}/superset/sqllab`); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.getByRole('textbox').first().fill(visitsCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const updatedNumberOfVisits = await page.locator('div.virtual-table-cell').textContent(); let updatedVisitsCount = Number(updatedNumberOfVisits); await expect(updatedVisitsCount).toBe(initialVisitsCount + 1); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let patientVisitQuery = `SELECT * FROM visits WHERE patient_uuid like '${patient_uuid}';`; await page.getByRole('textbox').first().fill(patientVisitQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let patientVisitType = await page.getByText('Facility Visit'); const patientGender = await page.getByText('M', {exact: true }); let patientAgeAtVisit = Number(await page.getByText('24', {exact: true }).nth(0).textContent()); @@ -98,227 +99,219 @@ test('Creating an OpenMRS visit creates the visit in Superset visits table.', as await expect(patientGender).toContainText('M'); await expect(patientAgeAtVisit).toBe(24); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); }); test('Creating an OpenMRS order creates the order in Superset orders table.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.searchOpenMRSPatientID(); + await openmrs.createPatient(); + await openmrs.searchPatientId(); const patientIdentifier = await page.locator('#demographics section p:nth-child(2)').textContent(); - await homePage.startPatientVisit(); - await homePage.goToSuperset(); + await openmrs.startPatientVisit(); + await superset.open(); await expect(page).toHaveURL(/.*superset/); - await homePage.selectDBSchema(); - await homePage.clearSQLEditor(); + await superset.selectDBSchema(); + await superset.clearSQLEditor(); let ordersCountQuery = `SELECT COUNT(*) FROM orders;` await page.getByRole('textbox').first().fill(ordersCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const initialNumberOfOrders = await page.locator('div.virtual-table-cell').textContent(); let initialOrdersCount = Number(initialNumberOfOrders); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.goto(`${O3_URL}`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.goToLabOrderForm(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.goToLabOrderForm(); await page.getByRole('button', { name: 'Add', exact: true }).click(); await page.locator('#tab select').selectOption('857AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); - await homePage.saveLabOrder(); + await openmrs.saveLabOrder(); // verify await page.goto(`${SUPERSET_URL}/superset/sqllab`); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.getByRole('textbox').first().fill(ordersCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const updatedNumberOfOrders = await page.locator('div.virtual-table-cell').textContent(); let updatedOrdersCount = Number(updatedNumberOfOrders); await expect(updatedOrdersCount).toBe(initialOrdersCount + 1); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let patientIdQuery = `SELECT patient_id FROM patients WHERE identifiers like 'OpenMRS ID: ${patientIdentifier}';`; await page.getByRole('textbox').fill(patientIdQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let patientId = await page.locator('div.virtual-table-cell').textContent(); const patientIdValue = Number(patientId); await page.getByRole('tab', { name: 'Results' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let orderQuery = `SELECT * FROM orders WHERE patient_id=${patientIdValue};`; await page.getByRole('textbox').first().fill(orderQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let orderTypeName = await page.getByText('Test Order' ); let encounterTypeName = await page.getByText('Consultation', { exact: true }); await expect(orderTypeName).toContainText('Test Order'); await expect(encounterTypeName).toContainText('Consultation'); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); }); test('Creating an OpenMRS encounter creates the encounter in Superset encounters table.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.searchOpenMRSPatientID(); + await openmrs.createPatient(); + await openmrs.searchPatientId(); const patientIdentifier = await page.locator('#demographics section p:nth-child(2)').textContent(); - await homePage.startPatientVisit(); - await homePage.goToSuperset(); + await openmrs.startPatientVisit(); + await superset.open(); await expect(page).toHaveURL(/.*superset/); - await homePage.selectDBSchema(); - await homePage.clearSQLEditor(); + await superset.selectDBSchema(); + await superset.clearSQLEditor(); let encountersCountQuery = `SELECT COUNT(*) FROM encounters;` await page.getByRole('textbox').first().fill(encountersCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const initialNumberOfEncounters = await page.locator('div.virtual-table-cell').textContent(); let initialEncountersCount = Number(initialNumberOfEncounters); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.goto(`${O3_URL}`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.goToLabOrderForm(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.goToLabOrderForm(); await page.getByRole('button', { name: 'Add', exact: true }).click(); await page.locator('#tab select').selectOption('857AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); - await homePage.saveLabOrder(); + await openmrs.saveLabOrder(); // verify await page.goto(`${SUPERSET_URL}/superset/sqllab`); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.getByRole('textbox').first().fill(encountersCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const updatedNumberOfEncounters = await page.locator('div.virtual-table-cell').textContent(); let updatedEncountersCount = Number(updatedNumberOfEncounters); await expect(updatedEncountersCount).toBe(initialEncountersCount + 1); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let patientIdQuery = `SELECT patient_id FROM patients WHERE identifiers like 'OpenMRS ID: ${patientIdentifier}';`; await page.getByRole('textbox').fill(patientIdQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let patientId = await page.locator('div.virtual-table-cell').textContent(); const patientIdValue = Number(patientId); await page.getByRole('tab', { name: 'Results' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let encounterIdQuery = `SELECT encounter_id FROM orders WHERE patient_id=${patientIdValue};`; await page.getByRole('textbox').first().fill(encounterIdQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let encounterId = await page.locator('div.virtual-table-cell').textContent(); const encounterIdValue = Number(encounterId); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let encounterTypeUuidQuery = `SELECT encounter_type_uuid FROM orders WHERE patient_id=${patientIdValue};`; await page.getByRole('textbox').fill(encounterTypeUuidQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let encounterTypeUuidValue = await page.locator('div.virtual-table-cell').textContent(); await page.getByRole('tab', { name: 'Results' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let encounterQuery = `SELECT * FROM encounters WHERE encounter_id=${encounterIdValue} AND encounter_type_uuid like '${encounterTypeUuidValue}';`; await page.getByRole('textbox').first().fill(encounterQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let encounterTypeName = await page.getByText('Consultation', { exact: true }); let visitTypeName = await page.getByText('Facility Visit'); await expect(encounterTypeName).toContainText('Consultation'); await expect(visitTypeName).toContainText('Facility Visit'); await page.getByRole('tab', { name: 'Results' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); }); test('Creating an OpenMRS condition creates the condition in Superset conditions table.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.searchOpenMRSPatientID(); + await openmrs.createPatient(); + await openmrs.searchPatientId(); const patientIdentifier = await page.locator('#demographics section p:nth-child(2)').textContent(); - await homePage.startPatientVisit(); - await homePage.goToSuperset(); + await openmrs.startPatientVisit(); + await superset.open(); await expect(page).toHaveURL(/.*superset/); - await homePage.selectDBSchema(); - await homePage.clearSQLEditor(); + await superset.selectDBSchema(); + await superset.clearSQLEditor(); let conditionsCountQuery = `SELECT COUNT (*) FROM conditions;` await page.getByRole('textbox').first().fill(conditionsCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const initialNumberOfConditions = await page.locator('div.virtual-table-cell').textContent(); let initialConditionsCount = Number(initialNumberOfConditions); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.goto(`${O3_URL}`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.addPatientCondition(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.addPatientCondition(); // verify await page.goto(`${SUPERSET_URL}/superset/sqllab`); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.getByRole('textbox').first().fill(conditionsCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const updatedNumberOfConditions = await page.locator('div.virtual-table-cell').textContent(); let updatedConditionsCount = Number(updatedNumberOfConditions); await expect(updatedConditionsCount).toBe(initialConditionsCount + 1); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let patientIdQuery = `SELECT patient_id FROM patients WHERE identifiers like 'OpenMRS ID: ${patientIdentifier}';`; await page.getByRole('textbox').fill(patientIdQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let patientId = await page.locator('div.virtual-table-cell').textContent(); const patientIdValue = Number(patientId); await page.getByRole('tab', { name: 'Results' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let conditionQuery = `SELECT * FROM conditions WHERE patient_id=${patientIdValue};`; await page.getByRole('textbox').first().fill(conditionQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let clinicalStatus = await page.getByText('ACTIVE'); let onSetDate = await page.getByText('2023-07-27'); await expect(clinicalStatus).toContainText('ACTIVE'); await expect(onSetDate).toContainText('2023-07-27T00:00:00'); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); }); test('Creating an OpenMRS obs creates the observation in Superset observations table.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - const patient_uuid = await homePage.getPatientUUID(); - await homePage.goToSuperset(); + await openmrs.createPatient(); + await openmrs.startPatientVisit(); + const patient_uuid = await openmrs.getPatientUuid(); + await superset.open(); await expect(page).toHaveURL(/.*superset/); - await homePage.selectDBSchema(); - await homePage.clearSQLEditor(); + await superset.selectDBSchema(); + await superset.clearSQLEditor(); let observationsCountQuery = `SELECT COUNT (*) FROM observations;` await page.getByRole('textbox').first().fill(observationsCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const initialNumberOfObservations = await page.locator('div.virtual-table-cell').textContent(); let initialObservationsCount = Number(initialNumberOfObservations); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.goto(`${O3_URL}`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.addPatientBiometrics(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.addPatientBiometrics(); // verify await page.goto(`${SUPERSET_URL}/superset/sqllab`); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.getByRole('textbox').first().fill(observationsCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const updatedNumberOfObservations = await page.locator('div.virtual-table-cell').textContent(); let updatedObservationsCount = Number(updatedNumberOfObservations); await expect(updatedObservationsCount).toBe(initialObservationsCount + 3); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let observationsQuery = `SELECT * FROM observations WHERE patient_uuid like '${patient_uuid}';`; await page.getByRole('textbox').fill(observationsQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let firstConceptName = await page.getByText('Circonférence du haut du bras').first(); let secondConceptName = await page.getByText('Taille (cm)').first(); let thirdConceptName = await page.getByText('Weight (kg)').first(); @@ -336,76 +329,72 @@ test('Creating an OpenMRS obs creates the observation in Superset observations t await expect(patientHeight).toBe(165); await expect(patientMidUpperArmCircumference).toBe(34); await page.getByRole('tab', { name: 'Results' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); }); test('Creating an OpenMRS appointment creates the appointment in Superset appointments table.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.searchOpenMRSPatientID(); + await openmrs.createPatient(); + await openmrs.searchPatientId(); const patientIdentifier = await page.locator('#demographics section p:nth-child(2)').textContent(); - await homePage.startPatientVisit(); - await homePage.goToSuperset(); + await openmrs.startPatientVisit(); + await superset.open(); await expect(page).toHaveURL(/.*superset/); - await homePage.selectDBSchema(); - await homePage.clearSQLEditor(); + await superset.selectDBSchema(); + await superset.clearSQLEditor(); let appointmentsCountQuery = `SELECT COUNT(*) FROM appointments;` await page.getByRole('textbox').first().fill(appointmentsCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const initialNumberOfAppointments = await page.locator('div.virtual-table-cell').textContent(); let initialAppointmentsCount = Number(initialNumberOfAppointments); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.goto(`${O3_URL}`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.addPatientAppointment(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.addPatientAppointment(); // verify await page.goto(`${SUPERSET_URL}/superset/sqllab`); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.getByRole('textbox').first().fill(appointmentsCountQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); const updatedNumberOfAppointments = await page.locator('div.virtual-table-cell').textContent(); let updatedAppointmentsCount = Number(updatedNumberOfAppointments); await expect(updatedAppointmentsCount).toBe(initialAppointmentsCount + 1); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let patientIdQuery = `SELECT patient_id FROM patients WHERE identifiers like 'OpenMRS ID: ${patientIdentifier}';`; await page.getByRole('textbox').fill(patientIdQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let patientId = await page.locator('div.virtual-table-cell').textContent(); const patientIdValue = Number(patientId); await page.getByRole('tab', { name: 'Results' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); let appointmentQuery = `SELECT * FROM appointments WHERE patient_id=${patientIdValue};`; await page.getByRole('textbox').first().fill(appointmentQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let appointmentStatus = await page.getByText('Scheduled').first(); await expect(appointmentStatus).toContainText('Scheduled'); await page.getByRole('tab', { name: 'Query history' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); }); test('Voiding an OpenMRS obs updates the observation in Superset observations table.', async ({ page }) => { // replay - await homePage.initiateLogin(); - await expect(page).toHaveURL(/.*home/); - await homePage.createPatient(); - await homePage.startPatientVisit(); - const patient_uuid = await homePage.getPatientUUID(); - await homePage.addPatientBiometrics(); - await homePage.goToSuperset(); + await openmrs.createPatient(); + await openmrs.startPatientVisit(); + const patient_uuid = await openmrs.getPatientUuid(); + await openmrs.addPatientBiometrics(); + await superset.open(); await expect(page).toHaveURL(/.*superset/); - await homePage.selectDBSchema(); - await homePage.clearSQLEditor(); + await superset.selectDBSchema(); + await superset.clearSQLEditor(); let obsVoidedQuery = `SELECT obs_voided FROM Observations WHERE patient_uuid like '${patient_uuid}';`; await page.getByRole('textbox').first().fill(obsVoidedQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); let firstObsVoidedState = await page.locator('div.virtual-table-cell:nth-child(1)'); let secondObsVoidedState = await page.locator('div.virtual-table-cell:nth-child(2)'); let thirdObsVoidedState = await page.locator('div.virtual-table-cell:nth-child(3)'); @@ -415,24 +404,24 @@ test('Voiding an OpenMRS obs updates the observation in Superset observations ta await expect(thirdObsVoidedState).toContainText('false'); await page.goto(`${O3_URL}/openmrs/spa/home`); - await homePage.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); - await homePage.voidEncounter(); + await openmrs.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); + await openmrs.voidEncounter(); // verify await page.goto(`${SUPERSET_URL}/superset/sqllab`); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); await page.getByRole('textbox').first().fill(obsVoidedQuery); - await homePage.runSQLQuery(); + await superset.runSQLQuery(); await expect(firstObsVoidedState).toContainText('true'); await expect(secondObsVoidedState).toContainText('true'); await expect(thirdObsVoidedState).toContainText('true'); await page.getByRole('tab', { name: 'Results' }).click(); - await homePage.clearSQLEditor(); + await superset.clearSQLEditor(); }); test.afterEach(async ({ page }) => { - await homePage.deletePatient(); + await openmrs.deletePatient(); await page.close(); }); diff --git a/e2e/utils/functions/keycloak.ts b/e2e/utils/functions/keycloak.ts new file mode 100644 index 00000000..28825a68 --- /dev/null +++ b/e2e/utils/functions/keycloak.ts @@ -0,0 +1,62 @@ +import { Page, expect } from '@playwright/test'; +import { randomOpenMRSRoleName } from '../functions/openmrs'; +import { randomSupersetRoleName } from '../functions/superset'; +import { KEYCLOAK_URL } from '../configs/globalSetup'; +import { delay } from './openmrs'; + +export var randomKeycloakRoleName = { + roleName : `Aa${(Math.random() + 1).toString(36).substring(2)}` +} + +export class Keycloak { + constructor(readonly page: Page) {} + + async open() { + await this.page.goto(`${KEYCLOAK_URL}/admin/master/console`); + await this.page.getByLabel('Username or email').fill(`${process.env.KEYCLOAK_USERNAME}`); + await this.page.getByLabel('Password').fill(`${process.env.KEYCLOAK_PASSWORD}`); + await this.page.getByRole('button', { name: 'Sign In' }).click(); + await delay(8000); + } + + async createRole() { + await this.page.getByTestId('create-role').click(); + await this.page.getByLabel('Role name').fill(`${randomKeycloakRoleName.roleName}`); + await this.page.getByLabel('Description').fill('This is Keycloak test role'); + await this.page.getByTestId('save').click(); + await expect(this.page.getByText('Role created')).toBeVisible(); + await delay(2000); + } + + async goToClients() { + await this.page.getByTestId('realmSelectorToggle').click(); + await this.page.getByRole('menuitem', { name: 'ozone' }).click(); + await this.page.getByRole('link', { name: 'Clients' }).click(); + await delay(2000); + } + + async selectOpenMRSId() { + await this.page.getByRole('link', { name: 'openmrs', exact: true }).click(); + await this.page.getByTestId('rolesTab').click(); + } + + async goToClientAttributes() { + await this.page.getByRole('link', { name: `${randomOpenMRSRoleName.roleName}` }).click(); + await this.page.getByTestId('attributesTab').click(); + } + + async selectSupersetId() { + if (await this.page. getByRole('link', { name: 'superset', exact: true }).isHidden()) { + await this.page.getByLabel('Pagination top').getByLabel('Go to next page').click(); + } + await this.page.getByRole('link', { name: 'superset', exact: true }).click(); + await this.page.getByTestId('rolesTab').click(); + } + + async deleteSyncedRole() { + await this.page.getByRole('row', { name: `${randomSupersetRoleName.roleName}` }).getByLabel('Actions').click(); + await this.page.getByRole('menuitem', { name: 'Delete' }).click(); + await this.page.getByTestId('confirm').click(); + await expect(this.page.getByText(`The role has been deleted`)).toBeVisible(); + } +} diff --git a/e2e/utils/functions/odoo.ts b/e2e/utils/functions/odoo.ts new file mode 100644 index 00000000..27dddb2a --- /dev/null +++ b/e2e/utils/functions/odoo.ts @@ -0,0 +1,31 @@ +import { Page } from '@playwright/test'; +import { patientName } from '../functions/openmrs'; +import { ODOO_URL } from '../configs/globalSetup'; +import { delay } from './openmrs'; + +export class Odoo { + constructor(readonly page: Page) {} + + async open() { + await this.page.goto(`${ODOO_URL}`); + if (`${process.env.TEST_PRO}` == 'true') { + await this.page.getByRole('link', { name: 'Login with Single Sign-On' }).click(); + } else { + await delay(3000); + await this.page.locator('#login').fill(`${process.env.ODOO_USERNAME_ON_FOSS}`); + await delay(1000); + await this.page.locator('#password').fill(`${process.env.ODOO_PASSWORD_ON_FOSS}`); + await delay(1000); + await this.page.locator('button[type="submit"]').click(); + } + } + + async searchCustomer() { + await this.page.locator("//a[contains(@class, 'full')]").click(); + await this.page.getByRole('menuitem', { name: 'Sales' }).click(); + await delay(1500); + await this.page.getByPlaceholder('Search...').type(`${patientName.firstName + ' ' + patientName.givenName}`); + await this.page.getByPlaceholder('Search...').press('Enter'); + await delay(2000); + } +} diff --git a/e2e/utils/functions/testBase.ts b/e2e/utils/functions/openmrs.ts similarity index 68% rename from e2e/utils/functions/testBase.ts rename to e2e/utils/functions/openmrs.ts index c45751f7..6f90019d 100644 --- a/e2e/utils/functions/testBase.ts +++ b/e2e/utils/functions/openmrs.ts @@ -1,12 +1,5 @@ import { Page, expect } from '@playwright/test'; -import { - O3_URL, - ODOO_URL, - SENAITE_URL, - KEYCLOAK_URL, - SUPERSET_URL -} - from '../configs/globalSetup'; +import { O3_URL } from '../configs/globalSetup'; export var patientName = { firstName : '', @@ -16,19 +9,10 @@ export var patientName = { var patientFullName = ''; -export var randomSupersetRoleName = { - roleName : `Ac${(Math.random() + 1).toString(36).substring(2)}`, - updatedRoleName : `Ab${(Math.random() + 1).toString(36).substring(2)}` -} - export var randomOpenMRSRoleName = { roleName : `Ab${(Math.random() + 1).toString(36).substring(2)}` } -export var randomKeycloakRoleName = { - roleName : `Aa${(Math.random() + 1).toString(36).substring(2)}` -} - export const delay = (mills) => { let datetime1 = new Date().getTime(); let datetime2 = datetime1 + mills; @@ -36,14 +20,13 @@ export const delay = (mills) => { datetime1 = new Date().getTime(); } } - -export class HomePage { +export class OpenMRS { constructor(readonly page: Page) {} readonly patientSearchIcon = () => this.page.locator('[data-testid="searchPatientIcon"]'); readonly patientSearchBar = () => this.page.locator('[data-testid="patientSearchBar"]'); - async initiateLogin() { + async login() { await this.page.goto(`${O3_URL}`); if (`${process.env.TEST_PRO}` == 'true') { await this.page.locator('#username').fill(`${process.env.OZONE_USERNAME}`); @@ -64,44 +47,6 @@ export class HomePage { await this.expectAllButtonsToBePresent(); } - async goToSuperset() { - await this.page.goto(`${SUPERSET_URL}`); - } - - async goToKeycloak() { - await this.page.goto(`${KEYCLOAK_URL}/admin/master/console`); - await this.page.getByLabel('Username or email').fill(`${process.env.KEYCLOAK_USERNAME}`); - await this.page.getByLabel('Password').fill(`${process.env.KEYCLOAK_PASSWORD}`); - await this.page.getByRole('button', { name: 'Sign In' }).click(); - await delay(8000); - } - - async goToOdoo() { - await this.page.goto(`${ODOO_URL}`); - if (`${process.env.TEST_PRO}` == 'true') { - await this.page.getByRole('link', { name: 'Login with Single Sign-On' }).click(); - } else { - await delay(3000); - await this.page.locator('#login').fill(`${process.env.ODOO_USERNAME_ON_FOSS}`); - await delay(1000); - await this.page.locator('#password').fill(`${process.env.ODOO_PASSWORD_ON_FOSS}`); - await delay(1000); - await this.page.locator('button[type="submit"]').click(); - } - } - - async goToSENAITE() { - await this.page.goto(`${SENAITE_URL}`); - if (!(`${process.env.TEST_PRO}` == 'true')) { - await delay(3000); - await this.page.locator('#__ac_name').fill(`${process.env.SENAITE_USERNAME_ON_FOSS}`); - await delay(1000); - await this.page.locator('#__ac_password').fill(`${process.env.SENAITE_PASSWORD_ON_FOSS}`); - await delay(1000); - await this.page.locator('#buttons-login').click(); - } - } - async createPatient() { patientName = { firstName : `e2e_test_${Math.floor(Math.random() * 10000)}`, @@ -148,7 +93,7 @@ export class HomePage { await this.page.getByRole('link', { name: `${patientFullName}` }).first().click(); } - async searchOpenMRSPatientID() { + async searchPatientId() { await this.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); await expect(this.page.getByText('Actions', {exact: true})).toBeVisible(); await this.page.getByRole('button', { name: 'Actions', exact: true }).click(); @@ -159,7 +104,7 @@ export class HomePage { await expect(this.page.getByText('OpenMRS ID', {exact: true})).toBeVisible(); } - async extractUUIDFromURL(url) { + async extractUuidFromURL(url) { // Regular expression to match UUID in URL var regex = /\/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\//; @@ -173,13 +118,13 @@ export class HomePage { } } - async getPatientUUID() { + async getPatientUuid() { await this.page.goto(`${O3_URL}/openmrs/spa/home`); await this.patientSearchIcon().click(); await this.patientSearchBar().type(`${patientName.firstName + ' ' + patientName.givenName}`); await this.page.getByRole('link', { name: `${patientFullName}` }).first().click(); let url = await this.page.url(); - return this.extractUUIDFromURL(url); + return this.extractUuidFromURL(url); } async startPatientVisit() { @@ -256,24 +201,6 @@ export class HomePage { await expect(appointmentStatus).toHaveText('Scheduled'); } - async selectDBSchema() { - await this.page.getByRole('button', { name: 'triangle-down SQL', exact: true }).click(); - await this.page.getByRole('link', { name: 'SQL Lab', exact: true }).click(); - await this.page.getByTitle('public').getByText('public').click(); - await delay(4000); - } - - async clearSQLEditor() { - await this.page.getByRole('textbox').first().clear(); - await this.page.getByRole('textbox').first().fill(''); - await delay(3000); - } - - async runSQLQuery() { - await this.page.getByRole('button', { name: 'Run' }).click(); - await delay(5000); - } - async goToLabOrderForm() { await this.page.getByLabel('Clinical forms').click(); await delay(3000); @@ -310,37 +237,13 @@ export class HomePage { await delay(5000); } - async createPartition() { - await this.page.locator('table tbody tr:nth-child(1) td.contentcell.title div').click(); - await this.page.locator('input[type=checkbox]').first().click(); - await this.page.locator('#receive_transition span:nth-child(1)').click(); - await this.page.getByRole('button', { name: 'Create Partitions' }).click(); - await this.page.locator('table tbody tr:nth-child(1) td.contentcell.getId div span a').click(); - await delay(3000); - } - - async publishLabResults() { - await this.page.locator('#ajax_save_selection').click(); - await this.page.getByRole('button', { name: 'Submit' }).click(); - await this.page.locator('input[name="uids\\:list"]').first().check(); - await this.page.getByRole('button', { name: 'Verify' }).click(); - await this.page.getByRole('navigation', { name: 'breadcrumb' }).getByRole('link', { name: `${patientName.firstName + ' ' + patientName.givenName}` }).click(); - await this.page.locator('input[name="uids\\:list"]').check(); - await this.page.locator('#publish_transition span:nth-child(1)').click(); - await delay(5000); - await this.page.getByRole('button', { name: 'Email' }).click(); - await delay(5000); - await this.page.getByRole('button', { name: 'Send' }).click(); - await delay(8000); - } - async viewTestResults() { await this.searchPatient(`${patientName.firstName + ' ' + patientName.givenName}`); await this.page.getByRole('link', { name: 'Results Viewer' }).click(); await this.page.getByRole('tab', { name: 'Panel' }).click(); } - async makeDrugOrder() { + async createDrugOrder() { await this.page.getByLabel('Order basket', { exact: true }).click(); await delay(3000); await this.page.getByRole('button', { name: 'Add', exact: true }).nth(0).click(); @@ -367,7 +270,7 @@ export class HomePage { await delay(5000); } - async prescribeFreeTextMedicationDosage() { + async createDrugOrderWithFreeTextDosage() { await this.page.getByLabel('Order basket', { exact: true }).click(); await delay(3000); await this.page.getByRole('button', { name: 'Add', exact: true }).nth(0).click(); @@ -417,22 +320,6 @@ export class HomePage { await delay(3000); } - async searchCustomerInOdoo() { - await this.page.locator("//a[contains(@class, 'full')]").click(); - await this.page.getByRole('menuitem', { name: 'Sales' }).click(); - await delay(1500); - await this.page.getByPlaceholder('Search...').type(`${patientName.firstName + ' ' + patientName.givenName}`); - await this.page.getByPlaceholder('Search...').press('Enter'); - await delay(2000); - } - - async searchClientInSENAITE() { - await this.page.getByRole('link', { name: 'Clients', exact: true }).click(); - await this.page.getByRole('textbox', { name: 'Search' }).type(`${patientName.givenName}`); - await this.page.locator('div.col-sm-3.text-right button:nth-child(2) i').click(); - await delay(2000); - } - async updatePatientDetails() { await this.page.getByRole('button', { name: 'Actions', exact: true }).click(); await this.page.getByRole('menuitem', { name: 'Edit patient details' }).click(); @@ -449,7 +336,7 @@ export class HomePage { await delay(5000); } - async addOpenMRSRole() { + async addRole() { await this.page.getByRole('link', { name: 'Add Role' }).click(); await this.page.locator('#role').fill(`${randomOpenMRSRoleName.roleName}`); await this.page.locator('textarea[name="description"]').fill('Role for e2e test'); @@ -462,7 +349,7 @@ export class HomePage { await expect(this.page.getByText('Role saved')).toBeVisible(); } - async updateOpenMRSRole() { + async updateRole() { await this.page.getByRole('link', { name: `${randomOpenMRSRoleName.roleName}` }).click(); await this.page.locator('textarea[name="description"]').clear(); await this.page.locator('textarea[name="description"]').fill('Updated role description'); @@ -472,105 +359,7 @@ export class HomePage { await expect(this.page.getByText('Role saved')).toBeVisible(); } - async addSupersetRole() { - await this.page.getByRole('button', { name: 'triangle-down Settings' }).click(); - await expect(this.page.getByText('List Roles')).toBeVisible(); - await this.page.getByRole('link', { name: 'List Roles' }).click(); - await this.page.getByRole('link', { name: 'Add' }).click(); - await this.page.getByPlaceholder('Name').clear(); - await this.page.getByPlaceholder('Name').fill(`${randomSupersetRoleName.roleName}`); - await this.page.getByPlaceholder('Select Value').click(); - await this.page.getByRole('option', { name: 'can read on SavedQuery' }).click(); - await this.page.getByRole('searchbox').click(); - await this.page.getByRole('option', { name: 'can read on Database' }).click(); - await this.page.getByRole('searchbox').click(); - await this.page.getByRole('option', { name: 'can write on Database' }).click(); - await this.page.getByRole('searchbox').click(); - await this.page.getByRole('option', { name: 'can read on Query' }).click(); - await this.page.locator('button[type="submit"]').click(); - await delay(2000); - await expect(this.page.getByText('Added Row')).toBeVisible(); - await expect(this.page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible(); - await delay(30000) - } - - async updateSupersetRole() { - await this.page.goto(`${SUPERSET_URL}/roles/list/`); - await this.page.getByRole('row', { name: `${randomSupersetRoleName.roleName}` }).getByRole('link').nth(1).click(); - await delay(2000); - await this.page.getByPlaceholder('Name').clear(); - await this.page.getByPlaceholder('Name').fill(`${randomSupersetRoleName.updatedRoleName}`); - await this.page.locator('button[type="submit"]').click(); - await delay(2000); - await expect(this.page.getByText('Changed Row')).toBeVisible(); - await expect(this.page.getByText(`${randomSupersetRoleName.updatedRoleName}`)).toBeVisible(); - await delay(30000); - } - - async deleteSupersetRole(){ - await this.page.goto(`${SUPERSET_URL}/roles/list`); - await this.page.getByRole('row', { name: `${randomSupersetRoleName.roleName}` }).getByRole('checkbox').check(); - await this.page.getByRole('row', { name: `${randomSupersetRoleName.roleName}` }).getByRole('link').nth(2).click(); - await delay(2000); - await this.page.getByRole('link', { name: 'OK' }).click(); - await delay(2500); - await expect(this.page.getByText(`Deleted Row`)).toBeVisible(); - await expect(this.page.getByText(`${randomSupersetRoleName.roleName}`)).not.toBeVisible(); - } - - async deleteUpdatedSupersetRole(){ - await this.page.goto(`${SUPERSET_URL}/roles/list`); - await this.page.getByRole('row', { name: `${randomSupersetRoleName.updatedRoleName}` }).getByRole('checkbox').check(); - await this.page.getByRole('row', { name: `${randomSupersetRoleName.updatedRoleName}` }).getByRole('link').nth(2).click(); - await delay(2000); - await this.page.getByRole('link', { name: 'OK' }).click(); - await delay(2500); - await expect(this.page.getByText(`Deleted Row`)).toBeVisible(); - await expect(this.page.getByText(`${randomSupersetRoleName.updatedRoleName}`)).not.toBeVisible(); - } - - async deleteSyncedSupersetRoleInKeycloak() { - await this.page.getByRole('row', { name: `${randomSupersetRoleName.roleName}` }).getByLabel('Actions').click(); - await this.page.getByRole('menuitem', { name: 'Delete' }).click(); - await this.page.getByTestId('confirm').click(); - await expect(this.page.getByText(`The role has been deleted`)).toBeVisible(); - } - - async goToClients() { - await this.page.getByTestId('realmSelectorToggle').click(); - await this.page.getByRole('menuitem', { name: 'ozone' }).click(); - await this.page.getByRole('link', { name: 'Clients' }).click(); - await delay(2000); - } - - async selectOpenMRSId() { - await this.page.getByRole('link', { name: 'openmrs', exact: true }).click(); - await this.page.getByTestId('rolesTab').click(); - } - - async goToClientAttributes() { - await this.page.getByRole('link', { name: `${randomOpenMRSRoleName.roleName}` }).click(); - await this.page.getByTestId('attributesTab').click(); - } - - async selectSupersetId() { - if (await this.page. getByRole('link', { name: 'superset', exact: true }).isHidden()) { - await this.page.getByLabel('Pagination top').getByLabel('Go to next page').click(); - } - await this.page.getByRole('link', { name: 'superset', exact: true }).click(); - await this.page.getByTestId('rolesTab').click(); - } - - async createRoleInKeycloak() { - await this.page.getByTestId('create-role').click(); - await this.page.getByLabel('Role name').fill(`${randomKeycloakRoleName.roleName}`); - await this.page.getByLabel('Description').fill('This is Keycloak test role'); - await this.page.getByTestId('save').click(); - await expect(this.page.getByText('Role created')).toBeVisible(); - await delay(2000); - } - - async unlinkInheritedOpenMRSRoles() { + async unlinkInheritedRoles() { await this.page.getByRole('link', { name: `${randomOpenMRSRoleName.roleName}` }).click(); await this.page.getByLabel('Application: Edits Existing Encounters').uncheck(); await this.page.getByLabel('Application: Enters Vitals').uncheck(); @@ -582,7 +371,7 @@ export class HomePage { await delay(2000); } - async unlinkUpdatedOpenMRSInheritedRoles() { + async unlinkUpdatedInheritedRoles() { await this.page.getByRole('link', { name: `${randomOpenMRSRoleName.roleName}` }).click(); await this.page.getByLabel('Application: Edits Existing Encounters').uncheck(); await this.page.getByLabel('Application: Enters Vitals').uncheck(); @@ -595,9 +384,9 @@ export class HomePage { await expect(this.page.getByText('Role saved')).toBeVisible(); } - async deleteOpenMRSRole() { + async deleteRole() { await this.page.goto(`${O3_URL}/openmrs/admin/users/role.list`); - await this.unlinkInheritedOpenMRSRoles(); + await this.unlinkInheritedRoles(); await this.page.getByRole('row', { name: `${randomOpenMRSRoleName.roleName}` }).getByRole('checkbox').check(); await this.page.getByRole('button', { name: 'Delete Selected Roles' }).click(); await expect(this.page.getByText(`${randomOpenMRSRoleName.roleName} deleted`)).toBeVisible(); diff --git a/e2e/utils/functions/senaite.ts b/e2e/utils/functions/senaite.ts new file mode 100644 index 00000000..d654ba60 --- /dev/null +++ b/e2e/utils/functions/senaite.ts @@ -0,0 +1,51 @@ +import { Page } from '@playwright/test'; +import { patientName } from '../functions/openmrs'; +import { SENAITE_URL } from '../configs/globalSetup'; +import { delay } from './openmrs'; + +export class SENAITE { + constructor(readonly page: Page) {} + + async open() { + await this.page.goto(`${SENAITE_URL}`); + if (!(`${process.env.TEST_PRO}` == 'true')) { + await delay(3000); + await this.page.locator('#__ac_name').fill(`${process.env.SENAITE_USERNAME_ON_FOSS}`); + await delay(1000); + await this.page.locator('#__ac_password').fill(`${process.env.SENAITE_PASSWORD_ON_FOSS}`); + await delay(1000); + await this.page.locator('#buttons-login').click(); + } + } + + async searchClient() { + await this.page.getByRole('link', { name: 'Clients', exact: true }).click(); + await this.page.getByRole('textbox', { name: 'Search' }).type(`${patientName.givenName}`); + await this.page.locator('div.col-sm-3.text-right button:nth-child(2) i').click(); + await delay(2000); + } + + async createPartition() { + await this.page.locator('table tbody tr:nth-child(1) td.contentcell.title div').click(); + await this.page.locator('input[type=checkbox]').first().click(); + await this.page.locator('#receive_transition span:nth-child(1)').click(); + await this.page.getByRole('button', { name: 'Create Partitions' }).click(); + await this.page.locator('table tbody tr:nth-child(1) td.contentcell.getId div span a').click(); + await delay(3000); + } + + async publishLabResults() { + await this.page.locator('#ajax_save_selection').click(); + await this.page.getByRole('button', { name: 'Submit' }).click(); + await this.page.locator('input[name="uids\\:list"]').first().check(); + await this.page.getByRole('button', { name: 'Verify' }).click(); + await this.page.getByRole('navigation', { name: 'breadcrumb' }).getByRole('link', { name: `${patientName.firstName + ' ' + patientName.givenName}` }).click(); + await this.page.locator('input[name="uids\\:list"]').check(); + await this.page.locator('#publish_transition span:nth-child(1)').click(); + await delay(5000); + await this.page.getByRole('button', { name: 'Email' }).click(); + await delay(5000); + await this.page.getByRole('button', { name: 'Send' }).click(); + await delay(8000); + } +} diff --git a/e2e/utils/functions/superset.ts b/e2e/utils/functions/superset.ts new file mode 100644 index 00000000..ae4c9f72 --- /dev/null +++ b/e2e/utils/functions/superset.ts @@ -0,0 +1,91 @@ +import { Page, expect } from '@playwright/test'; +import { SUPERSET_URL } from '../configs/globalSetup'; +import { delay } from './openmrs'; + +export var randomSupersetRoleName = { + roleName : `Ac${(Math.random() + 1).toString(36).substring(2)}`, + updatedRoleName : `Ab${(Math.random() + 1).toString(36).substring(2)}` +} + +export class Superset { + constructor(readonly page: Page) {} + + async open() { + await this.page.goto(`${SUPERSET_URL}`); + } + + async selectDBSchema() { + await this.page.getByRole('button', { name: 'triangle-down SQL', exact: true }).click(); + await this.page.getByRole('link', { name: 'SQL Lab', exact: true }).click(); + await this.page.getByTitle('public').getByText('public').click(); + await delay(4000); + } + + async clearSQLEditor() { + await this.page.getByRole('textbox').first().clear(); + await this.page.getByRole('textbox').first().fill(''); + await delay(3000); + } + + async runSQLQuery() { + await this.page.getByRole('button', { name: 'Run' }).click(); + await delay(5000); + } + + async addRole() { + await this.page.getByRole('button', { name: 'triangle-down Settings' }).click(); + await expect(this.page.getByText('List Roles')).toBeVisible(); + await this.page.getByRole('link', { name: 'List Roles' }).click(); + await this.page.getByRole('link', { name: 'Add' }).click(); + await this.page.getByPlaceholder('Name').clear(); + await this.page.getByPlaceholder('Name').fill(`${randomSupersetRoleName.roleName}`); + await this.page.getByPlaceholder('Select Value').click(); + await this.page.getByRole('option', { name: 'can read on SavedQuery' }).click(); + await this.page.getByRole('searchbox').click(); + await this.page.getByRole('option', { name: 'can read on Database' }).click(); + await this.page.getByRole('searchbox').click(); + await this.page.getByRole('option', { name: 'can write on Database' }).click(); + await this.page.getByRole('searchbox').click(); + await this.page.getByRole('option', { name: 'can read on Query' }).click(); + await this.page.locator('button[type="submit"]').click(); + await delay(2000); + await expect(this.page.getByText('Added Row')).toBeVisible(); + await expect(this.page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible(); + await delay(30000) + } + + async updateRole() { + await this.page.goto(`${SUPERSET_URL}/roles/list/`); + await this.page.getByRole('row', { name: `${randomSupersetRoleName.roleName}` }).getByRole('link').nth(1).click(); + await delay(2000); + await this.page.getByPlaceholder('Name').clear(); + await this.page.getByPlaceholder('Name').fill(`${randomSupersetRoleName.updatedRoleName}`); + await this.page.locator('button[type="submit"]').click(); + await delay(2000); + await expect(this.page.getByText('Changed Row')).toBeVisible(); + await expect(this.page.getByText(`${randomSupersetRoleName.updatedRoleName}`)).toBeVisible(); + await delay(30000); + } + + async deleteRole(){ + await this.page.goto(`${SUPERSET_URL}/roles/list`); + await this.page.getByRole('row', { name: `${randomSupersetRoleName.roleName}` }).getByRole('checkbox').check(); + await this.page.getByRole('row', { name: `${randomSupersetRoleName.roleName}` }).getByRole('link').nth(2).click(); + await delay(2000); + await this.page.getByRole('link', { name: 'OK' }).click(); + await delay(2500); + await expect(this.page.getByText(`Deleted Row`)).toBeVisible(); + await expect(this.page.getByText(`${randomSupersetRoleName.roleName}`)).not.toBeVisible(); + } + + async deleteUpdatedRole(){ + await this.page.goto(`${SUPERSET_URL}/roles/list`); + await this.page.getByRole('row', { name: `${randomSupersetRoleName.updatedRoleName}` }).getByRole('checkbox').check(); + await this.page.getByRole('row', { name: `${randomSupersetRoleName.updatedRoleName}` }).getByRole('link').nth(2).click(); + await delay(2000); + await this.page.getByRole('link', { name: 'OK' }).click(); + await delay(2500); + await expect(this.page.getByText(`Deleted Row`)).toBeVisible(); + await expect(this.page.getByText(`${randomSupersetRoleName.updatedRoleName}`)).not.toBeVisible(); + } +}