-
Notifications
You must be signed in to change notification settings - Fork 700
CONSOLE-5197: Add Playwright E2E test infrastructure for Prow/CI #16374
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
vikram-raj
wants to merge
2
commits into
openshift:main
Choose a base branch
from
vikram-raj:prow-playwright-e2e
base: main
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.
+232
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| 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 "$@" | ||
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,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 |
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.
There was a problem hiding this comment.
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.jsonas we do in Cypress?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see package.json in https://github.com/openshift/console/pull/16320/changes