From 1ead4562ca84148cec72808daf05de768a5027a6 Mon Sep 17 00:00:00 2001 From: ramakrishnajangatisetty Date: Sat, 28 Jun 2025 14:22:25 -0500 Subject: [PATCH 01/12] Use multi-stage builds to keep the image smaller. Clean up unnecessary files after install to reduce image size. --- Dockerfile.playwright | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/Dockerfile.playwright b/Dockerfile.playwright index 4c5b9f1..051c0f9 100644 --- a/Dockerfile.playwright +++ b/Dockerfile.playwright @@ -1,30 +1,41 @@ -FROM mcr.microsoft.com/playwright:v1.53.1-jammy +# === Stage 1: Build and install dependencies === +FROM mcr.microsoft.com/playwright:v1.53.1-jammy AS builder -# Install Java 11 (required for Allure) +# Install Java & Allure RUN apt-get update && apt-get install -y wget gnupg2 && \ wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor -o /usr/share/keyrings/adoptium.gpg && \ echo "deb [signed-by=/usr/share/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb focal main" | tee /etc/apt/sources.list.d/adoptium.list && \ apt-get update && apt-get install -y temurin-11-jdk && \ + npm install -g allure-commandline --force && \ rm -rf /var/lib/apt/lists/* -# Install Allure CLI globally -RUN npm install -g allure-commandline --force - -# Set JAVA_HOME for Allure +# Set up env ENV JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64 ENV PATH=$JAVA_HOME/bin:$PATH -# Set working directory WORKDIR /app - -# Copy only package files first to cache layer COPY package*.json ./ +RUN npm install + +# === Stage 2: Final image === +FROM mcr.microsoft.com/playwright:v1.53.1-jammy -# Install Node dependencies -RUN npm ci +# Copy Java, Allure, and installed node_modules from builder +COPY --from=builder /usr/lib/jvm/temurin-11-jdk-amd64 /usr/lib/jvm/temurin-11-jdk-amd64 +COPY --from=builder /usr/share/keyrings/adoptium.gpg /usr/share/keyrings/adoptium.gpg +COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules +COPY --from=builder /usr/local/bin/allure /usr/local/bin/allure +COPY --from=builder /app/node_modules /app/node_modules -# Copy the rest of the application +# Set up env again +ENV JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64 +ENV PATH=$JAVA_HOME/bin:$PATH + +WORKDIR /app COPY . . +COPY env ./env + +# Clean unnecessary files +RUN rm -rf /root/.cache /root/.npm /tmp/* -# Default CMD is overridden by GitHub Action's docker run step CMD ["npm", "run", "test:allure"] From 194581775cdf3e2e24832f73f51050caa8b400b0 Mon Sep 17 00:00:00 2001 From: ramakrishnajangatisetty Date: Sat, 28 Jun 2025 14:25:56 -0500 Subject: [PATCH 02/12] Use multi-stage builds to keep the image smaller. Clean up unnecessary files after install to reduce image size. --- Dockerfile.playwright | 48 ++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/Dockerfile.playwright b/Dockerfile.playwright index 051c0f9..5f8bec0 100644 --- a/Dockerfile.playwright +++ b/Dockerfile.playwright @@ -1,41 +1,51 @@ -# === Stage 1: Build and install dependencies === -FROM mcr.microsoft.com/playwright:v1.53.1-jammy AS builder +# ---- Build Stage ---- +FROM mcr.microsoft.com/playwright:v1.53.1-jammy AS build -# Install Java & Allure +# Install Java 11 (required for Allure) RUN apt-get update && apt-get install -y wget gnupg2 && \ wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor -o /usr/share/keyrings/adoptium.gpg && \ echo "deb [signed-by=/usr/share/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb focal main" | tee /etc/apt/sources.list.d/adoptium.list && \ apt-get update && apt-get install -y temurin-11-jdk && \ - npm install -g allure-commandline --force && \ rm -rf /var/lib/apt/lists/* -# Set up env +# Install Allure CLI globally +RUN npm install -g allure-commandline --force + +# Set JAVA_HOME for Allure ENV JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64 ENV PATH=$JAVA_HOME/bin:$PATH WORKDIR /app + +# Copy only package files first to cache layer COPY package*.json ./ -RUN npm install -# === Stage 2: Final image === +# Install Node dependencies +RUN npm ci + +# Copy environment files +COPY env ./env + +# Copy the rest of the application +COPY . . + +# ---- Final Stage ---- FROM mcr.microsoft.com/playwright:v1.53.1-jammy -# Copy Java, Allure, and installed node_modules from builder -COPY --from=builder /usr/lib/jvm/temurin-11-jdk-amd64 /usr/lib/jvm/temurin-11-jdk-amd64 -COPY --from=builder /usr/share/keyrings/adoptium.gpg /usr/share/keyrings/adoptium.gpg -COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules -COPY --from=builder /usr/local/bin/allure /usr/local/bin/allure -COPY --from=builder /app/node_modules /app/node_modules +# Copy Java and Allure from build stage +COPY --from=build /usr/lib/jvm/ /usr/lib/jvm/ +COPY --from=build /usr/local/lib/node_modules/allure-commandline /usr/local/lib/node_modules/allure-commandline +RUN ln -s /usr/local/lib/node_modules/allure-commandline/bin/allure /usr/local/bin/allure -# Set up env again ENV JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64 ENV PATH=$JAVA_HOME/bin:$PATH WORKDIR /app -COPY . . -COPY env ./env -# Clean unnecessary files -RUN rm -rf /root/.cache /root/.npm /tmp/* +# Copy node_modules and built app from build stage +COPY --from=build /app/node_modules ./node_modules +COPY --from=build /app/env ./env +COPY --from=build /app/. . +COPY --from=build /app/package*.json ./ -CMD ["npm", "run", "test:allure"] +CMD ["npm", "run", "test:allure"] \ No newline at end of file From d15063b93cd34199497b0856a7a7a55560c20a70 Mon Sep 17 00:00:00 2001 From: ramakrishnajangatisetty Date: Sat, 28 Jun 2025 14:30:30 -0500 Subject: [PATCH 03/12] Use multi-stage builds to keep the image smaller. Clean up unnecessary files after install to reduce image size. --- Dockerfile.playwright | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Dockerfile.playwright b/Dockerfile.playwright index 5f8bec0..a81421a 100644 --- a/Dockerfile.playwright +++ b/Dockerfile.playwright @@ -8,13 +8,6 @@ RUN apt-get update && apt-get install -y wget gnupg2 && \ apt-get update && apt-get install -y temurin-11-jdk && \ rm -rf /var/lib/apt/lists/* -# Install Allure CLI globally -RUN npm install -g allure-commandline --force - -# Set JAVA_HOME for Allure -ENV JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64 -ENV PATH=$JAVA_HOME/bin:$PATH - WORKDIR /app # Copy only package files first to cache layer @@ -32,10 +25,15 @@ COPY . . # ---- Final Stage ---- FROM mcr.microsoft.com/playwright:v1.53.1-jammy -# Copy Java and Allure from build stage -COPY --from=build /usr/lib/jvm/ /usr/lib/jvm/ -COPY --from=build /usr/local/lib/node_modules/allure-commandline /usr/local/lib/node_modules/allure-commandline -RUN ln -s /usr/local/lib/node_modules/allure-commandline/bin/allure /usr/local/bin/allure +# Install Java 11 (required for Allure) in the final image +RUN apt-get update && apt-get install -y wget gnupg2 && \ + wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor -o /usr/share/keyrings/adoptium.gpg && \ + echo "deb [signed-by=/usr/share/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb focal main" | tee /etc/apt/sources.list.d/adoptium.list && \ + apt-get update && apt-get install -y temurin-11-jdk && \ + rm -rf /var/lib/apt/lists/* + +# Install Allure CLI globally in the final image +RUN npm install -g allure-commandline --force ENV JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64 ENV PATH=$JAVA_HOME/bin:$PATH From 4d6ba2d4959c1d4002ffa06bd9e52a04e45ccf22 Mon Sep 17 00:00:00 2001 From: ramakrishnajangatisetty Date: Sat, 28 Jun 2025 14:37:22 -0500 Subject: [PATCH 04/12] updated config.ts file --- utils/config.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/config.ts b/utils/config.ts index f9616e9..c6fcc4d 100644 --- a/utils/config.ts +++ b/utils/config.ts @@ -1,13 +1,13 @@ -import * as dotenv from 'dotenv'; -import * as path from 'path'; +import * as dotenvFlow from 'dotenv-flow'; -// Determine the environment (default to 'local' if not provided) const envName = process.env.TEST_ENV || 'local'; console.log("Environment Name is: " + envName); -// Load the corresponding .env file from /env folder -console.log(`../../env/.env.${envName}`); -dotenv.config({ path: path.resolve(__dirname, `../env/.env.${envName}`) }); +// Load .env files using dotenv-flow +dotenvFlow.config({ + node_env: envName, // This will load .env.qa1, .env.dev, etc. + path: `${__dirname}/../env` +}); interface TestConfig { url: string; From 2904791b11ea198749f2155579cc31e5ae8fd7d9 Mon Sep 17 00:00:00 2001 From: ramakrishnajangatisetty Date: Sat, 28 Jun 2025 16:54:32 -0500 Subject: [PATCH 05/12] Loading baseURL from your .env files for consistency. --- README.md | 15 +++++++++++++++ env/.env.dev1 | 2 +- env/.env.dev2 | 2 +- env/.env.qa1 | 2 +- env/.env.qa2 | 2 +- global/test-run-context.json | 4 ++-- pages/LoginPage.ts | 2 +- playwright.config.ts | 9 ++++++++- utils/config.ts | 4 ++-- 9 files changed, 32 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1fc6dc4..53ab7c9 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,20 @@ e2e-playwright-framework/ ├── DockerFile.playwright # Dockerfile for CI/CD ├── .github/workflows/ # GitHub Actions workflows ``` +## 🌐 Overriding baseURL +- By default, `baseURL` is loaded from your environment file (e.g., `env/.env.dev1`). +- To override for a specific run, set the `BASE_URL` variable: + +```sh +BASE_URL=https://another-url.com npm test +``` + +- Or use a different environment: + +```sh +TEST_ENV=dev1 npm test +``` --- ## ✅ GitHub Actions CI/CD @@ -148,6 +161,8 @@ This project uses **GitHub Actions** to automate test execution and reporting. --- + + ## 📄 License MIT © 2025 Ramakrishna Jangatisetty \ No newline at end of file diff --git a/env/.env.dev1 b/env/.env.dev1 index db053b5..43fa645 100644 --- a/env/.env.dev1 +++ b/env/.env.dev1 @@ -1,3 +1,3 @@ -URL=https://saucedemo.com +BASE_URL=https://saucedemo.com USERNAME=standard_user PASSWORD=secret_sauce \ No newline at end of file diff --git a/env/.env.dev2 b/env/.env.dev2 index db053b5..43fa645 100644 --- a/env/.env.dev2 +++ b/env/.env.dev2 @@ -1,3 +1,3 @@ -URL=https://saucedemo.com +BASE_URL=https://saucedemo.com USERNAME=standard_user PASSWORD=secret_sauce \ No newline at end of file diff --git a/env/.env.qa1 b/env/.env.qa1 index db053b5..43fa645 100644 --- a/env/.env.qa1 +++ b/env/.env.qa1 @@ -1,3 +1,3 @@ -URL=https://saucedemo.com +BASE_URL=https://saucedemo.com USERNAME=standard_user PASSWORD=secret_sauce \ No newline at end of file diff --git a/env/.env.qa2 b/env/.env.qa2 index db053b5..43fa645 100644 --- a/env/.env.qa2 +++ b/env/.env.qa2 @@ -1,3 +1,3 @@ -URL=https://saucedemo.com +BASE_URL=https://saucedemo.com USERNAME=standard_user PASSWORD=secret_sauce \ No newline at end of file diff --git a/global/test-run-context.json b/global/test-run-context.json index d9b57e2..b8aed53 100644 --- a/global/test-run-context.json +++ b/global/test-run-context.json @@ -1,6 +1,6 @@ { - "testRunId": "run_20250628182021939", - "startTime": "2025-06-28T18:20:21.939Z", + "testRunId": "run_20250628215003653", + "startTime": "2025-06-28T21:50:03.653Z", "environment": "qa1", "project": "e2e-playwright-typescript-framework", "status": "in-progress" diff --git a/pages/LoginPage.ts b/pages/LoginPage.ts index c1690f6..1244988 100644 --- a/pages/LoginPage.ts +++ b/pages/LoginPage.ts @@ -21,7 +21,7 @@ export class LoginPage extends BasePage { } async goto() { - await this.page.goto(config.url) + await this.page.goto(config.baseUrl) } constructor(page: Page) { diff --git a/playwright.config.ts b/playwright.config.ts index daf66b0..504eef1 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,6 +1,13 @@ import { defineConfig } from '@playwright/test'; +import * as dotenvFlow from 'dotenv-flow'; import path from 'path'; +// Load env variables before config is defined +dotenvFlow.config({ + path: path.resolve(__dirname, 'env'), + node_env: process.env.TEST_ENV || 'local' +}); + export default defineConfig({ testDir: './tests', workers: 2, @@ -24,4 +31,4 @@ export default defineConfig({ globalSetup: require.resolve('./global/setup.ts'), globalTeardown: require.resolve('./global/teardown.ts'), -}); +}); \ No newline at end of file diff --git a/utils/config.ts b/utils/config.ts index c6fcc4d..6aab3ab 100644 --- a/utils/config.ts +++ b/utils/config.ts @@ -10,7 +10,7 @@ dotenvFlow.config({ }); interface TestConfig { - url: string; + baseUrl: string; username: string; password: string; } @@ -23,7 +23,7 @@ function assertEnvVar(name: string, value: string | undefined): string { } export const config: TestConfig = { - url: assertEnvVar('URL', process.env.URL), + baseUrl: assertEnvVar('URL', process.env.BASE_URL), username: assertEnvVar('USERNAME', process.env.USERNAME), password: assertEnvVar('PASSWORD', process.env.PASSWORD), }; \ No newline at end of file From 0d381e8377993dbea72d28cf09566f464f41e9c6 Mon Sep 17 00:00:00 2001 From: ramakrishnajangatisetty Date: Sat, 28 Jun 2025 17:01:30 -0500 Subject: [PATCH 06/12] Updated config.ts file --- utils/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/config.ts b/utils/config.ts index 6aab3ab..3c5d174 100644 --- a/utils/config.ts +++ b/utils/config.ts @@ -23,7 +23,7 @@ function assertEnvVar(name: string, value: string | undefined): string { } export const config: TestConfig = { - baseUrl: assertEnvVar('URL', process.env.BASE_URL), + baseUrl: assertEnvVar('BASE_URL', process.env.BASE_URL), username: assertEnvVar('USERNAME', process.env.USERNAME), password: assertEnvVar('PASSWORD', process.env.PASSWORD), }; \ No newline at end of file From 2c310fcbfc4ad528ba1c3d4d503c5c06a22f59c0 Mon Sep 17 00:00:00 2001 From: ramakrishnajangatisetty Date: Sat, 28 Jun 2025 17:08:41 -0500 Subject: [PATCH 07/12] Updated setup.ts file not to use path aliases, using relative imports --- tests/setup.ts | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/tests/setup.ts b/tests/setup.ts index b7827c3..e229634 100644 --- a/tests/setup.ts +++ b/tests/setup.ts @@ -1,11 +1,26 @@ -import { test as base, expect, type Page, type TestInfo } from '@playwright/test'; -import { logger } from '../utils/logger'; +/** + * Custom Playwright test setup. + * + * This file exports a customized `test` and `expect` for use in all test files. + * It wraps Playwright's base test to add common hooks, logging, and shared fixtures. + * + * Usage: + * Import `test` and `expect` from this file in your test specs using a relative path: + * import { test, expect } from '../setup'; + * + * Why not use a path alias? + * Playwright and Node.js do not resolve TypeScript path aliases at runtime by default. + * Using relative imports ensures compatibility in all environments. + * + * Contributors: + * - Add shared hooks, fixtures, or logging here to apply them across all tests. + * - Do not import `@playwright/test` directly in your test files—use this setup instead. + */ -base.beforeEach(async ({ page }, testInfo) => { - logger.info(`🚀 Starting test: ${testInfo.title}`); - logger.info(`🔖 Tags: ${testInfo.annotations.map(a => a.type).join(', ') || 'None'}`); -}); +import { test as base, expect } from '@playwright/test'; +import { logger } from '../utils/logger'; +// Example: Add a global afterEach hook for logging base.afterEach(async ({ page }, testInfo) => { const status = testInfo.status?.toUpperCase(); const duration = `${testInfo.duration}ms`; @@ -20,4 +35,4 @@ base.afterEach(async ({ page }, testInfo) => { }); export const test = base; -export { expect }; +export { expect }; \ No newline at end of file From 193ca1b42ceffa473f560eefd5be814276a71b83 Mon Sep 17 00:00:00 2001 From: ramakrishnajangatisetty Date: Sat, 28 Jun 2025 17:19:55 -0500 Subject: [PATCH 08/12] Updated playwright.yml to cache npm dependencies for faster --- .github/workflows/playwright.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 5908e4a..6c94711 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -42,6 +42,14 @@ jobs: - name: Checkout repo uses: actions/checkout@v3 + - name: Cache node_modules + uses: actions/cache@v4 + with: + path: ~/.npm + key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-npm- + - name: Build Docker Image run: docker build -t my-playwright-runner -f Dockerfile.playwright . @@ -79,4 +87,4 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./allure-report - publish_branch: gh-pages + publish_branch: gh-pages \ No newline at end of file From 0c69aed605fc45020cb7c36b2e8e10591bd94953 Mon Sep 17 00:00:00 2001 From: ramakrishnajangatisetty Date: Sat, 28 Jun 2025 17:24:00 -0500 Subject: [PATCH 09/12] updated the playwright.config.ts file to update projects --- playwright.config.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/playwright.config.ts b/playwright.config.ts index 504eef1..938f107 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -26,7 +26,9 @@ export default defineConfig({ trace: 'on-first-retry', }, projects: [ - { name: 'Chromium', use: { browserName: 'chromium' } } + { name: 'Chromium', use: { browserName: 'chromium' } }, + { name: 'Firefox', use: { browserName: 'firefox' } }, + { name: 'WebKit', use: { browserName: 'webkit' } } ], globalSetup: require.resolve('./global/setup.ts'), From 739b53f9dc54b39c067b9a7551bd721db946f888 Mon Sep 17 00:00:00 2001 From: ramakrishnajangatisetty Date: Sat, 28 Jun 2025 17:53:02 -0500 Subject: [PATCH 10/12] Updated Docker file to generate allure reports in docker --- Dockerfile.playwright | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Dockerfile.playwright b/Dockerfile.playwright index a81421a..e670669 100644 --- a/Dockerfile.playwright +++ b/Dockerfile.playwright @@ -1,7 +1,7 @@ # ---- Build Stage ---- FROM mcr.microsoft.com/playwright:v1.53.1-jammy AS build -# Install Java 11 (required for Allure) +# Install Java 11 (for Allure) RUN apt-get update && apt-get install -y wget gnupg2 && \ wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor -o /usr/share/keyrings/adoptium.gpg && \ echo "deb [signed-by=/usr/share/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb focal main" | tee /etc/apt/sources.list.d/adoptium.list && \ @@ -10,7 +10,7 @@ RUN apt-get update && apt-get install -y wget gnupg2 && \ WORKDIR /app -# Copy only package files first to cache layer +# Copy package files first to leverage Docker caching COPY package*.json ./ # Install Node dependencies @@ -19,31 +19,30 @@ RUN npm ci # Copy environment files COPY env ./env -# Copy the rest of the application +# Copy the full application COPY . . # ---- Final Stage ---- FROM mcr.microsoft.com/playwright:v1.53.1-jammy -# Install Java 11 (required for Allure) in the final image +# Install Java 11 and Allure CLI RUN apt-get update && apt-get install -y wget gnupg2 && \ wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor -o /usr/share/keyrings/adoptium.gpg && \ echo "deb [signed-by=/usr/share/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb focal main" | tee /etc/apt/sources.list.d/adoptium.list && \ apt-get update && apt-get install -y temurin-11-jdk && \ + npm install -g allure-commandline --force && \ rm -rf /var/lib/apt/lists/* -# Install Allure CLI globally in the final image -RUN npm install -g allure-commandline --force - ENV JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64 ENV PATH=$JAVA_HOME/bin:$PATH WORKDIR /app -# Copy node_modules and built app from build stage +# Copy built assets and node_modules from the build stage COPY --from=build /app/node_modules ./node_modules COPY --from=build /app/env ./env COPY --from=build /app/. . COPY --from=build /app/package*.json ./ -CMD ["npm", "run", "test:allure"] \ No newline at end of file +# Default CMD — runs Playwright tests and generates Allure report +CMD ["npm", "run", "test:allure"] From 3be807eaab029f8e32af2155fc52889d5bb489cd Mon Sep 17 00:00:00 2001 From: ramakrishnajangatisetty Date: Sat, 28 Jun 2025 18:27:00 -0500 Subject: [PATCH 11/12] Added Architecture Document --- ARCHITECTURE.md | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 ARCHITECTURE.md diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md new file mode 100644 index 0000000..4b7926d --- /dev/null +++ b/ARCHITECTURE.md @@ -0,0 +1,141 @@ +# 📘 Playwright E2E Framework - Architecture Documentation + +## 📁 Project Structure Overview + +``` +├── .github/workflows/ +│ └── playwright.yml # GitHub Actions workflow with dynamic test config +├── env/ +│ └── .env.qa1 # Environment-specific config +├── global/ +│ ├── setup.ts # Global setup for context and metadata +│ ├── teardown.ts # Global teardown to enrich test results +├── pages/ +│ ├── BasePage.ts # Base class with reusable Playwright actions +│ └── LoginPage.ts # Page Object Model (POM) for Login page +├── playwright-report/ # Allure and JSON report outputs +├── tests/ +│ ├── testsetup.ts # Custom test hooks with logger integration +│ └── ui/ +│ └── login.spec.ts # Sample test for login validation +├── utils/ +│ ├── allureHelper.ts # Helper for tagging tests in Allure +│ ├── config.ts # Typed environment config reader +│ ├── loadEnv.ts # Dynamic .env loader by TEST_ENV +│ └── logger.ts # Winston logger +├── Dockerfile.playwright # Multi-stage Dockerfile with Java + Allure setup +├── package.json +├── playwright.config.ts # Main test runner config +└── run-with-params.sh # Shell script for running tests with dynamic env +``` + +--- + +## 🔧 Core Technologies + +* **Playwright** for browser automation +* **TypeScript** for type safety and maintainability +* **Allure Reporter** for rich test visualization +* **Docker** to encapsulate execution +* **GitHub Actions** for CI/CD with test param flexibility + +--- + +## 🏗️ Key Components Explained + +### ✅ playwright.config.ts + +* Configures base test settings, retries, reporters, and project runners. +* Includes: + + * Global hooks (`globalSetup`, `globalTeardown`) + * `json` reporter for enriching data in teardown + * Allure and HTML reports + +### ✅ global/setup.ts + +* Loads environment from `.env.{env}` using `loadEnv.ts` +* Initializes metadata like testRunId, startTime +* Writes `test-run-context.json` + +### ✅ global/teardown.ts + +* Parses `test-results.json` +* Enhances each test case with: + + * Duration, tags, retry count + * Failure message + stack trace if applicable + * History stub fields (e.g., flaky count, last failed) +* Merges data into `enriched-test-results.json` + +### ✅ testsetup.ts + +* Adds `beforeEach` and `afterEach` logging using Winston +* Replaces Playwright's default test + +### ✅ Dockerfile.playwright + +* Multi-stage: + + * Stage 1 installs deps and caches builds + * Stage 2 copies node\_modules, env, and source +* Includes Java and Allure CLI for reporting + +### ✅ GitHub Actions Workflow + +* Supports inputs: `tag`, `browser`, `workers`, `retries`, `test_env` +* Uses `run-with-params.sh` inside container +* Publishes Allure report to GitHub Pages + +### ✅ env/.env.qa1 + +* Customizes: + + * `URL=https://saucedemo.com` + * `USERNAME`, `PASSWORD` + +### ✅ utils/config.ts + +* Loads env vars with type safety +* Validates missing values early + +### ✅ utils/logger.ts + +* Uses Winston logger with ISO timestamps + +### ✅ run-with-params.sh + +* Dynamically runs Playwright with flags like: + +```bash +npx playwright test \ + --project="$BROWSER" \ + --workers="$WORKERS" \ + --retries="$RETRIES" \ + $TAG +``` + +--- + +## 📈 Future-Ready Features (Planned or Extendable) + +* 🔍 Store enriched JSON to DynamoDB/Postgres +* 📊 Build custom dashboards from enriched test result metadata +* 📤 Slack/GitHub notification integration +* 🤖 Integrate GPT-based RCA suggestions per failure +* 🔄 Automatic test rerun for flaky failures + +--- + +## 🙌 Usage Summary + +* `TEST_ENV=qa1 npx playwright test` (local) +* `docker build -t my-playwright-runner .` +* `docker run --rm -e TEST_ENV=qa1 my-playwright-runner` +* CI: Trigger via GitHub Actions with tag and env + +--- + +## ✅ Author + +Maintained by [@ramjangatisetty](https://github.com/ramjangatisetty) with ❤️ for the testing community. From f3dbcd5bb4cc2aca0f954649b4c8566fb01a34fb Mon Sep 17 00:00:00 2001 From: ramakrishnajangatisetty Date: Sat, 28 Jun 2025 19:50:50 -0500 Subject: [PATCH 12/12] updated README.md with link of ARCHITECTURE.md --- README.md | 1 + ARCHITECTURE.md => docs/ARCHITECTURE.md | 0 2 files changed, 1 insertion(+) rename ARCHITECTURE.md => docs/ARCHITECTURE.md (100%) diff --git a/README.md b/README.md index 53ab7c9..e4bff6f 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Supports cross-browser testing, rich reporting with **Allure**, Dockerized execu ## 📚 Documentation +- [ARCHITECTURE](docs/ARCHITECTURE.md) - [BasePage](docs/BasePage.md) - [LoginPage](docs/LoginPage.md) - [HomePage](docs/HomePage.md) diff --git a/ARCHITECTURE.md b/docs/ARCHITECTURE.md similarity index 100% rename from ARCHITECTURE.md rename to docs/ARCHITECTURE.md