|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# ============================================================================== |
| 5 | +# Script for running Playwright tests in a containerized environment. |
| 6 | +# |
| 7 | +# This script uses pre-copied test files from the local repository and |
| 8 | +# executes Playwright tests based on environment variables. |
| 9 | +# |
| 10 | +# Required Environment Variables: |
| 11 | +# - CLUSTER_NAME: Name of the OpenShift cluster to target. |
| 12 | +# - VSPHERE_PROVIDER: vSphere provider to use for testing. |
| 13 | +# - TEST_ARGS: (Optional) Arbitrary arguments for the playwright command. |
| 14 | +# - CLUSTER_PASSWORD: The password for the OCP cluster. |
| 15 | +# - PROVIDERS_JSON: The content of the .providers.json file. |
| 16 | +# |
| 17 | +# Mounted Volumes: |
| 18 | +# - /results: Directory to store test artifacts (reports, results). |
| 19 | +# |
| 20 | +# ============================================================================== |
| 21 | + |
| 22 | +# --- Configuration and Defaults --- |
| 23 | +# Use /results if WORKSPACE is not set (for container environment) |
| 24 | +RESULTS_DIR="${WORKSPACE:-/results}" |
| 25 | +TEST_ARGS=${TEST_ARGS:-"--grep=@downstream"} |
| 26 | + |
| 27 | +log() { |
| 28 | + echo "--- $1 ---" |
| 29 | +} |
| 30 | + |
| 31 | +log "Container Image Information" |
| 32 | +echo " Version: ${IMAGE_VERSION:-unknown}" |
| 33 | +echo " Git Commit: ${IMAGE_GIT_COMMIT:-unknown}" |
| 34 | +echo " Build Date: ${IMAGE_BUILD_DATE:-unknown}" |
| 35 | +echo "" |
| 36 | + |
| 37 | +cd /test-runner |
| 38 | + |
| 39 | +log "Validating environment and setting up credentials..." |
| 40 | + |
| 41 | +if [ -z "$CLUSTER_NAME" ]; then |
| 42 | + echo "ERROR: CLUSTER_NAME environment variable is not set." |
| 43 | + exit 1 |
| 44 | +fi |
| 45 | + |
| 46 | +if [ -z "$PROVIDERS_JSON" ]; then |
| 47 | + echo "ERROR: PROVIDERS_JSON environment variable is not set." |
| 48 | + exit 1 |
| 49 | +fi |
| 50 | + |
| 51 | +if [ -z "$CLUSTER_PASSWORD" ]; then |
| 52 | + echo "ERROR: CLUSTER_PASSWORD environment variable is not set." |
| 53 | + exit 1 |
| 54 | +fi |
| 55 | + |
| 56 | +log "Validation complete. Using pre-copied test files from /test-runner" |
| 57 | + |
| 58 | +log "Creating .providers.json from environment variable..." |
| 59 | +echo "$PROVIDERS_JSON" > .providers.json |
| 60 | + |
| 61 | +export BASE_ADDRESS="https://console-openshift-console.apps.${CLUSTER_NAME}.rhos-psi.cnv-qe.rhood.us" |
| 62 | +export CI=true |
| 63 | +export JENKINS=true |
| 64 | +export NODE_TLS_REJECT_UNAUTHORIZED=0 |
| 65 | +export CLUSTER_USERNAME="kubeadmin" |
| 66 | +export CLUSTER_PASSWORD=${CLUSTER_PASSWORD} |
| 67 | +export VSPHERE_PROVIDER=${VSPHERE_PROVIDER} |
| 68 | + |
| 69 | +log "Running Playwright tests..." |
| 70 | +echo " Cluster: ${CLUSTER_NAME}" |
| 71 | +echo " Base Address: ${BASE_ADDRESS}" |
| 72 | +echo " Playwright Args: ${TEST_ARGS}" |
| 73 | + |
| 74 | + |
| 75 | +set +e |
| 76 | +echo "Starting Playwright test execution..." |
| 77 | +yarn playwright test \ |
| 78 | + ${TEST_ARGS} |
| 79 | +TEST_EXIT_CODE=$? |
| 80 | +set -e |
| 81 | + |
| 82 | +log "Tests finished with exit code: $TEST_EXIT_CODE" |
| 83 | + |
| 84 | +mkdir -p "${RESULTS_DIR}" |
| 85 | +[ -d "playwright-report" ] && cp -r "playwright-report" "${RESULTS_DIR}/" |
| 86 | +[ -d "test-results" ] && cp -r "test-results" "${RESULTS_DIR}/" |
| 87 | + |
| 88 | +exit $TEST_EXIT_CODE |
0 commit comments