-
Notifications
You must be signed in to change notification settings - Fork 351
GITOPS-9682 UI E2E Create App test #1162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
trdoyle81
wants to merge
6
commits into
redhat-developer:master
Choose a base branch
from
trdoyle81:GITOPS-9682-Create-App-Test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b491d88
GITOPS-9682 UI E2E Create App test
0ed24a8
address Coderabbit PR review feedback
b5ae621
address Coderabbit 'nitpick' feedback
c0ebb34
address further coderabbit feedback ...
d260866
update applications page locators for 1.21.0 compatibility
430bac8
address the coderabbit feedback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,65 +1,115 @@ | ||
| # GitOps Operator - UI End-to-End Tests | ||
|
|
||
| This suite validates the OpenShift GitOps Operator UI, focusing on Argo CD and SSO integration. | ||
| # OpenShift GitOps Operator - UI End-to-End Test Suite | ||
|
|
||
| ## Prerequisites | ||
| 1. **Node.js** (v18+) | ||
| 2. **OpenShift CLI (oc)**: Installed and in your PATH. | ||
| 3. **Install Dependencies:** Navigate to this directory and install required packages: | ||
| ```bash | ||
| cd test/ui-e2e | ||
| npm install | ||
| npx playwright install chromium | ||
| ``` | ||
| 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. | ||
|
|
||
| ## Environment Variables | ||
| 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: | ||
| --- | ||
|
|
||
| ```text | ||
| # .env file example | ||
| CLUSTER_PASSWORD=your_openshift_admin_password | ||
| OC_API_URL=[https://api.cluster.com:6443](https://api.cluster.com:6443) | ||
| CLUSTER_USER=kubeadmin # (Optional) Defaults to kubeadmin | ||
| IDP=kube:admin # (Optional) Defaults to kube:admin | ||
| ``` | ||
| ## Prerequisites | ||
|
|
||
| ## Execution Commands | ||
| Before running the suite locally, ensure your machine has the following tools installed: | ||
|
|
||
| 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.** | ||
| 1. **Node.js** (v18 or higher) | ||
| 2. **OpenShift CLI (oc)**: Must be configured in your system PATH. | ||
| 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. | ||
|
|
||
| **Run All Tests (Headless):** | ||
| ```bash | ||
| ./run-ui-tests.sh --project=chromium | ||
| ``` | ||
| ### Installation | ||
|
|
||
| Navigate to this directory and install the Node modules along with the required Playwright browser binaries: | ||
|
|
||
| **Run All Tests (Headed + Trace):** | ||
| ```bash | ||
| ./run-ui-tests.sh --project=chromium --headed --reporter=list --trace on | ||
| cd test/ui-e2e | ||
| npm install | ||
| npx playwright install chromium | ||
|
|
||
| ``` | ||
|
|
||
| **Run Single Test (Headed + Trace):** | ||
| --- | ||
|
|
||
| ## Environment Configuration | ||
|
|
||
| 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. | ||
|
|
||
| ### Quick Setup (Local Development) | ||
|
|
||
| Generate a local `.env` file in the root of this directory using the following block: | ||
|
|
||
| ```bash | ||
| ./run-ui-tests.sh tests/login.spec.ts --project=chromium --headed --trace on | ||
| cat <<EOF > .env | ||
| export CLUSTER_USER="kubeadmin" | ||
| export CLUSTER_PASSWORD="<your_cluster_password>" | ||
| export OC_API_URL="<your_cluster_server_url>" | ||
| export IDP="kube:admin" # (Optional) Defaults to kube:admin | ||
| EOF | ||
|
|
||
| ``` | ||
|
|
||
| **View Trace Results:** | ||
| > **Security Warning:** The `.env` file is explicitly ignored by Git. Please don't commit credentials to the repository. | ||
|
|
||
| --- | ||
|
|
||
| ## Execution Commands | ||
|
|
||
| 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. | ||
|
|
||
| ### Standard Test Execution | ||
|
|
||
| | Target | Command | | ||
| | --- | --- | | ||
| | **Run All Tests (Headless/CI Mode)** | `./run-ui-tests.sh --project=chromium` | | ||
| | **Run All Tests (Headed + Visual Tracing)** | `./run-ui-tests.sh --project=chromium --headed --trace on` | | ||
| | **Run a Specific Spec File** | `./run-ui-tests.sh tests/create-application.spec.ts --project=chromium --headed --trace on` | | ||
|
|
||
| ### Playwright Flags Reference | ||
|
|
||
| | Flag | Purpose | | ||
| | --- | --- | | ||
| | `--headed` | Launches the visible Chromium browser UI. Excellent for local debugging. | | ||
| | `--trace on` | Records a granular execution trace (DOM snapshots, network calls, actions) for visual triage. | | ||
| | `--reporter=list` | Switches stdout to a clean line-by-line format, ideal for monitoring real-time execution steps. | | ||
|
|
||
| ### Visual Debugging (Trace Viewer) | ||
|
|
||
| If a test fails during execution, Playwright records a full interactive timeline (DOM snapshots, network calls, console logs). | ||
|
|
||
| When a test fails, the terminal output will provide an exact command to view the trace. Copy and paste that specific command: | ||
|
|
||
| ```bash | ||
| npx playwright show-trace test-results/**/*/trace.zip | ||
| # Example: | ||
| npx playwright show-trace test-results/create-application-chromium/trace.zip | ||
|
|
||
| ``` | ||
|
|
||
| ** Helpful Flags Explained** | ||
| * `--headed`: Runs tests in a visible browser. Without this, tests run in "headless" mode (invisible background). | ||
| * `--reporter=list`: Changes console output to a clean, line-by-line list so you can see exactly which test is running in real-time. | ||
| * `--trace on`: Captures a full "recording" (DOM snapshots, network, actions) of the test for debugging. | ||
| --- | ||
|
|
||
| ## Architecture | ||
| ## Suite Architecture | ||
|
|
||
| **Global Setup:** | ||
| `.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. | ||
| ```text | ||
| ├── .auth/ | ||
| │ └── setup.ts # Orchestrates global OCP authentication & saves storageState.json | ||
| ├── src/ | ||
| │ └── pages/ # Page Object Models (POM) isolating UI selectors from spec logic | ||
| │ └── ApplicationsPage.ts | ||
| ├── tests/ # Test specs organized by feature epic | ||
| │ ├── login.spec.ts | ||
| │ └── create-application.spec.ts | ||
| ├── .env # Local runtime environment overrides (Git ignored) | ||
| └── run-ui-tests.sh # Context-aware orchestrator & URL discovery engine | ||
|
|
||
| ``` | ||
|
|
||
| ### Core Architecture Patterns | ||
|
|
||
| **Spec Isolation:** | ||
| `login.spec.ts` explicitly clears session cookies to force a full SSO UI validation from a fresh state. | ||
| * **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. | ||
| * **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. | ||
| * **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. | ||
|
|
||
| --- | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| * **"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. | ||
| ### Symptom: Playwright targets the wrong cluster version | ||
|
|
||
| * **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. | ||
| * **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. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { test as base, expect } from '@playwright/test'; | ||
| import { LoginPage } from './pages/LoginPage'; | ||
| import { ApplicationsPage } from './pages/ApplicationsPage'; | ||
|
|
||
| //define custom fixture types | ||
| type MyFixtures = { | ||
| managedApp: string; | ||
| }; | ||
|
|
||
| export const test = base.extend<MyFixtures>({ | ||
|
|
||
| //login override | ||
| page: async ({ page }, use) => { | ||
| const loginPage = new LoginPage(page); | ||
| await loginPage.goto(); | ||
|
|
||
| // 1. Grab variables from the environment | ||
| const user = process.env.CLUSTER_USER || 'kubeadmin'; | ||
| const pass = process.env.CLUSTER_PASSWORD; | ||
| const idp = process.env.IDP || 'kube:admin'; | ||
|
|
||
| // 2. Fail loudly if the password is missing | ||
| if (!pass) { | ||
| throw new Error('CLUSTER_PASSWORD environment variable is missing. Cannot authenticate.'); | ||
| } | ||
|
|
||
| // 3. Pass them into the login method | ||
| await loginPage.loginViaOpenShift(user, pass, idp); | ||
|
|
||
| await use(page); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }, | ||
|
|
||
| //app setup/teardown | ||
| managedApp: [ async ({ page }, use) => { | ||
| const appName = `e2e-app-${Date.now()}`; | ||
| const appsPage = new ApplicationsPage(page); | ||
|
|
||
| console.log(`[setup] creating and syncing application: ${appName}`); | ||
| await appsPage.navigate(); | ||
| await appsPage.createApp( | ||
| appName, | ||
| 'https://github.com/redhat-developer/openshift-gitops-getting-started.git', | ||
| 'app' | ||
| ); | ||
| await appsPage.syncApplication(appName); | ||
| await appsPage.verifyStatus(appName); | ||
|
|
||
| //pass the name to the test | ||
| await use(appName); | ||
|
|
||
| //teardown | ||
| console.log(`[teardown] deleting ${appName} via api`); | ||
| const response = await page.request.delete(`/api/v1/applications/${appName}?cascade=true`, { | ||
| headers: { 'Content-Type': 'application/json' } | ||
| }); | ||
|
|
||
| // 4. Update the teardown to only ignore 404s, treating 403s as failures | ||
| if (response.status() === 404) { | ||
| return; | ||
| } else { | ||
| expect(response.status()).toBeLessThan(400); | ||
| } | ||
| }, { timeout: 120000 } ], | ||
| }); | ||
|
|
||
| //export it so spec files can use it | ||
| export { expect }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.