From c8ca422adac9eac379570c3923e2016ae1ca2eb7 Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Fri, 20 Oct 2023 12:43:12 -0700 Subject: [PATCH 1/2] Add docker setup to run E2E on Bamboo --- e2e/support/bamboo/docker-compose.yml | 56 ++++++++++++++++++++++++ e2e/support/bamboo/e2e-test-runner.sh | 13 ++++++ e2e/support/bamboo/playwright.Dockerfile | 12 +++++ package.json | 2 +- yarn.lock | 30 ++++++------- 5 files changed, 97 insertions(+), 16 deletions(-) create mode 100644 e2e/support/bamboo/docker-compose.yml create mode 100644 e2e/support/bamboo/e2e-test-runner.sh create mode 100644 e2e/support/bamboo/playwright.Dockerfile diff --git a/e2e/support/bamboo/docker-compose.yml b/e2e/support/bamboo/docker-compose.yml new file mode 100644 index 0000000..2239cea --- /dev/null +++ b/e2e/support/bamboo/docker-compose.yml @@ -0,0 +1,56 @@ +# This docker compose file is used to create a dockerized environment when running E2E tests on Bamboo. +version: "3.7" + +services: + playwright: + build: + context: . + dockerfile: playwright.Dockerfile + args: + USER_ID: ${USER_ID} + GROUP_ID: ${GROUP_ID} + container_name: form-builder-e2e-tests-container + working_dir: /app + command: sh /app/e2e/support/bamboo/e2e-test-runner.sh + volumes: + - ../../../:/app + networks: + - test + + gateway: + image: openmrs/openmrs-reference-application-3-gateway:${TAG:-nightly} + depends_on: + - frontend + - backend + ports: + - "80:80" + networks: + - test + + frontend: + image: openmrs/openmrs-reference-application-3-frontend:${TAG:-nightly} + environment: + SPA_PATH: /openmrs/spa + API_URL: /openmrs + SPA_CONFIG_URLS: + healthcheck: + test: [ "CMD", "curl", "-f", "http://localhost/" ] + timeout: 5s + depends_on: + - backend + networks: + - test + + backend: + image: openmrs/openmrs-reference-application-3-backend:nightly-with-data + depends_on: + - db + networks: + - test + db: + image: openmrs/openmrs-reference-application-3-db:nightly-with-data + networks: + - test + +networks: + test: diff --git a/e2e/support/bamboo/e2e-test-runner.sh b/e2e/support/bamboo/e2e-test-runner.sh new file mode 100644 index 0000000..3d2df2e --- /dev/null +++ b/e2e/support/bamboo/e2e-test-runner.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +export E2E_BASE_URL=http://gateway/openmrs +export CI=true + +while [ "$(curl -s -o /dev/null -w ''%{http_code}'' http://gateway/openmrs/login.htm)" != "200" ]; do + echo "Waiting for the backend to be up..." + sleep 10 +done + +cp example.env .env + +yarn test-e2e diff --git a/e2e/support/bamboo/playwright.Dockerfile b/e2e/support/bamboo/playwright.Dockerfile new file mode 100644 index 0000000..4fd9020 --- /dev/null +++ b/e2e/support/bamboo/playwright.Dockerfile @@ -0,0 +1,12 @@ +FROM mcr.microsoft.com/playwright:v1.39.0-jammy + +ARG USER_ID +ARG GROUP_ID + +RUN if ! getent group $GROUP_ID > /dev/null; then \ + groupadd -g $GROUP_ID myusergroup; \ +fi + +RUN useradd -u $USER_ID -g $GROUP_ID -m playwrightuser + +USER playwrightuser diff --git a/package.json b/package.json index 4349758..f0b0604 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "@dnd-kit/utilities": "^3.2.1", "@openmrs/esm-framework": "next", "@openmrs/esm-styleguide": "next", - "@playwright/test": "^1.38.0", + "@playwright/test": "1.39.0", "@swc/cli": "^0.1.62", "@swc/core": "^1.3.85", "@swc/jest": "^0.2.29", diff --git a/yarn.lock b/yarn.lock index bc0f4ce..de62ec1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3176,7 +3176,7 @@ __metadata: "@openmrs/esm-framework": next "@openmrs/esm-styleguide": next "@openmrs/openmrs-form-engine-lib": next - "@playwright/test": ^1.38.0 + "@playwright/test": 1.39.0 "@swc/cli": ^0.1.62 "@swc/core": ^1.3.85 "@swc/jest": ^0.2.29 @@ -3441,14 +3441,14 @@ __metadata: languageName: node linkType: hard -"@playwright/test@npm:^1.38.0": - version: 1.38.0 - resolution: "@playwright/test@npm:1.38.0" +"@playwright/test@npm:1.39.0": + version: 1.39.0 + resolution: "@playwright/test@npm:1.39.0" dependencies: - playwright: 1.38.0 + playwright: 1.39.0 bin: playwright: cli.js - checksum: 0768b6b98f0993d9d8017e4bcca3a5c3fe1bf0270acaa89b141479c4319c16350d60e6d2511cbd655283942059fa409ce23fce30435f0936f5e2577834f356ba + checksum: e93e58fc1af4239f239b890374f066c9a758e2492d25e2c1a532f3f00782ab8e7706956a07540fd14882c74e75f5de36273621adce9b79afb8e36e6c15f1d539 languageName: node linkType: hard @@ -14935,27 +14935,27 @@ __metadata: languageName: node linkType: hard -"playwright-core@npm:1.38.0": - version: 1.38.0 - resolution: "playwright-core@npm:1.38.0" +"playwright-core@npm:1.39.0": + version: 1.39.0 + resolution: "playwright-core@npm:1.39.0" bin: playwright-core: cli.js - checksum: 9eb43fc6c3cb392d5f35b0fd0b7291b38a8cbdc3cbb944a8261f744f30d09196dfa3b5d84aa02ffc09af87d08d31b385b007b6af20d0b6cd50a29344f3b0db8d + checksum: 556e78dee4f9890facf2af8249972e0d6e01a5ae98737b0f6b0166c660a95ffee4cb79350335b1ef96430a0ef01d3669daae9099fa46c8d403d11c623988238b languageName: node linkType: hard -"playwright@npm:1.38.0": - version: 1.38.0 - resolution: "playwright@npm:1.38.0" +"playwright@npm:1.39.0": + version: 1.39.0 + resolution: "playwright@npm:1.39.0" dependencies: fsevents: 2.3.2 - playwright-core: 1.38.0 + playwright-core: 1.39.0 dependenciesMeta: fsevents: optional: true bin: playwright: cli.js - checksum: c5356690a391d5dd41f814d4e2694b93ba9e79381ce63de752da1c6c59b1f9c69bc6be853d973d0542d73a44a6b15f7c0081a164a64cd27b6b31207710c0ab34 + checksum: 96d8ca5aa25465c1c5d554d0d6071981d55e22477800ff8f5d47a53ca75193d60ece2df538a01b7165b3277dd5493c67603a5acda713029df7fbd95ce2417bc9 languageName: node linkType: hard From b0dddf101ed4e5701ec211e03e31076f31fcc061 Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Fri, 20 Oct 2023 13:19:30 -0700 Subject: [PATCH 2/2] Change E2E output Dir --- .gitignore | 2 +- README.md | 3 +- e2e/README.md | 115 ------------------------------------------- playwright.config.ts | 7 +-- 4 files changed, 4 insertions(+), 123 deletions(-) delete mode 100644 e2e/README.md diff --git a/.gitignore b/.gitignore index 5cc37f5..59b26cb 100644 --- a/.gitignore +++ b/.gitignore @@ -84,4 +84,4 @@ dist/ /playwright-report/ /playwright/.cache/ e2e/storageState.json - +results.xml diff --git a/README.md b/README.md index 6f42ba4..a502c00 100644 --- a/README.md +++ b/README.md @@ -95,8 +95,7 @@ Then, in a separate terminal, run: yarn test-e2e --headed ``` -Please read [our e2e docs](e2e/README.md) for more information about E2E testing. - +Read the [e2e testing guide](/e2e/README.md) to learn more about End-to-End tests in this project. ## Building ```sh diff --git a/e2e/README.md b/e2e/README.md deleted file mode 100644 index 4d479b6..0000000 --- a/e2e/README.md +++ /dev/null @@ -1,115 +0,0 @@ -# E2E Tests - -This directory contains an E2E test suite using the [Playwright](https://playwright.dev) -framework. - -## Getting Started - -Please ensure that you have followed the basic installation guide in the -[root README](../README.md). -Once everything is set up, make sure the dev server is running by using: - -```sh -yarn start -``` -Then, in a separate terminal, run: - -```sh -yarn test-e2e --headed -``` - -By default, the test suite will run against the http://localhost:8080. -You can override this by exporting `E2E_BASE_URL` environment variables beforehand: - -```sh -# Ex: Set the server URL to dev3: -export E2E_BASE_URL=https://dev3.openmrs.org/openmrs - -# Run all e2e tests: -yarn test-e2e --headed -``` -To run a specific test by title: -```sh -yarn test-e2e --headed -g "title of the test" -``` -Check [this documentation](https://playwright.dev/docs/running-tests#command-line) for more running options. - -It is also highly recommended to install the companion VS Code extension: -https://playwright.dev/docs/getting-started-vscode - - -## Writing New Tests - -In general, it is recommended to read through the official [Playwright docs](https://playwright.dev/docs/intro) -before writing new test cases. The project uses the official Playwright test runner and, -generally, follows a very simple project structure: - -``` -e2e -|__ commands -| ^ Contains "commands" (simple reusable functions) that can be used in test cases/specs, -| e.g. generate a random patient. -|__ core -| ^ Contains code related to the test runner itself, e.g. setting up the custom fixtures. -| You probably need to touch this infrequently. -|__ fixtures -| ^ Contains fixtures (https://playwright.dev/docs/test-fixtures) which are used -| to run reusable setup/teardown tasks -|__ pages -| ^ Contains page object model classes for interacting with the frontend. -| See https://playwright.dev/docs/test-pom for details. -|__ specs -| ^ Contains the actual test cases/specs. New tests should be placed in this folder. -|__ support - ^ Contains support files that requires to run e2e tests, e.g. docker compose files. -``` - -When you want to write a new test case, start by creating a new spec in `./specs`. -Depending on what you want to achieve, you might want to create new fixtures and/or -page object models. To see examples, have a look at the existing code to see how these -different concepts play together. - -## Open reports from GitHub Actions / Bamboo - -To download the report from the GitHub action/Bamboo plan, follow these steps: - -1. Go to the artifact section of the action/plan and locate the report file. -2. Download the report file and unzip it using a tool of your choice. -3. Open the index.html file in a web browser to view the report. - -The report will show you a full summary of your tests, including information on which -tests passed, failed, were skipped, or were flaky. You can filter the report by browser -and explore the details of individual tests, including any errors or failures, video -recordings, and the steps involved in each test. Simply click on a test to view its details. - -## Debugging Tests - -Refer to [this documentation](https://playwright.dev/docs/debug) on how to debug a test. - -## Configuration - -This is very much underdeveloped/WIP. At the moment, there exists a (git-shared) `.env` -file which can be used for configuring certain test attributes. This is most likely -about to change in the future. Stay tuned for updates! - - -## Github Action integration -The e2e.yml workflow is made up of two jobs: one for running on pull requests (PRs) and -one for running on commits. - -1. When running on PRs, the workflow will start the dev server, use dev3.openmrs.org as the backend, -and run tests only on chromium. This is done in order to quickly provide feedback to the developer. -The tests are designed to generate their own data and clean up after themselves once they are finished. -This ensures that the tests will have minimum effect from changes made to dev3 by other developers. -In the future, we plan to use a docker container to run the tests in an isolated environment once we -figure out a way to spin up the container within a small amount of time. -2. When running on commits, the workflow will spin up a docker container and run the dev server against -it in order to provide a known and isolated environment. In addition, tests will be run on multiple -browsers (chromium, firefox, and WebKit) to ensure compatibility. - -## Troubleshooting tips - -On MacOS, you might run into the following error: -```browserType.launch: Executable doesn't exist at /Users//Library/Caches/ms-playwright/chromium-1015/chrome-mac/Chromium.app/Contents/MacOS/Chromium``` -In order to fix this, you can attempt to force the browser reinstallation by running: -```PLAYWRIGHT_BROWSERS_PATH=/Users/$USER/Library/Caches/ms-playwright npx playwright install``` diff --git a/playwright.config.ts b/playwright.config.ts index 2b9fb81..0ddeb08 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -10,13 +10,10 @@ const config: PlaywrightTestConfig = { expect: { timeout: 20 * 1000, }, - fullyParallel: true, - outputDir: '../test-results/results', + workers: 1, forbidOnly: !!process.env.CI, retries: 0, - reporter: process.env.CI - ? [['junit', { outputFile: 'results.xml' }], ['html']] - : [['html', { outputFolder: '../test-results/report' }]], + reporter: process.env.CI ? [['junit', { outputFile: 'results.xml' }], ['html']] : [['html']], globalSetup: require.resolve('./e2e/core/global-setup'), use: { baseURL: `${process.env.E2E_BASE_URL}/spa/`,