|
| 1 | +# 📘 Playwright E2E Framework - Architecture Documentation |
| 2 | + |
| 3 | +## 📁 Project Structure Overview |
| 4 | + |
| 5 | +``` |
| 6 | +├── .github/workflows/ |
| 7 | +│ └── playwright.yml # GitHub Actions workflow with dynamic test config |
| 8 | +├── env/ |
| 9 | +│ └── .env.qa1 # Environment-specific config |
| 10 | +├── global/ |
| 11 | +│ ├── setup.ts # Global setup for context and metadata |
| 12 | +│ ├── teardown.ts # Global teardown to enrich test results |
| 13 | +├── pages/ |
| 14 | +│ ├── BasePage.ts # Base class with reusable Playwright actions |
| 15 | +│ └── LoginPage.ts # Page Object Model (POM) for Login page |
| 16 | +├── playwright-report/ # Allure and JSON report outputs |
| 17 | +├── tests/ |
| 18 | +│ ├── testsetup.ts # Custom test hooks with logger integration |
| 19 | +│ └── ui/ |
| 20 | +│ └── login.spec.ts # Sample test for login validation |
| 21 | +├── utils/ |
| 22 | +│ ├── allureHelper.ts # Helper for tagging tests in Allure |
| 23 | +│ ├── config.ts # Typed environment config reader |
| 24 | +│ ├── loadEnv.ts # Dynamic .env loader by TEST_ENV |
| 25 | +│ └── logger.ts # Winston logger |
| 26 | +├── Dockerfile.playwright # Multi-stage Dockerfile with Java + Allure setup |
| 27 | +├── package.json |
| 28 | +├── playwright.config.ts # Main test runner config |
| 29 | +└── run-with-params.sh # Shell script for running tests with dynamic env |
| 30 | +``` |
| 31 | + |
| 32 | +--- |
| 33 | + |
| 34 | +## 🔧 Core Technologies |
| 35 | + |
| 36 | +* **Playwright** for browser automation |
| 37 | +* **TypeScript** for type safety and maintainability |
| 38 | +* **Allure Reporter** for rich test visualization |
| 39 | +* **Docker** to encapsulate execution |
| 40 | +* **GitHub Actions** for CI/CD with test param flexibility |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +## 🏗️ Key Components Explained |
| 45 | + |
| 46 | +### ✅ playwright.config.ts |
| 47 | + |
| 48 | +* Configures base test settings, retries, reporters, and project runners. |
| 49 | +* Includes: |
| 50 | + |
| 51 | + * Global hooks (`globalSetup`, `globalTeardown`) |
| 52 | + * `json` reporter for enriching data in teardown |
| 53 | + * Allure and HTML reports |
| 54 | + |
| 55 | +### ✅ global/setup.ts |
| 56 | + |
| 57 | +* Loads environment from `.env.{env}` using `loadEnv.ts` |
| 58 | +* Initializes metadata like testRunId, startTime |
| 59 | +* Writes `test-run-context.json` |
| 60 | + |
| 61 | +### ✅ global/teardown.ts |
| 62 | + |
| 63 | +* Parses `test-results.json` |
| 64 | +* Enhances each test case with: |
| 65 | + |
| 66 | + * Duration, tags, retry count |
| 67 | + * Failure message + stack trace if applicable |
| 68 | + * History stub fields (e.g., flaky count, last failed) |
| 69 | +* Merges data into `enriched-test-results.json` |
| 70 | + |
| 71 | +### ✅ testsetup.ts |
| 72 | + |
| 73 | +* Adds `beforeEach` and `afterEach` logging using Winston |
| 74 | +* Replaces Playwright's default test |
| 75 | + |
| 76 | +### ✅ Dockerfile.playwright |
| 77 | + |
| 78 | +* Multi-stage: |
| 79 | + |
| 80 | + * Stage 1 installs deps and caches builds |
| 81 | + * Stage 2 copies node\_modules, env, and source |
| 82 | +* Includes Java and Allure CLI for reporting |
| 83 | + |
| 84 | +### ✅ GitHub Actions Workflow |
| 85 | + |
| 86 | +* Supports inputs: `tag`, `browser`, `workers`, `retries`, `test_env` |
| 87 | +* Uses `run-with-params.sh` inside container |
| 88 | +* Publishes Allure report to GitHub Pages |
| 89 | + |
| 90 | +### ✅ env/.env.qa1 |
| 91 | + |
| 92 | +* Customizes: |
| 93 | + |
| 94 | + * `URL=https://saucedemo.com` |
| 95 | + * `USERNAME`, `PASSWORD` |
| 96 | + |
| 97 | +### ✅ utils/config.ts |
| 98 | + |
| 99 | +* Loads env vars with type safety |
| 100 | +* Validates missing values early |
| 101 | + |
| 102 | +### ✅ utils/logger.ts |
| 103 | + |
| 104 | +* Uses Winston logger with ISO timestamps |
| 105 | + |
| 106 | +### ✅ run-with-params.sh |
| 107 | + |
| 108 | +* Dynamically runs Playwright with flags like: |
| 109 | + |
| 110 | +```bash |
| 111 | +npx playwright test \ |
| 112 | + --project="$BROWSER" \ |
| 113 | + --workers="$WORKERS" \ |
| 114 | + --retries="$RETRIES" \ |
| 115 | + $TAG |
| 116 | +``` |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +## 📈 Future-Ready Features (Planned or Extendable) |
| 121 | + |
| 122 | +* 🔍 Store enriched JSON to DynamoDB/Postgres |
| 123 | +* 📊 Build custom dashboards from enriched test result metadata |
| 124 | +* 📤 Slack/GitHub notification integration |
| 125 | +* 🤖 Integrate GPT-based RCA suggestions per failure |
| 126 | +* 🔄 Automatic test rerun for flaky failures |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## 🙌 Usage Summary |
| 131 | + |
| 132 | +* `TEST_ENV=qa1 npx playwright test` (local) |
| 133 | +* `docker build -t my-playwright-runner .` |
| 134 | +* `docker run --rm -e TEST_ENV=qa1 my-playwright-runner` |
| 135 | +* CI: Trigger via GitHub Actions with tag and env |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## ✅ Author |
| 140 | + |
| 141 | +Maintained by [@ramjangatisetty](https://github.com/ramjangatisetty) with ❤️ for the testing community. |
0 commit comments