Skip to content

Commit 19bb177

Browse files
committed
Add e2e tests to test both msf server and
Add e2e tests to test both msf server and latest openmrs release rerun build change branch name to the corresponding head of the pull resuest Update e2e.yml Update e2e.yml Update e2e.yml Update e2e.yml Update e2e.yml Update e2e.yml Update e2e.yml Update e2e.yml Update e2e.yml fix broken e2e.yml remove lock file refresh yarn file create the yarn.lock file force yarn to change the lock file Update e2e.yml remove more packages upgrade packages fix testing url upload video of result Update login.spec.ts Update registration-and-edit-page.ts
1 parent 25c4b5f commit 19bb177

24 files changed

+1855
-0
lines changed

.github/workflows/e2e.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
pull_request:
9+
branches:
10+
- main
11+
- dev
12+
13+
jobs:
14+
run_e2e_tests:
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 15
17+
steps:
18+
- name: Extract branch name
19+
shell: bash
20+
run: echo "BRANCH_NAME=$(echo ${GITHUB_BASE_REF#refs/heads/} | sed 's/\//-/g')" >> $GITHUB_ENV
21+
22+
- name: Set the Environment
23+
shell: bash
24+
run: |
25+
if [ "${{ env.BRANCH_NAME }}" = "main" ]; then
26+
echo "ENVIRONMENT=prod" >> $GITHUB_ENV
27+
else
28+
echo "ENVIRONMENT=${{ env.BRANCH_NAME }}" >> $GITHUB_ENV
29+
fi
30+
31+
- name: Checkout repo
32+
uses: actions/checkout@v4
33+
34+
- name: Enable Corepack before setting up Node
35+
run: corepack enable
36+
37+
- name: Setup node
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: 18
41+
42+
- name: Cache dependencies
43+
id: cache
44+
uses: actions/cache@v4
45+
with:
46+
path: '**/node_modules'
47+
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
48+
49+
- name: Copy test environment variables
50+
run: cp example.env .env
51+
working-directory: ./e2e
52+
53+
- name: Install dependencies
54+
run: yarn install
55+
working-directory: ./e2e
56+
57+
- name: Install Playwright Browsers
58+
run: npx playwright install chromium --with-deps
59+
working-directory: ./e2e
60+
61+
- name: Run MSF/OCG LIME ${{ env.BRANCH_NAME }} server
62+
run: docker compose -f docker-compose.yml --env-file ./config/secrets/${{ env.ENVIRONMENT }}/${{ env.ENVIRONMENT }}.env up -d
63+
64+
- name: Wait for OpenMRS instance to start
65+
run: while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost/openmrs/login.htm)" != "200" ]]; do sleep 10; done
66+
67+
- name: Run E2E tests
68+
run: yarn test-e2e
69+
working-directory: ./e2e
70+
71+
- name: Stop dev server
72+
if: '!cancelled()'
73+
run: docker stop $(docker ps -a -q)
74+
75+
- name: Upload report
76+
uses: actions/upload-artifact@v4
77+
if: '!cancelled()'
78+
with:
79+
name: playwright-report
80+
path: e2e/playwright-report/
81+
retention-days: 30
82+
overwrite: true
83+
84+
- name: Capture Server Logs
85+
if: '!cancelled()'
86+
uses: jwalton/gh-docker-logs@v2
87+
with:
88+
dest: './logs'
89+
90+
- name: Upload Logs as Artifact
91+
uses: actions/upload-artifact@v4
92+
if: '!cancelled()'
93+
with:
94+
name: server-logs
95+
path: './logs'
96+
retention-days: 2
97+
overwrite: true

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@
33
**/node_modules/
44
.idea/
55
.vscode/settings.json
6+
7+
# Playwright and e2e tests
8+
e2e/test-results/
9+
e2e/playwright-report/
10+
e2e/playwright/.cache/
11+
e2e/storageState.json
12+
e2e/.pnp**
13+
14+
**/.yarn/

docs/README.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,126 @@ When building the frontend image for OpenMRS 3, the system automatically detects
660660
- `--progress=plain`: This option shows the build progress in plain text format, making it easier to track the build process. (this is optional)
661661
- `-f ./frontend/Dockerfile`: Specifies that we are using the frontend Dockerfile for building
662662
- `-t msfocg/openmrs3-frontend:qa`: tag of the frontend image must have the same name as in docker compose.
663+
664+
# [e2e Testing](#e2e-testing)
665+
666+
The MSF/OCG LIME is build with an E2E test suite using the [Playwright](https://playwright.dev)
667+
framework.
668+
669+
## Running tests locally
670+
671+
Below are the steps you need to test the current version of the MSF/OCG LIME server.
672+
673+
```sh
674+
docker compose up -d
675+
```
676+
Then, in a separate terminal, run:
677+
678+
```sh
679+
cd e2e \
680+
yarn install \
681+
cp example.env .env \
682+
yarn test-e2e --headed
683+
```
684+
<!-- markdown-link-check-disable-next-line -->
685+
By default, the test suite will run against the local server at `http://localhost`.
686+
You can override this by exporting `E2E_BASE_URL` environment variables beforehand:
687+
688+
For example to **test the latest release of openmrs** set `E2E_BASE_URL` to point to the `o3.openmrs.org` instance like below
689+
690+
```sh
691+
# Ex: Set the server URL to o3:
692+
export E2E_BASE_URL=https://o3.openmrs.org/openmrs
693+
694+
# Run all e2e tests:
695+
yarn test-e2e --headed
696+
```
697+
To run a specific test by title:
698+
```sh
699+
yarn test-e2e --headed -g "title of the test"
700+
```
701+
Check [this documentation](https://playwright.dev/docs/running-tests#command-line) for more running options.
702+
703+
It is also highly recommended to install the companion VS Code extension:
704+
(https://playwright.dev/docs/getting-started-vscode)
705+
706+
707+
## Features Tested
708+
709+
- User login
710+
- Patient Registration
711+
- Patient Search
712+
713+
## Writing New Tests
714+
715+
In general, it is recommended to read through the official [Playwright docs](https://playwright.dev/docs/intro)
716+
before writing new test cases. The project uses the official Playwright test runner and,
717+
generally, follows a very simple project structure:
718+
719+
```
720+
e2e
721+
|__ commands
722+
| ^ Contains "commands" (simple reusable functions) that can be used in test cases/specs,
723+
| e.g. generate a random patient.
724+
|__ core
725+
| ^ Contains code related to the test runner itself, e.g. setting up the custom fixtures.
726+
| You probably need to touch this infrequently.
727+
|__ fixtures
728+
| ^ Contains fixtures (https://playwright.dev/docs/test-fixtures) which are used
729+
| to run reusable setup/teardown tasks
730+
|__ pages
731+
| ^ Contains page object model classes for interacting with the frontend.
732+
| See https://playwright.dev/docs/test-pom for details.
733+
|__ specs
734+
| ^ Contains the actual test cases/specs. New tests should be placed in this folder.
735+
|__ support
736+
^ Contains support files that requires to run e2e tests, e.g. docker compose files.
737+
```
738+
739+
When you want to write a new test case, start by creating a new spec in `./specs`.
740+
Depending on what you want to achieve, you might want to create new fixtures and/or
741+
page object models. To see examples, have a look at the existing code to see how these
742+
different concepts play together.
743+
744+
## Open reports from GitHub Actions
745+
746+
To download the report from the GitHub action plan, follow these steps:
747+
748+
1. Go to the artifact section of the action/plan and locate the report file.
749+
2. Download the report file and unzip it using a tool of your choice.
750+
3. Open the index.html file in a web browser to view the report.
751+
752+
The report will show you a full summary of your tests, including information on which
753+
tests passed, failed, were skipped, or were flaky. You can filter the report by browser
754+
and explore the details of individual tests, including any errors or failures, video
755+
recordings, and the steps involved in each test. Simply click on a test to view its details.
756+
757+
## Debugging Tests
758+
759+
Refer to [this documentation](https://playwright.dev/docs/debug) on how to debug a test.
760+
761+
## Configuration
762+
763+
This is very much underdeveloped/WIP. At the moment, there exists a (git-shared) `.env`
764+
file which can be used for configuring certain test attributes. This is most likely
765+
about to change in the future. Stay tuned for updates!
766+
767+
768+
## Github Action integration
769+
The e2e.yml workflow is made up of two jobs: one for running on pull requests (PRs) and
770+
one for running on commits.
771+
772+
1. When running on PRs, the workflow will start the OpenMRS msf server, and run tests only on chromium.
773+
This is done in order to quickly provide feedback to the developer.
774+
The tests are designed to generate their own data and clean up after themselves once they are finished.
775+
In the future, we plan figure out how to run containers within a small amount of time.
776+
2. When running on commits, the workflow will spin up a docker container and run the msf server against
777+
it in order to provide a known and isolated environment. In addition, tests will be run on multiple
778+
browsers (chromium, firefox, and WebKit) to ensure compatibility.
779+
780+
## Troubleshooting tips
781+
782+
On MacOS, you might run into the following error:
783+
```browserType.launch: Executable doesn't exist at /Users/<user>/Library/Caches/ms-playwright/chromium-1015/chrome-mac/Chromium.app/Contents/MacOS/Chromium```
784+
In order to fix this, you can attempt to force the browser reinstallation by running:
785+
```PLAYWRIGHT_BROWSERS_PATH=/Users/$USER/Library/Caches/ms-playwright npx playwright install```

e2e/README.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# E2E Tests
2+
3+
This directory contains an E2E test suite using the [Playwright](https://playwright.dev)
4+
framework.
5+
6+
## Getting Started
7+
8+
Please ensure that you have followed the basic installation guide in the
9+
[root README](../README.md).
10+
Once everything is set up, make sure the dev server is running by using:
11+
12+
```sh
13+
yarn start --sources 'packages/esm-*-app/'
14+
```
15+
Then, in a separate terminal, run:
16+
17+
```sh
18+
yarn test-e2e --headed
19+
```
20+
<!-- markdown-link-check-disable-next-line -->
21+
By default, the test suite will run against the `http://localhost:8080`.
22+
You can override this by exporting `E2E_BASE_URL` environment variables beforehand:
23+
24+
```sh
25+
# Ex: Set the server URL to dev3:
26+
export E2E_BASE_URL=https://dev3.openmrs.org/openmrs
27+
28+
# Run all e2e tests:
29+
yarn test-e2e --headed
30+
```
31+
To run a specific test by title:
32+
```sh
33+
yarn test-e2e --headed -g "title of the test"
34+
```
35+
Check [this documentation](https://playwright.dev/docs/running-tests#command-line) for more running options.
36+
37+
It is also highly recommended to install the companion VS Code extension:
38+
(https://playwright.dev/docs/getting-started-vscode)
39+
40+
41+
## Writing New Tests
42+
43+
In general, it is recommended to read through the official [Playwright docs](https://playwright.dev/docs/intro)
44+
before writing new test cases. The project uses the official Playwright test runner and,
45+
generally, follows a very simple project structure:
46+
47+
```
48+
e2e
49+
|__ commands
50+
| ^ Contains "commands" (simple reusable functions) that can be used in test cases/specs,
51+
| e.g. generate a random patient.
52+
|__ core
53+
| ^ Contains code related to the test runner itself, e.g. setting up the custom fixtures.
54+
| You probably need to touch this infrequently.
55+
|__ fixtures
56+
| ^ Contains fixtures (https://playwright.dev/docs/test-fixtures) which are used
57+
| to run reusable setup/teardown tasks
58+
|__ pages
59+
| ^ Contains page object model classes for interacting with the frontend.
60+
| See https://playwright.dev/docs/test-pom for details.
61+
|__ specs
62+
| ^ Contains the actual test cases/specs. New tests should be placed in this folder.
63+
|__ support
64+
^ Contains support files that requires to run e2e tests, e.g. docker compose files.
65+
```
66+
67+
When you want to write a new test case, start by creating a new spec in `./specs`.
68+
Depending on what you want to achieve, you might want to create new fixtures and/or
69+
page object models. To see examples, have a look at the existing code to see how these
70+
different concepts play together.
71+
72+
## Open reports from GitHub Actions / Bamboo
73+
74+
To download the report from the GitHub action/Bamboo plan, follow these steps:
75+
76+
1. Go to the artifact section of the action/plan and locate the report file.
77+
2. Download the report file and unzip it using a tool of your choice.
78+
3. Open the index.html file in a web browser to view the report.
79+
80+
The report will show you a full summary of your tests, including information on which
81+
tests passed, failed, were skipped, or were flaky. You can filter the report by browser
82+
and explore the details of individual tests, including any errors or failures, video
83+
recordings, and the steps involved in each test. Simply click on a test to view its details.
84+
85+
## Debugging Tests
86+
87+
Refer to [this documentation](https://playwright.dev/docs/debug) on how to debug a test.
88+
89+
## Configuration
90+
91+
This is very much underdeveloped/WIP. At the moment, there exists a (git-shared) `.env`
92+
file which can be used for configuring certain test attributes. This is most likely
93+
about to change in the future. Stay tuned for updates!
94+
95+
96+
## Github Action integration
97+
The e2e.yml workflow is made up of two jobs: one for running on pull requests (PRs) and
98+
one for running on commits.
99+
100+
1. When running on PRs, the workflow will start the dev server, use dev3.openmrs.org as the backend,
101+
and run tests only on chromium. This is done in order to quickly provide feedback to the developer.
102+
The tests are designed to generate their own data and clean up after themselves once they are finished.
103+
This ensures that the tests will have minimum effect from changes made to dev3 by other developers.
104+
In the future, we plan to use a docker container to run the tests in an isolated environment once we
105+
figure out a way to spin up the container within a small amount of time.
106+
2. When running on commits, the workflow will spin up a docker container and run the dev server against
107+
it in order to provide a known and isolated environment. In addition, tests will be run on multiple
108+
browsers (chromium, firefox, and WebKit) to ensure compatibility.
109+
110+
## Troubleshooting tips
111+
112+
On MacOS, you might run into the following error:
113+
```browserType.launch: Executable doesn't exist at /Users/<user>/Library/Caches/ms-playwright/chromium-1015/chrome-mac/Chromium.app/Contents/MacOS/Chromium```
114+
In order to fix this, you can attempt to force the browser reinstallation by running:
115+
```PLAYWRIGHT_BROWSERS_PATH=/Users/$USER/Library/Caches/ms-playwright npx playwright install```

e2e/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './patientOperations';
2+

0 commit comments

Comments
 (0)