diff --git a/frontend/integration-tests/test-playwright-e2e.sh b/frontend/integration-tests/test-playwright-e2e.sh new file mode 100755 index 00000000000..2eaf7f7a639 --- /dev/null +++ b/frontend/integration-tests/test-playwright-e2e.sh @@ -0,0 +1,165 @@ +#!/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, cluster BRIDGE_* / +# WEB_CONSOLE_URL, optional create-user, then Playwright in the root e2e/ tree or +# a package integration-tests directory. +# +# 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 +# +# -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, 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} + +if [ "$(basename "$(pwd)")" != "frontend" ]; then + echo "This script must be run from the frontend folder" >&2 + exit 1 +fi + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +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 + export BRIDGE_KUBEADMIN_PASSWORD="$(cat "$pass_file")" + 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 WEB_CONSOLE_URL="${WEB_CONSOLE_URL:-${BRIDGE_BASE_ADDRESS}${BRIDGE_BASE_PATH}}" + +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 + playwright_bin="${FRONTEND_ABS}/node_modules/.bin/playwright" +fi +if [ ! -f "$playwright_bin" ]; then + echo "error: Playwright CLI not found. Install at 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