Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 165 additions & 0 deletions frontend/integration-tests/test-playwright-e2e.sh
Original file line number Diff line number Diff line change
@@ -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 <package> [playwright test args...]
# ./integration-tests/test-playwright-e2e.sh -d <path-under-frontend> [playwright test args...]
# ./integration-tests/test-playwright-e2e.sh -c
#
# -p <package> Shorthand for a packages/*/integration-tests working directory (see -l).
# -d <path> 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 <name> 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 <package>|-d <dir-under-frontend>] [-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 <package> or -d <path>, 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 "$@"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we build a set of scripts defined in package.json as we do in Cypress?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

12 changes: 12 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
55 changes: 55 additions & 0 deletions test-prow-playwright-e2e.sh
Original file line number Diff line number Diff line change
@@ -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