diff --git a/e2e/tests/erpnext-openmrs-flows.spec.ts b/e2e/tests/erpnext-openmrs-flows.spec.ts index af0f1685..cc468459 100644 --- a/e2e/tests/erpnext-openmrs-flows.spec.ts +++ b/e2e/tests/erpnext-openmrs-flows.spec.ts @@ -5,6 +5,7 @@ import { OpenMRS, patientName } from '../utils/functions/openmrs'; let openmrs: OpenMRS; let erpnext: ERPNext; +let quotation; test.beforeEach(async ({ page }) => { openmrs = new OpenMRS(page); @@ -26,6 +27,7 @@ test('Ordering a lab test for an OpenMRS patient creates the corresponding ERPNe await erpnext.searchCustomer(); const customer = await page.locator(".bold a:nth-child(1)"); await expect(customer).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`); + quotation = null; }); test('Ordering a drug for an OpenMRS patient creates the corresponding ERPNext customer with a filled quotation.', async ({ page }) => { @@ -123,9 +125,14 @@ test('Discontinuing a synced OpenMRS drug order for an ERPNext customer with a s await erpnext.searchQuotation(); await expect(page.getByText(`${patientName.firstName + ' ' + patientName.givenName}`)).not.toBeVisible(); await expect(page.getByText('No Quotation found')).toBeVisible(); + quotation = null; }); test.afterEach(async ({ page }) => { await openmrs.deletePatient(); + if (quotation !== null) { + await erpnext.deleteQuotation(); + } + await erpnext.deleteCustomer(); await page.close(); }); diff --git a/e2e/utils/functions/erpnext.ts b/e2e/utils/functions/erpnext.ts index b421adb5..0a0799a2 100644 --- a/e2e/utils/functions/erpnext.ts +++ b/e2e/utils/functions/erpnext.ts @@ -1,4 +1,4 @@ -import { Page } from '@playwright/test'; +import { Page, expect } from '@playwright/test'; import { delay, patientName } from './openmrs'; import { ERPNEXT_URL } from '../configs/globalSetup'; @@ -28,4 +28,26 @@ export class ERPNext { await this.page.getByPlaceholder(/title/i).fill(`${patientName.givenName}`); await delay(3000); } + + async deleteQuotation() { + await this.page.goto(`${ERPNEXT_URL}/app/quotation`); + await this.searchQuotation(); + await this.page.getByRole('checkbox', { name: 'Select All' }).check(); + await delay(2500); + await this.page.getByRole('button', { name: 'Actions' }).click(); + await this.page.getByRole('link', { name: 'Delete' }).click(); + await this.page.getByRole('button', { name: 'Yes' }).click(); + await expect(this.page.getByText('No Quotation found')).toBeVisible(); + } + + async deleteCustomer() { + await this.page.goto(`${ERPNEXT_URL}/app/customer`); + await this.searchCustomer(); + await this.page.getByRole('checkbox', { name: 'Select All' }).check(); + await delay(2500); + await this.page.getByRole('button', { name: 'Actions' }).click(); + await this.page.getByRole('link', { name: 'Delete' }).click(); + await this.page.getByRole('button', { name: 'Yes' }).click(); + await expect(this.page.getByText('No Customer found')).toBeVisible(); + } } diff --git a/e2e/utils/functions/openmrs.ts b/e2e/utils/functions/openmrs.ts index e1125db3..0ca9710f 100644 --- a/e2e/utils/functions/openmrs.ts +++ b/e2e/utils/functions/openmrs.ts @@ -44,7 +44,7 @@ export class OpenMRS { await this.page.locator('label').filter({ hasText: 'Inpatient Ward' }).locator('span').first().click(); await this.page.getByRole('button', { name: 'Confirm' }).click(); await delay(5000); - await this.expectAllButtonsToBePresent(); + await this.waitHomePageToLoad(); } async createPatient() { @@ -54,7 +54,7 @@ export class OpenMRS { updatedFirstName: `${(Math.random() + 1).toString(36).substring(2)}` } patientFullName = patientName.firstName + ' ' + patientName.givenName; - await this.expectAllButtonsToBePresent(); + await this.waitHomePageToLoad(); await this.page.getByRole('button', { name: 'Add Patient' }).click(); await expect(this.page.getByRole('button', { name: 'Register Patient' })).toBeEnabled(); await this.page.getByLabel('First Name').clear(); @@ -153,7 +153,6 @@ export class OpenMRS { await this.page.getByRole('button', { name: 'Delete Patient', exact: true }).click(); const message = await this.page.locator('//*[@id="patientFormVoided"]').textContent(); await expect(message?.includes('This patient has been deleted')).toBeTruthy(); - await this.page.getByRole('link', { name: 'Log out' }).click(); } async addPatientCondition() { @@ -403,10 +402,9 @@ export class OpenMRS { await this.page.getByRole('link', { name: 'Log out' }).click(); } - async expectAllButtonsToBePresent() { + async waitHomePageToLoad() { await expect(this.page.getByRole('button', { name: 'Search Patient' })).toBeEnabled(); await expect(this.page.getByRole('button', { name: 'Add Patient' })).toBeEnabled(); - await expect(this.page.getByRole('button', { name: 'Implementer Tools' })).toBeEnabled(); await expect(this.page.getByRole('button', { name: 'My Account' })).toBeEnabled(); await expect(this.page.getByRole('button', { name: 'App Menu' })).toBeEnabled(); } diff --git a/package.json b/package.json index fed2a293..10c0aeaa 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "!playwright-report/" ], "scripts": { - "e2e-tests-pro": "npx playwright test", + "e2e-tests-pro": "npx playwright test erpnext-openmrs", "e2e-tests-foss": "npx playwright test odoo-openmrs openmrs-senaite" }, "publishConfig": {