From 47f11101d5e8ff3a66c2cd2b49283aa12ac43859 Mon Sep 17 00:00:00 2001 From: Vikram Raj Date: Wed, 29 Apr 2026 19:27:38 +0530 Subject: [PATCH 1/2] Add prow playwright e2e script --- .../integration-tests/test-playwright-e2e.sh | 122 ++++++++++++++++++ test-prow-playwright-e2e.sh | 55 ++++++++ 2 files changed, 177 insertions(+) create mode 100755 frontend/integration-tests/test-playwright-e2e.sh create mode 100644 test-prow-playwright-e2e.sh diff --git a/frontend/integration-tests/test-playwright-e2e.sh b/frontend/integration-tests/test-playwright-e2e.sh new file mode 100755 index 00000000000..dba6f82d217 --- /dev/null +++ b/frontend/integration-tests/test-playwright-e2e.sh @@ -0,0 +1,122 @@ +#!/usr/bin/env bash +# +# Run Playwright E2E tests against OpenShift Console from the frontend workspace. +# Same operational idea as test-cypress.sh: run from ./frontend, optional cluster-derived +# BRIDGE_* / PLAYWRIGHT_BASE_URL, optional kubeadmin + create-user, then invoke Playwright +# in frontend/ or a subdirectory package. +# +# Prerequisites (typical): +# - oc logged in (unless BRIDGE_BASE_ADDRESS is already set) +# - In the target directory: yarn add -D @playwright/test && yarn playwright install +# - playwright.config.{ts,js,mts,mjs} under that directory +# +# Usage (always from repo frontend/): +# ./integration-tests/test-playwright-e2e.sh [playwright test arguments...] +# ./integration-tests/test-playwright-e2e.sh -d packages/my-plugin/e2e tests/smoke.spec.ts +# ./integration-tests/test-playwright-e2e.sh -c +# +# Options: +# -d Directory relative to frontend/ where Playwright is installed (default: .) +# -c Run contrib/create-user.sh first (Prow-style htpasswd idp; needs repo root) +# +# Environment: +# BRIDGE_BASE_ADDRESS If unset, from oc get consoles.config.openshift.io cluster +# BRIDGE_BASE_PATH Default / +# PLAYWRIGHT_BASE_URL Default ${BRIDGE_BASE_ADDRESS}${BRIDGE_BASE_PATH} +# INSTALLER_DIR, ARTIFACT_DIR, KUBEADMIN_PASSWORD_FILE Kubeadmin password for login flows +# OPENSHIFT_CI If true, sets NO_COLOR=1 (same as test-cypress.sh) +# + +set -euo pipefail + +ARTIFACT_DIR=${ARTIFACT_DIR:-/tmp/artifacts} +INSTALLER_DIR=${INSTALLER_DIR:-${ARTIFACT_DIR}/installer} +OPENSHIFT_CI=${OPENSHIFT_CI:-false} + +if [ "$(basename "$(pwd)")" != "frontend" ]; then + echo "This script must be run from the frontend folder" >&2 + exit 1 +fi + +if [ "$OPENSHIFT_CI" = true ]; then + export NO_COLOR=1 +fi + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# integration-tests/ -> frontend/ -> openshift/console repo root +REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" + +if [ -z "${BRIDGE_KUBEADMIN_PASSWORD:-}" ]; then + pass_file="${KUBEADMIN_PASSWORD_FILE:-${INSTALLER_DIR}/auth/kubeadmin-password}" + if [ -f "$pass_file" ]; then + set +x + export BRIDGE_KUBEADMIN_PASSWORD="$(cat "$pass_file")" + set -x + fi +fi + +if [ -z "${BRIDGE_BASE_ADDRESS:-}" ]; then + if ! command -v oc >/dev/null 2>&1; then + echo "error: BRIDGE_BASE_ADDRESS is unset and oc was not found in PATH." >&2 + exit 1 + fi + if ! BRIDGE_BASE_ADDRESS="$(oc get consoles.config.openshift.io cluster -o jsonpath='{.status.consoleURL}' 2>/dev/null)" || + [ -z "$BRIDGE_BASE_ADDRESS" ]; then + echo "error: BRIDGE_BASE_ADDRESS is unset and oc could not read consoles.config.openshift.io cluster status.consoleURL." >&2 + echo " Log in with oc or export BRIDGE_BASE_ADDRESS (e.g. http://localhost:9000)." >&2 + exit 1 + fi + export BRIDGE_BASE_ADDRESS +fi + +BRIDGE_BASE_PATH=${BRIDGE_BASE_PATH:-/} +export BRIDGE_BASE_PATH +export PLAYWRIGHT_BASE_URL="${PLAYWRIGHT_BASE_URL:-${BRIDGE_BASE_ADDRESS}${BRIDGE_BASE_PATH}}" + +PLAYWRIGHT_REL_DIR="." +RUN_CREATE_USER=false +while getopts "d:c" flag; do + case "${flag}" in + d) PLAYWRIGHT_REL_DIR="${OPTARG}" ;; + c) RUN_CREATE_USER=true ;; + *) echo "Usage: $0 [-d ] [-c] [--] [playwright test args...]" >&2 + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +if [ ! -d node_modules ]; then + yarn install +fi + +if [ "$RUN_CREATE_USER" = true ]; then + "${REPO_ROOT}/contrib/create-user.sh" +fi + +FRONTEND_ABS="$(pwd)" +TARGET_DIR="${FRONTEND_ABS}/${PLAYWRIGHT_REL_DIR}" +if [ ! -d "$TARGET_DIR" ]; then + echo "error: Playwright directory does not exist: $TARGET_DIR" >&2 + exit 1 +fi +TARGET_DIR="$(cd "$TARGET_DIR" && pwd)" +if [[ "${TARGET_DIR}" != "${FRONTEND_ABS}" && "${TARGET_DIR}" != "${FRONTEND_ABS}/"* ]]; then + echo "error: resolved path must stay under ${FRONTEND_ABS}" >&2 + exit 1 +fi + +cd "$TARGET_DIR" + +playwright_bin="${TARGET_DIR}/node_modules/.bin/playwright" +if [ ! -f "$playwright_bin" ]; then + # When running from a subfolder without its own node_modules, fall back to frontend root bin + playwright_bin="${FRONTEND_ABS}/node_modules/.bin/playwright" +fi +if [ ! -f "$playwright_bin" ]; then + echo "error: Playwright CLI not found. Install in $TARGET_DIR or frontend root:" >&2 + echo " yarn add -D @playwright/test && yarn playwright install" >&2 + exit 1 +fi + +exec "$playwright_bin" test "$@" diff --git a/test-prow-playwright-e2e.sh b/test-prow-playwright-e2e.sh new file mode 100644 index 00000000000..db7aead8679 --- /dev/null +++ b/test-prow-playwright-e2e.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +# +# Prow / CI entrypoint for Playwright E2E against a live OpenShift cluster console. +# Mirrors test-prow-e2e.sh: kubeadmin password, BRIDGE_BASE_ADDRESS from the cluster, +# contrib/create-user.sh, then tests under frontend/, and the same CSP check as Cypress Prow. +# +# Run from the openshift/console repository root (same as test-prow-e2e.sh). +# +# Usage: +# ./test-prow-playwright-e2e.sh [e2e|release|smoke] [arguments passed to: playwright test ...] +# +# Scenarios (first argument; default: e2e): +# e2e, release — full Playwright suite (default project / config) +# smoke — only e2e smoke specs +# +# Environment (typical Prow / installer): +# ARTIFACT_DIR, INSTALLER_DIR, KUBEADMIN_PASSWORD_FILE same as test-prow-e2e.sh +# OPENSHIFT_CI forwarded to frontend test-playwright-e2e.sh (NO_COLOR when true) +# + +set -exuo pipefail + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "${REPO_ROOT}" + +ARTIFACT_DIR=${ARTIFACT_DIR:-/tmp/artifacts} +INSTALLER_DIR=${INSTALLER_DIR:=${ARTIFACT_DIR}/installer} + +# don't log kubeadmin-password +set +x +export BRIDGE_KUBEADMIN_PASSWORD="$(cat "${KUBEADMIN_PASSWORD_FILE:-${INSTALLER_DIR}/auth/kubeadmin-password}")" +set -x +export BRIDGE_BASE_ADDRESS="$(oc get consoles.config.openshift.io cluster -o jsonpath='{.status.consoleURL}')" + +./contrib/create-user.sh + +pushd frontend + +SCENARIO="${1:-e2e}" +if [ $# -gt 0 ]; then + shift +fi + +if [ "$SCENARIO" == "e2e" ] || [ "$SCENARIO" == "release" ]; then + ./integration-tests/test-playwright-e2e.sh "$@" +elif [ "$SCENARIO" == "smoke" ]; then + ./integration-tests/test-playwright-e2e.sh e2e/tests/smoke "$@" +else + echo "error: unknown scenario '$SCENARIO' (use: e2e, release, or smoke)" >&2 + exit 1 +fi + +env NO_SANDBOX=true yarn test-puppeteer-csp + +popd From 1fb30660b01d496c86e98606c9294b3959276b0e Mon Sep 17 00:00:00 2001 From: Vikram Raj Date: Wed, 29 Apr 2026 19:39:41 +0530 Subject: [PATCH 2/2] CONSOLE-5197: Add package selection and yarn scripts for Playwright E2E tests Enhance the Playwright E2E test infrastructure with package selection similar to the existing Cypress workflow, plus convenience yarn scripts. **Package Selection**: - Add -p flag to run tests for specific packages (console, olm, dev-console, etc.) - Add -l flag to list available package IDs and their paths - Support 10 packages: console, olm, dev-console, shipwright, webterminal, telemetry, knative, helm, topology, container-security - Mutual exclusion validation between -p and -d flags **Yarn Scripts**: - Add test-playwright-e2e (run from frontend root) - Add test-playwright-e2e-list (show available packages) - Add test-playwright-{package} scripts for all 10 supported packages **Breaking Change**: - Rename PLAYWRIGHT_BASE_URL to WEB_CONSOLE_URL for consistency with test-cypress.sh. Scripts using PLAYWRIGHT_BASE_URL will need to update. **Other Changes**: - Simplify usage documentation - Move option parsing before environment setup for better UX Co-Authored-By: Claude Sonnet 4.5 --- .../integration-tests/test-playwright-e2e.sh | 129 ++++++++++++------ frontend/package.json | 12 ++ 2 files changed, 98 insertions(+), 43 deletions(-) diff --git a/frontend/integration-tests/test-playwright-e2e.sh b/frontend/integration-tests/test-playwright-e2e.sh index dba6f82d217..2eaf7f7a639 100755 --- a/frontend/integration-tests/test-playwright-e2e.sh +++ b/frontend/integration-tests/test-playwright-e2e.sh @@ -1,57 +1,114 @@ #!/usr/bin/env bash # # Run Playwright E2E tests against OpenShift Console from the frontend workspace. -# Same operational idea as test-cypress.sh: run from ./frontend, optional cluster-derived -# BRIDGE_* / PLAYWRIGHT_BASE_URL, optional kubeadmin + create-user, then invoke Playwright -# in frontend/ or a subdirectory package. +# Same operational idea as test-cypress.sh: run from ./frontend, cluster BRIDGE_* / +# WEB_CONSOLE_URL, optional create-user, then Playwright in the root e2e/ tree or +# a package integration-tests directory. # -# Prerequisites (typical): -# - oc logged in (unless BRIDGE_BASE_ADDRESS is already set) -# - In the target directory: yarn add -D @playwright/test && yarn playwright install -# - playwright.config.{ts,js,mts,mjs} under that directory -# -# Usage (always from repo frontend/): -# ./integration-tests/test-playwright-e2e.sh [playwright test arguments...] -# ./integration-tests/test-playwright-e2e.sh -d packages/my-plugin/e2e tests/smoke.spec.ts +# Usage (from repo frontend/): +# ./integration-tests/test-playwright-e2e.sh [playwright test args...] +# ./integration-tests/test-playwright-e2e.sh -l +# ./integration-tests/test-playwright-e2e.sh -p [playwright test args...] +# ./integration-tests/test-playwright-e2e.sh -d [playwright test args...] # ./integration-tests/test-playwright-e2e.sh -c # -# Options: -# -d Directory relative to frontend/ where Playwright is installed (default: .) -# -c Run contrib/create-user.sh first (Prow-style htpasswd idp; needs repo root) +# -p Shorthand for a packages/*/integration-tests working directory (see -l). +# -d Explicit directory under frontend/ (default: .). Do not combine with -p. # # Environment: -# BRIDGE_BASE_ADDRESS If unset, from oc get consoles.config.openshift.io cluster -# BRIDGE_BASE_PATH Default / -# PLAYWRIGHT_BASE_URL Default ${BRIDGE_BASE_ADDRESS}${BRIDGE_BASE_PATH} -# INSTALLER_DIR, ARTIFACT_DIR, KUBEADMIN_PASSWORD_FILE Kubeadmin password for login flows -# OPENSHIFT_CI If true, sets NO_COLOR=1 (same as test-cypress.sh) +# BRIDGE_BASE_ADDRESS, BRIDGE_BASE_PATH, WEB_CONSOLE_URL +# INSTALLER_DIR, ARTIFACT_DIR, KUBEADMIN_PASSWORD_FILE # set -euo pipefail ARTIFACT_DIR=${ARTIFACT_DIR:-/tmp/artifacts} INSTALLER_DIR=${INSTALLER_DIR:-${ARTIFACT_DIR}/installer} -OPENSHIFT_CI=${OPENSHIFT_CI:-false} if [ "$(basename "$(pwd)")" != "frontend" ]; then echo "This script must be run from the frontend folder" >&2 exit 1 fi -if [ "$OPENSHIFT_CI" = true ]; then - export NO_COLOR=1 -fi - SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -# integration-tests/ -> frontend/ -> openshift/console repo root REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" +# Resolve -p to a path under frontend/ (aligned with test-cypress.sh package names). +playwright_package_to_dir() { + case "$1" in + console) echo "packages/integration-tests" ;; + olm) echo "packages/operator-lifecycle-manager/integration-tests" ;; + dev-console) echo "packages/dev-console/integration-tests" ;; + shipwright) echo "packages/shipwright-plugin/integration-tests" ;; + webterminal) echo "packages/webterminal-plugin/integration-tests" ;; + telemetry) echo "packages/console-telemetry-plugin/integration-tests" ;; + knative) echo "packages/knative-plugin/integration-tests" ;; + helm) echo "packages/helm-plugin/integration-tests" ;; + topology) echo "packages/topology/integration-tests" ;; + container-security) echo "packages/container-security/integration-tests" ;; + *) + return 1 + ;; + esac +} + +list_playwright_packages() { + echo "Playwright -p package ids (paths under frontend/):" + echo " console -> packages/integration-tests" + echo " olm -> packages/operator-lifecycle-manager/integration-tests" + echo " dev-console -> packages/dev-console/integration-tests" + echo " shipwright -> packages/shipwright-plugin/integration-tests" + echo " webterminal -> packages/webterminal-plugin/integration-tests" + echo " telemetry -> packages/console-telemetry-plugin/integration-tests" + echo " knative -> packages/knative-plugin/integration-tests" + echo " helm -> packages/helm-plugin/integration-tests" + echo " topology -> packages/topology/integration-tests" + echo " container-security -> packages/container-security/integration-tests" + echo "Default (no -p/-d): -> . (frontend root; e.g. e2e/ when configured)" +} + +PLAYWRIGHT_REL_DIR="." +RUN_CREATE_USER=false +PLAYWRIGHT_PKG="" +LIST_ONLY=false + +while getopts "cd:lp:" flag; do + case "${flag}" in + c) RUN_CREATE_USER=true ;; + d) PLAYWRIGHT_REL_DIR="${OPTARG}" ;; + l) LIST_ONLY=true ;; + p) PLAYWRIGHT_PKG="${OPTARG}" ;; + *) + echo "Usage: $0 [-l] [-p |-d ] [-c] [--] [playwright test args...]" >&2 + echo "Run $0 -l for package ids." >&2 + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +if [ "$LIST_ONLY" = true ]; then + list_playwright_packages + exit 0 +fi + +if [ -n "$PLAYWRIGHT_PKG" ] && [ "$PLAYWRIGHT_REL_DIR" != "." ]; then + echo "error: use only one of -p or -d , not both." >&2 + exit 1 +fi + +if [ -n "$PLAYWRIGHT_PKG" ]; then + if ! resolved="$(playwright_package_to_dir "$PLAYWRIGHT_PKG")"; then + echo "error: unknown package '$PLAYWRIGHT_PKG'. Run $0 -l for valid ids." >&2 + exit 1 + fi + PLAYWRIGHT_REL_DIR="$resolved" +fi + if [ -z "${BRIDGE_KUBEADMIN_PASSWORD:-}" ]; then pass_file="${KUBEADMIN_PASSWORD_FILE:-${INSTALLER_DIR}/auth/kubeadmin-password}" if [ -f "$pass_file" ]; then - set +x export BRIDGE_KUBEADMIN_PASSWORD="$(cat "$pass_file")" - set -x fi fi @@ -71,20 +128,7 @@ fi BRIDGE_BASE_PATH=${BRIDGE_BASE_PATH:-/} export BRIDGE_BASE_PATH -export PLAYWRIGHT_BASE_URL="${PLAYWRIGHT_BASE_URL:-${BRIDGE_BASE_ADDRESS}${BRIDGE_BASE_PATH}}" - -PLAYWRIGHT_REL_DIR="." -RUN_CREATE_USER=false -while getopts "d:c" flag; do - case "${flag}" in - d) PLAYWRIGHT_REL_DIR="${OPTARG}" ;; - c) RUN_CREATE_USER=true ;; - *) echo "Usage: $0 [-d ] [-c] [--] [playwright test args...]" >&2 - exit 1 - ;; - esac -done -shift $((OPTIND - 1)) +export WEB_CONSOLE_URL="${WEB_CONSOLE_URL:-${BRIDGE_BASE_ADDRESS}${BRIDGE_BASE_PATH}}" if [ ! -d node_modules ]; then yarn install @@ -110,11 +154,10 @@ cd "$TARGET_DIR" playwright_bin="${TARGET_DIR}/node_modules/.bin/playwright" if [ ! -f "$playwright_bin" ]; then - # When running from a subfolder without its own node_modules, fall back to frontend root bin playwright_bin="${FRONTEND_ABS}/node_modules/.bin/playwright" fi if [ ! -f "$playwright_bin" ]; then - echo "error: Playwright CLI not found. Install in $TARGET_DIR or frontend root:" >&2 + echo "error: Playwright CLI not found. Install at frontend root:" >&2 echo " yarn add -D @playwright/test && yarn playwright install" >&2 exit 1 fi diff --git a/frontend/package.json b/frontend/package.json index 8c41d94edc6..fded747487e 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -49,6 +49,18 @@ "test-cypress-topology": "cd packages/topology/integration-tests && yarn run test-cypress", "test-cypress-topology-headless": "cd packages/topology/integration-tests && yarn run test-cypress-headless", "test-cypress-topology-nightly": "cd packages/topology/integration-tests && yarn run test-cypress-headless-all", + "test-playwright-e2e": "./integration-tests/test-playwright-e2e.sh", + "test-playwright-e2e-list": "./integration-tests/test-playwright-e2e.sh -l", + "test-playwright-console": "./integration-tests/test-playwright-e2e.sh -p console", + "test-playwright-olm": "./integration-tests/test-playwright-e2e.sh -p olm", + "test-playwright-dev-console": "./integration-tests/test-playwright-e2e.sh -p dev-console", + "test-playwright-shipwright": "./integration-tests/test-playwright-e2e.sh -p shipwright", + "test-playwright-webterminal": "./integration-tests/test-playwright-e2e.sh -p webterminal", + "test-playwright-telemetry": "./integration-tests/test-playwright-e2e.sh -p telemetry", + "test-playwright-knative": "./integration-tests/test-playwright-e2e.sh -p knative", + "test-playwright-helm": "./integration-tests/test-playwright-e2e.sh -p helm", + "test-playwright-topology": "./integration-tests/test-playwright-e2e.sh -p topology", + "test-playwright-container-security": "./integration-tests/test-playwright-e2e.sh -p container-security", "test-puppeteer-csp": "yarn ts-node ./test-puppeteer-csp.ts", "cypress-merge": "mochawesome-merge ./gui_test_screenshots/cypress_report*.json > ./gui_test_screenshots/cypress.json", "cypress-generate": "marge -o ./gui_test_screenshots/ -f cypress-report -t 'OpenShift Console Cypress Test Results' -p 'OpenShift Cypress Test Results' --showPassed false --assetsDir ./gui_test_screenshots/cypress/assets ./gui_test_screenshots/cypress.json",