Skip to content

Commit

Permalink
OZ-589: E2E tests should run against local instance (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaud committed Jun 6, 2024
1 parent 54944a0 commit f197b8a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ TEST_ENVIRONMENT=dev
# Set to true to test Ozone Pro, false to test Ozone FOSS.
TEST_PRO=true

# Set to true to test on localhost.
TEST_LOCALHOST=false

#
# Ozone HIS URLs for dev, qa and demo environments.
#
Expand Down Expand Up @@ -64,6 +67,10 @@ ODOO_PASSWORD_ON_FOSS=admin
SENAITE_USERNAME_ON_FOSS=admin
SENAITE_PASSWORD_ON_FOSS=password

# SUPERSET test user credentials for FOSS
SUPERSET_USERNAME_ON_FOSS=admin
SUPERSET_PASSWORD_ON_FOSS=password

# (Pro only) Ozone test user credentials
OZONE_USERNAME=jdoe
OZONE_PASSWORD=password
Expand Down
8 changes: 4 additions & 4 deletions e2e/tests/openmrs-senaite-flows.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';
import { OpenMRS, patientName } from '../utils/functions/openmrs';
import { SENAITE } from '../utils/functions/senaite';
import { O3_URL } from '../utils/configs/globalSetup';
import { O3_URL, SENAITE_URL } from '../utils/configs/globalSetup';

let openmrs: OpenMRS;
let senaite: SENAITE;
Expand Down Expand Up @@ -47,7 +47,7 @@ test('Editing the details of an OpenMRS patient with a synced lab order edits th
await openmrs.updatePatientDetails();

// verify
await senaite.open();
await page.goto(`${SENAITE_URL}`);
await senaite.searchClient();

await expect(client).toContainText(`${patientName.updatedFirstName}` + ' ' + `${patientName.givenName }`);
Expand All @@ -73,7 +73,7 @@ test('Editing a synced OpenMRS lab order edits the corresponding SENAITE analysi
await openmrs.updateLabOrder();

// verify
await senaite.open();
await page.goto(`${SENAITE_URL}`);
await senaite.searchClient();

await expect(client).toContainText(`${patientName.firstName + ' ' + patientName.givenName}`);
Expand Down Expand Up @@ -102,7 +102,7 @@ test('Voiding a synced OpenMRS lab order cancels the corresponding SENAITE analy
await openmrs.voidEncounter();

// verify
await senaite.open();
await page.goto(`${SENAITE_URL}`);
await senaite.searchClient();
await expect(client).not.toHaveText(`${patientName.firstName + ' ' + patientName.givenName}`);
});
Expand Down
6 changes: 3 additions & 3 deletions e2e/utils/functions/erpnext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ERPNext {
await this.page.goto(`${ERPNEXT_URL}/app/quotation`);
await this.searchQuotation();
await this.page.getByRole('checkbox', { name: 'Select All' }).check();
await delay(2500);
await delay(2000);
await this.page.getByRole('button', { name: 'Actions' }).click();
await this.page.getByRole('link', { name: 'Delete' }).click();
await this.page.getByRole('button', { name: 'Yes' }).click();
Expand All @@ -44,7 +44,7 @@ export class ERPNext {
await this.page.goto(`${ERPNEXT_URL}/app/quotation`);
await this.searchQuotation();
await this.page.getByRole('checkbox', { name: 'Select All' }).check();
await delay(2500);
await delay(2000);
await this.page.getByRole('button', { name: 'Actions' }).click();
await this.page.getByRole('link', { name: 'Cancel' }).click();
await this.page.getByRole('button', { name: 'Yes' }).click();
Expand All @@ -54,7 +54,7 @@ export class ERPNext {
await this.page.goto(`${ERPNEXT_URL}/app/customer`);
await this.searchCustomer();
await this.page.getByRole('checkbox', { name: 'Select All' }).check();
await delay(2500);
await delay(2000);
await this.page.getByRole('button', { name: 'Actions' }).click();
await this.page.getByRole('link', { name: 'Delete' }).click();
await this.page.getByRole('button', { name: 'Yes' }).click();
Expand Down
2 changes: 1 addition & 1 deletion e2e/utils/functions/keycloak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Keycloak {
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);
await delay(6000);
}

async createRole() {
Expand Down
1 change: 0 additions & 1 deletion e2e/utils/functions/odoo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class Odoo {
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}`);
Expand Down
22 changes: 17 additions & 5 deletions e2e/utils/functions/openmrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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 delay(4000);
await this.waitHomePageToLoad();
}

Expand Down Expand Up @@ -82,14 +82,18 @@ export class OpenMRS {
}

async goToHomePage() {
await this.page.goto(`${O3_URL}/openmrs/spa/home`);
if (`${process.env.TEST_LOCALHOST}` == 'true') {
await this.page.goto(`${O3_URL}/home`);
} else {
await this.page.goto(`${O3_URL}/openmrs/spa/home`);
}
await expect(this.page).toHaveURL(/.*home/);
}

async searchPatient(searchText: string) {
await this.goToHomePage();
await this.patientSearchIcon().click();
await this.patientSearchBar().type(searchText);
await this.patientSearchBar().fill(searchText);
await this.page.getByRole('link', { name: `${patientFullName}` }).first().click();
}

Expand Down Expand Up @@ -119,7 +123,11 @@ export class OpenMRS {
}

async getPatientUuid() {
await this.page.goto(`${O3_URL}/openmrs/spa/home`);
if (`${process.env.TEST_LOCALHOST}` == 'true') {
await this.page.goto(`${O3_URL}/home`);

This comment has been minimized.

Copy link
@mks-d

mks-d Jun 10, 2024

Contributor

Why ${O3_URL}/home and not http:https://localhost/openmrs/home?

In other words, why is the pattern not the same as there?

This comment has been minimized.

Copy link
@kdaud

kdaud Jun 10, 2024

Author Contributor

Very good question.
There is a difference between the urls for a localhost and online instance.

  • localhost: O3_URL=http:https://localhost/openmrs/spa
  • online: O3_URL=https://ozone-dev.mekomsolutions.net

The respective urls to the home page:

  • localhost: ${O3_URL}/home
  • online: ${O3_URL}/openmrs/spa/home

The respective urls to the backend UI

  • localhost: http:https://localhost/openmrs/admin/patients/index.htm. Note: The url for the localhost doesn't contain the string spa.
  • online: ${O3_URL}/openmrs/admin/index.htm

The possible way to make this pattern better is to set the base url for localhost in the .env config file to:

O3_URL=http:https://localhost/openmrs

But again, the suggested url in actual sense redirects to the login page of the backend side however, the string spa can be concatenated in the test implementation to have the url redirect to the login page of the O3 frontend UI.

This comment has been minimized.

Copy link
@mks-d

mks-d Jun 10, 2024

Contributor

The possible way to make this pattern better is to set the base url for localhost in the .env config file to:

O3_URL=http:https://localhost/openmrs

That definitely sounds like a better way. What would be the downside of doing this?

This comment has been minimized.

Copy link
@kdaud

kdaud Jun 10, 2024

Author Contributor

I'll get back here after analyzing the suggested solution.

This comment has been minimized.

Copy link
@kdaud

kdaud Jun 11, 2024

Author Contributor

What would be the downside of doing this?

I see inconsistencies in the O3 URLs in the docs. The quick start guide gives the URL as http:https://localhost/openmrs/spa.

This comment has been minimized.

Copy link
@kdaud

kdaud Jun 11, 2024

Author Contributor

But again, these instructions help devs run E2E tests during development, so we can use the URL that works best to achieve this. And in fact we can use O3_URL=http:https://localhost to have the pattern the same across the test implementation.

@mks-d let me know what you think.

This comment has been minimized.

Copy link
@mks-d

mks-d Jun 17, 2024

Contributor

@kdaud if http:https://localhost is the O3 URL within Ozone HIS, then this is how it should be set. Especially if the side benefit is that the E2E code base is made simpler.

This comment has been minimized.

Copy link
@mks-d

mks-d Jun 17, 2024

Contributor

The quick start guide gives the URL as http:https://localhost/openmrs/spa.

If this is incorrect, then the Docs must be updated! Could you confirm?

This comment has been minimized.

Copy link
@kdaud

kdaud Jun 17, 2024

Author Contributor

If this is incorrect, then the Docs must be updated! Could you confirm?

Definitely, once these changes are merged then I'll update the url in the docs.

This comment has been minimized.

Copy link
@kdaud

kdaud Jun 17, 2024

Author Contributor

PR on the ozone-his/ozone-e2e is merged and I've updated the ulr in the docs.

} else {
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();
Expand All @@ -146,7 +154,11 @@ export class OpenMRS {
}

async voidPatient() {
await this.page.goto(`${O3_URL}/openmrs/admin/patients/index.htm`);
if (`${process.env.TEST_LOCALHOST}` == 'true') {
await this.page.goto(`http:https://localhost/openmrs/admin/patients/index.htm`);
} else {
await this.page.goto(`${O3_URL}/openmrs/admin/patients/index.htm`);
}
await this.page.getByPlaceholder(' ').type(`${patientName.firstName + ' ' + patientName.givenName}`);
await this.page.locator('#openmrsSearchTable tbody tr.odd td:nth-child(1)').click();
await this.page.locator('input[name="voidReason"]').fill('Void patient created by smoke test');
Expand Down
3 changes: 1 addition & 2 deletions e2e/utils/functions/senaite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export class SENAITE {

async open() {
await this.page.goto(`${SENAITE_URL}`);
if (!(`${process.env.TEST_PRO}` == 'true')) {
await delay(3000);
if ((`${process.env.TEST_PRO}` == 'false')) {
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}`);
Expand Down
7 changes: 7 additions & 0 deletions e2e/utils/functions/superset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export class Superset {

async open() {
await this.page.goto(`${SUPERSET_URL}`);
if ((`${process.env.TEST_PRO}` == 'false')) {
await this.page.locator('#username').fill(`${process.env.SUPERSET_USERNAME_ON_FOSS}`);
await delay(1000);
await this.page.locator('#password').fill(`${process.env.SUPERSET_PASSWORD_ON_FOSS}`);
await delay(1000);
await this.page.locator('input[type="submit"]').click();
}
}

async selectDBSchema() {
Expand Down

0 comments on commit f197b8a

Please sign in to comment.