diff --git a/.github/workflows/on-push-main-playwright.yaml b/.github/workflows/on-push-main-playwright.yaml index 068dcbf6e..29b68a9e6 100644 --- a/.github/workflows/on-push-main-playwright.yaml +++ b/.github/workflows/on-push-main-playwright.yaml @@ -25,10 +25,14 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v5 with: - context: . + context: ./testing file: ./testing/PlaywrightContainerFile push: true tags: quay.io/kubev2v/forklift-ui-tests:latest + build-args: | + VERSION=${{ github.ref_name }} + GIT_COMMIT=${{ github.sha }} + BUILD_DATE=${{ github.event.head_commit.timestamp }} - name: Logout from Quay.io run: docker logout quay.io diff --git a/testing/PlaywrightContainerFile b/testing/PlaywrightContainerFile index aa27f6955..cd3ae8e6b 100644 --- a/testing/PlaywrightContainerFile +++ b/testing/PlaywrightContainerFile @@ -1,10 +1,39 @@ -FROM mcr.microsoft.com/playwright:latest +FROM mcr.microsoft.com/playwright:v1.55.0-noble -WORKDIR /e2e +ARG GIT_COMMIT=unknown +ARG BUILD_DATE=unknown +ARG VERSION=dev + +LABEL org.opencontainers.image.created="${BUILD_DATE}" \ + org.opencontainers.image.source="https://github.com/kubev2v/forklift-console-plugin" \ + org.opencontainers.image.version="${VERSION}" \ + org.opencontainers.image.revision="${GIT_COMMIT}" \ + org.opencontainers.image.title="MTV UI Tests" + +ENV LANG=en_US.UTF-8 \ + LANGUAGE=en_US:en \ + LC_ALL=en_US.UTF-8 \ + IMAGE_VERSION="${VERSION}" \ + IMAGE_GIT_COMMIT="${GIT_COMMIT}" \ + IMAGE_BUILD_DATE="${BUILD_DATE}" + +RUN apt-get update && \ + apt-get install -y --no-install-recommends locales && \ + rm -rf /var/lib/apt/lists/* && \ + locale-gen en_US.UTF-8 + +WORKDIR /test-runner + +COPY package.json yarn.lock ./ +RUN corepack enable && \ + yarn install --frozen-lockfile --ignore-scripts COPY . . -ENV BASE_ADDRESS="http://host.docker.internal:9000" +RUN chmod +x run-tests.sh && \ + chown -R 1001:0 /test-runner && \ + chmod -R g+w /test-runner + +USER 1001 -RUN yarn -RUN npx playwright install \ No newline at end of file +CMD ["./run-tests.sh"] diff --git a/testing/README.md b/testing/README.md index dbab509be..c5ed7d921 100644 --- a/testing/README.md +++ b/testing/README.md @@ -103,3 +103,24 @@ From the `testing` directory, run: ```bash yarn test:downstream:remote:docker ``` + +## Updating the Container Image + +To build and push the test container image manually: + +```bash +cd testing + +podman build \ + --no-cache \ + --platform linux/amd64 \ + --build-arg VERSION=main \ + --build-arg GIT_COMMIT=$(git rev-parse HEAD) \ + --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ + -f PlaywrightContainerFile \ + -t quay.io/kubev2v/forklift-ui-tests:latest \ + . + +podman login quay.io +podman quay.io/kubev2v/forklift-ui-tests:latest +``` diff --git a/testing/package.json b/testing/package.json index 07596dcb7..d511bd58e 100644 --- a/testing/package.json +++ b/testing/package.json @@ -13,8 +13,8 @@ "license": "ISC", "description": "", "devDependencies": { - "playwright": "1.54.2", - "@playwright/test": "1.54.2", + "playwright": "1.55.0", + "@playwright/test": "1.55.0", "@types/node": "^20.0.0", "typescript": "^5.8.2" }, diff --git a/testing/playwright.config.ts b/testing/playwright.config.ts index 557ed5647..5bf3340d2 100644 --- a/testing/playwright.config.ts +++ b/testing/playwright.config.ts @@ -12,9 +12,15 @@ export default defineConfig({ retries: process.env.GITHUB_ACTIONS ? 3 : 0, + reporter: [['list'], ['html', { open: 'never' }]], + use: { - actionTimeout: 5_000, - navigationTimeout: 10_000, + actionTimeout: 20_000, + navigationTimeout: 20_000, + }, + + expect: { + timeout: 20_000, }, projects: [ @@ -30,6 +36,7 @@ export default defineConfig({ viewport: { width: 1920, height: 1080 }, screenshot: 'only-on-failure', video: 'retain-on-failure', + trace: 'retain-on-failure', // Use data-testid to match actual rendered HTML testIdAttribute: 'data-testid', ignoreHTTPSErrors: true, diff --git a/testing/run-tests.sh b/testing/run-tests.sh new file mode 100644 index 000000000..dbdf9276b --- /dev/null +++ b/testing/run-tests.sh @@ -0,0 +1,88 @@ +#!/bin/bash +set -e + +# ============================================================================== +# Script for running Playwright tests in a containerized environment. +# +# This script uses pre-copied test files from the local repository and +# executes Playwright tests based on environment variables. +# +# Required Environment Variables: +# - CLUSTER_NAME: Name of the OpenShift cluster to target. +# - VSPHERE_PROVIDER: vSphere provider to use for testing. +# - TEST_ARGS: (Optional) Arbitrary arguments for the playwright command. +# - CLUSTER_PASSWORD: The password for the OCP cluster. +# - PROVIDERS_JSON: The content of the .providers.json file. +# +# Mounted Volumes: +# - /results: Directory to store test artifacts (reports, results). +# +# ============================================================================== + +# --- Configuration and Defaults --- +# Use /results if WORKSPACE is not set (for container environment) +RESULTS_DIR="${WORKSPACE:-/results}" +TEST_ARGS=${TEST_ARGS:-"--grep=@downstream"} + +log() { + echo "--- $1 ---" +} + +log "Container Image Information" +echo " Version: ${IMAGE_VERSION:-unknown}" +echo " Git Commit: ${IMAGE_GIT_COMMIT:-unknown}" +echo " Build Date: ${IMAGE_BUILD_DATE:-unknown}" +echo "" + +cd /test-runner + +log "Validating environment and setting up credentials..." + +if [ -z "$CLUSTER_NAME" ]; then + echo "ERROR: CLUSTER_NAME environment variable is not set." + exit 1 +fi + +if [ -z "$PROVIDERS_JSON" ]; then + echo "ERROR: PROVIDERS_JSON environment variable is not set." + exit 1 +fi + +if [ -z "$CLUSTER_PASSWORD" ]; then + echo "ERROR: CLUSTER_PASSWORD environment variable is not set." + exit 1 +fi + +log "Validation complete. Using pre-copied test files from /test-runner" + +log "Creating .providers.json from environment variable..." +echo "$PROVIDERS_JSON" > .providers.json + +export BASE_ADDRESS="https://console-openshift-console.apps.${CLUSTER_NAME}.rhos-psi.cnv-qe.rhood.us" +export CI=true +export JENKINS=true +export NODE_TLS_REJECT_UNAUTHORIZED=0 +export CLUSTER_USERNAME="kubeadmin" +export CLUSTER_PASSWORD=${CLUSTER_PASSWORD} +export VSPHERE_PROVIDER=${VSPHERE_PROVIDER} + +log "Running Playwright tests..." +echo " Cluster: ${CLUSTER_NAME}" +echo " Base Address: ${BASE_ADDRESS}" +echo " Playwright Args: ${TEST_ARGS}" + + +set +e +echo "Starting Playwright test execution..." +yarn playwright test \ + ${TEST_ARGS} +TEST_EXIT_CODE=$? +set -e + +log "Tests finished with exit code: $TEST_EXIT_CODE" + +mkdir -p "${RESULTS_DIR}" +[ -d "playwright-report" ] && cp -r "playwright-report" "${RESULTS_DIR}/" +[ -d "test-results" ] && cp -r "test-results" "${RESULTS_DIR}/" + +exit $TEST_EXIT_CODE diff --git a/testing/yarn.lock b/testing/yarn.lock index 92730eb79..5b03821ee 100644 --- a/testing/yarn.lock +++ b/testing/yarn.lock @@ -4,15 +4,15 @@ "@kubev2v/types@0.0.22": version "0.0.22" - resolved "https://registry.yarnpkg.com/@kubev2v/types/-/types-0.0.22.tgz#582091a79cdb159be7789dcd62a2632542592c60" + resolved "https://registry.npmjs.org/@kubev2v/types/-/types-0.0.22.tgz" integrity sha512-1s2RhE9zPf2esJzcy0KCbcso4SJE2Mp9ObV3We0c8KCGvp8i42xCxBIV9vMDiM14ZRlCUMo7gGB9GdZvexDURg== -"@playwright/test@1.54.2": - version "1.54.2" - resolved "https://registry.npmjs.org/@playwright/test/-/test-1.54.2.tgz" - integrity sha512-A+znathYxPf+72riFd1r1ovOLqsIIB0jKIoPjyK2kqEIe30/6jF6BC7QNluHuwUmsD2tv1XZVugN8GqfTMOxsA== +"@playwright/test@1.55.0": + version "1.55.0" + resolved "https://registry.npmjs.org/@playwright/test/-/test-1.55.0.tgz" + integrity sha512-04IXzPwHrW69XusN/SIdDdKZBzMfOT9UNT/YiJit/xpy2VuAoB8NHc8Aplb96zsWDddLnbkPL3TsmrS04ZU2xQ== dependencies: - playwright "1.54.2" + playwright "1.55.0" "@types/node@^20.0.0": version "20.19.9" @@ -26,17 +26,17 @@ fsevents@2.3.2: resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== -playwright-core@1.54.2: - version "1.54.2" - resolved "https://registry.npmjs.org/playwright-core/-/playwright-core-1.54.2.tgz" - integrity sha512-n5r4HFbMmWsB4twG7tJLDN9gmBUeSPcsBZiWSE4DnYz9mJMAFqr2ID7+eGC9kpEnxExJ1epttwR59LEWCk8mtA== +playwright-core@1.55.0: + version "1.55.0" + resolved "https://registry.npmjs.org/playwright-core/-/playwright-core-1.55.0.tgz" + integrity sha512-GvZs4vU3U5ro2nZpeiwyb0zuFaqb9sUiAJuyrWpcGouD8y9/HLgGbNRjIph7zU9D3hnPaisMl9zG9CgFi/biIg== -playwright@1.54.2: - version "1.54.2" - resolved "https://registry.npmjs.org/playwright/-/playwright-1.54.2.tgz" - integrity sha512-Hu/BMoA1NAdRUuulyvQC0pEqZ4vQbGfn8f7wPXcnqQmM+zct9UliKxsIkLNmz/ku7LElUNqmaiv1TG/aL5ACsw== +playwright@1.55.0: + version "1.55.0" + resolved "https://registry.npmjs.org/playwright/-/playwright-1.55.0.tgz" + integrity sha512-sdCWStblvV1YU909Xqx0DhOjPZE4/5lJsIS84IfN9dAZfcl/CIZ5O8l3o0j7hPMjDvqoTF8ZUcc+i/GL5erstA== dependencies: - playwright-core "1.54.2" + playwright-core "1.55.0" optionalDependencies: fsevents "2.3.2"