|
1 | | -# GitOps Operator - UI End-to-End Tests |
2 | 1 |
|
3 | | -This suite validates the OpenShift GitOps Operator UI, focusing on Argo CD and SSO integration. |
| 2 | +# OpenShift GitOps Operator - UI End-to-End Test Suite |
4 | 3 |
|
5 | | -## Prerequisites |
6 | | -1. **Node.js** (v18+) |
7 | | -2. **OpenShift CLI (oc)**: Installed and in your PATH. |
8 | | -3. **Install Dependencies:** Navigate to this directory and install required packages: |
9 | | - ```bash |
10 | | - cd test/ui-e2e |
11 | | - npm install |
12 | | - npx playwright install chromium |
13 | | - ``` |
| 4 | +This directory contains the Playwright-based UI End-to-End (E2E) automation suite for the OpenShift GitOps Operator. It validates core frontend workflows, console integration, Red Hat Single Sign-On (RHSSO) loops, and multi-version Argo CD compatibility across OpenShift clusters. |
14 | 5 |
|
15 | | -## Environment Variables |
16 | | -You must provide cluster credentials before running tests. You can either `export` these in your terminal (or pipeline), or create a `.env` file in the `test/ui-e2e` directory: |
| 6 | +--- |
17 | 7 |
|
18 | | -```text |
19 | | -# .env file example |
20 | | -CLUSTER_PASSWORD=your_openshift_admin_password |
21 | | -OC_API_URL=[https://api.cluster.com:6443](https://api.cluster.com:6443) |
22 | | -CLUSTER_USER=kubeadmin # (Optional) Defaults to kubeadmin |
23 | | -IDP=kube:admin # (Optional) Defaults to kube:admin |
24 | | -``` |
| 8 | +## Prerequisites |
25 | 9 |
|
26 | | -## Execution Commands |
| 10 | +Before running the suite locally, ensure your machine has the following tools installed: |
27 | 11 |
|
28 | | -All commands use the `./run-ui-tests.sh` wrapper which handles auth, OpenShift token generation, and URL discovery. **Ensure you are in the `test/ui-e2e` directory.** |
| 12 | +1. **Node.js** (v18 or higher) |
| 13 | +2. **OpenShift CLI (oc)**: Must be configured in your system PATH. |
| 14 | +3. **Browser Binaries**: Playwright requires its own specific browser engines to run tests reproducibly. These are installed automatically when you run the `npx playwright install` setup command. |
29 | 15 |
|
30 | | -**Run All Tests (Headless):** |
31 | | -```bash |
32 | | -./run-ui-tests.sh --project=chromium |
33 | | -``` |
| 16 | +### Installation |
| 17 | + |
| 18 | +Navigate to this directory and install the Node modules along with the required Playwright browser binaries: |
34 | 19 |
|
35 | | -**Run All Tests (Headed + Trace):** |
36 | 20 | ```bash |
37 | | -./run-ui-tests.sh --project=chromium --headed --reporter=list --trace on |
| 21 | +cd test/ui-e2e |
| 22 | +npm install |
| 23 | +npx playwright install chromium |
| 24 | + |
38 | 25 | ``` |
39 | 26 |
|
40 | | -**Run Single Test (Headed + Trace):** |
| 27 | +--- |
| 28 | + |
| 29 | +## Environment Configuration |
| 30 | + |
| 31 | +The test suite requires cluster administrative credentials to discover routes and handle authentication loops. You can configure these either via a local `.env` file or by exporting them directly into your terminal/CI environment pipeline. |
| 32 | + |
| 33 | +### Quick Setup (Local Development) |
| 34 | + |
| 35 | +Generate a local `.env` file in the root of this directory using the following block: |
| 36 | + |
41 | 37 | ```bash |
42 | | -./run-ui-tests.sh tests/login.spec.ts --project=chromium --headed --trace on |
| 38 | +cat <<EOF > .env |
| 39 | +export CLUSTER_USER="kubeadmin" |
| 40 | +export CLUSTER_PASSWORD="<your_cluster_password>" |
| 41 | +export OC_API_URL="<your_cluster_server_url>" |
| 42 | +export IDP="kube:admin" # (Optional) Defaults to kube:admin |
| 43 | +EOF |
| 44 | + |
43 | 45 | ``` |
44 | 46 |
|
45 | | -**View Trace Results:** |
| 47 | +> **Security Warning:** The `.env` file is explicitly ignored by Git. Please don't commit credentials to the repository. |
| 48 | +
|
| 49 | +--- |
| 50 | + |
| 51 | +## Execution Commands |
| 52 | + |
| 53 | +All executions are driven via the ./run-ui-tests.sh wrapper script. This wrapper automatically syncs your local oc CLI context to match your .env configuration, performs route discovery for the Console/Argo CD components, and initializes the Playwright runner. |
| 54 | + |
| 55 | +### Standard Test Execution |
| 56 | + |
| 57 | +| Target | Command | |
| 58 | +| --- | --- | |
| 59 | +| **Run All Tests (Headless/CI Mode)** | `./run-ui-tests.sh --project=chromium` | |
| 60 | +| **Run All Tests (Headed + Visual Tracing)** | `./run-ui-tests.sh --project=chromium --headed --trace on` | |
| 61 | +| **Run a Specific Spec File** | `./run-ui-tests.sh tests/create-application.spec.ts --project=chromium --headed --trace on` | |
| 62 | + |
| 63 | +### Playwright Flags Reference |
| 64 | + |
| 65 | +| Flag | Purpose | |
| 66 | +| --- | --- | |
| 67 | +| `--headed` | Launches the visible Chromium browser UI. Excellent for local debugging. | |
| 68 | +| `--trace on` | Records a granular execution trace (DOM snapshots, network calls, actions) for visual triage. | |
| 69 | +| `--reporter=list` | Switches stdout to a clean line-by-line format, ideal for monitoring real-time execution steps. | |
| 70 | + |
| 71 | +### Visual Debugging (Trace Viewer) |
| 72 | + |
| 73 | +If a test fails during execution, Playwright records a full interactive timeline (DOM snapshots, network calls, console logs). |
| 74 | + |
| 75 | +When a test fails, the terminal output will provide an exact command to view the trace. Copy and paste that specific command: |
| 76 | + |
46 | 77 | ```bash |
47 | | -npx playwright show-trace test-results/**/*/trace.zip |
| 78 | +# Example: |
| 79 | +npx playwright show-trace test-results/create-application-chromium/trace.zip |
| 80 | + |
48 | 81 | ``` |
49 | 82 |
|
50 | | -** Helpful Flags Explained** |
51 | | -* `--headed`: Runs tests in a visible browser. Without this, tests run in "headless" mode (invisible background). |
52 | | -* `--reporter=list`: Changes console output to a clean, line-by-line list so you can see exactly which test is running in real-time. |
53 | | -* `--trace on`: Captures a full "recording" (DOM snapshots, network, actions) of the test for debugging. |
| 83 | +--- |
54 | 84 |
|
55 | | -## Architecture |
| 85 | +## Suite Architecture |
56 | 86 |
|
57 | | -**Global Setup:** |
58 | | -`.auth/setup.ts` logs into the OCP console to generate a reusable session (`storageState.json`). This prevents having to log in repeatedly for every test file. |
| 87 | +```text |
| 88 | +├── .auth/ |
| 89 | +│ └── setup.ts # Orchestrates global OCP authentication & saves storageState.json |
| 90 | +├── src/ |
| 91 | +│ └── pages/ # Page Object Models (POM) isolating UI selectors from spec logic |
| 92 | +│ └── ApplicationsPage.ts |
| 93 | +├── tests/ # Test specs organized by feature epic |
| 94 | +│ ├── login.spec.ts |
| 95 | +│ └── create-application.spec.ts |
| 96 | +├── .env # Local runtime environment overrides (Git ignored) |
| 97 | +└── run-ui-tests.sh # Context-aware orchestrator & URL discovery engine |
| 98 | +
|
| 99 | +``` |
| 100 | + |
| 101 | +### Core Architecture Patterns |
59 | 102 |
|
60 | | -**Spec Isolation:** |
61 | | -`login.spec.ts` explicitly clears session cookies to force a full SSO UI validation from a fresh state. |
| 103 | +* **Global Authentication Reusability:** The .auth/setup.ts module runs first to execute the login sequence against the OpenShift cluster identity provider. It drops an authenticated session state cookie into storageState.json, allowing subsequent test specs to skip login actions entirely and save execution time. |
| 104 | +* **Isolated SSO Specs:** Explicit UI authentication testing (such as login.spec.ts) bypasses global storage state configurations and clears active browser contexts intentionally to validate raw login screens and provider selections. |
| 105 | +* **Cross-Version UI Abstraction:** Selectors inside the Page Object Models are written to withstand UI layout drift between consecutive OpenShift versions by prioritizing user-facing roles and text-based assertions over brittle CSS class trees. |
| 106 | + |
| 107 | +--- |
62 | 108 |
|
63 | 109 | ## Troubleshooting |
64 | 110 |
|
65 | | -* **"Invalid login or password" during automated login:** If you are testing against multiple clusters sequentially, your terminal's `oc` CLI might be holding onto a sticky session from an older cluster. Run `oc logout` before running the bash script to force a clean authentication. |
| 111 | +### Symptom: Playwright targets the wrong cluster version |
| 112 | + |
| 113 | +* **Cause:** The wrapper script handles cross-cluster contexts dynamically. If your terminal environment variables don't match your local ~/.kube/config cache, your terminal may fall back to cached sessions. |
| 114 | +* **Resolution:** Ensure you either run `source .env` inside your terminal window to reset active shell contexts, or verify that the variables declared within your .env file match your active target system configuration. |
| 115 | + |
0 commit comments