Skip to content

Commit d8f0b0d

Browse files
Merge pull request #4 from ramjangatisetty/feature/githubworkflowwithdocker
Feature/githubworkflowwithdocker
2 parents 3e17052 + f3dbcd5 commit d8f0b0d

File tree

13 files changed

+245
-38
lines changed

13 files changed

+245
-38
lines changed

.github/workflows/playwright.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ jobs:
4242
- name: Checkout repo
4343
uses: actions/checkout@v3
4444

45+
- name: Cache node_modules
46+
uses: actions/cache@v4
47+
with:
48+
path: ~/.npm
49+
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
50+
restore-keys: |
51+
${{ runner.os }}-npm-
52+
4553
- name: Build Docker Image
4654
run: docker build -t my-playwright-runner -f Dockerfile.playwright .
4755

@@ -79,4 +87,4 @@ jobs:
7987
with:
8088
github_token: ${{ secrets.GITHUB_TOKEN }}
8189
publish_dir: ./allure-report
82-
publish_branch: gh-pages
90+
publish_branch: gh-pages

Dockerfile.playwright

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,48 @@
1-
FROM mcr.microsoft.com/playwright:v1.53.1-jammy
1+
# ---- Build Stage ----
2+
FROM mcr.microsoft.com/playwright:v1.53.1-jammy AS build
23

3-
# Install Java 11 (required for Allure)
4+
# Install Java 11 (for Allure)
45
RUN apt-get update && apt-get install -y wget gnupg2 && \
56
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor -o /usr/share/keyrings/adoptium.gpg && \
67
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 && \
78
apt-get update && apt-get install -y temurin-11-jdk && \
89
rm -rf /var/lib/apt/lists/*
910

10-
# Install Allure CLI globally
11-
RUN npm install -g allure-commandline --force
12-
13-
# Set JAVA_HOME for Allure
14-
ENV JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64
15-
ENV PATH=$JAVA_HOME/bin:$PATH
16-
17-
# Set working directory
1811
WORKDIR /app
1912

20-
# Copy only package files first to cache layer
13+
# Copy package files first to leverage Docker caching
2114
COPY package*.json ./
2215

2316
# Install Node dependencies
2417
RUN npm ci
2518

26-
# Copy the rest of the application
19+
# Copy environment files
20+
COPY env ./env
21+
22+
# Copy the full application
2723
COPY . .
2824

29-
# Default CMD is overridden by GitHub Action's docker run step
25+
# ---- Final Stage ----
26+
FROM mcr.microsoft.com/playwright:v1.53.1-jammy
27+
28+
# Install Java 11 and Allure CLI
29+
RUN apt-get update && apt-get install -y wget gnupg2 && \
30+
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor -o /usr/share/keyrings/adoptium.gpg && \
31+
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 && \
32+
apt-get update && apt-get install -y temurin-11-jdk && \
33+
npm install -g allure-commandline --force && \
34+
rm -rf /var/lib/apt/lists/*
35+
36+
ENV JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64
37+
ENV PATH=$JAVA_HOME/bin:$PATH
38+
39+
WORKDIR /app
40+
41+
# Copy built assets and node_modules from the build stage
42+
COPY --from=build /app/node_modules ./node_modules
43+
COPY --from=build /app/env ./env
44+
COPY --from=build /app/. .
45+
COPY --from=build /app/package*.json ./
46+
47+
# Default CMD — runs Playwright tests and generates Allure report
3048
CMD ["npm", "run", "test:allure"]

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Supports cross-browser testing, rich reporting with **Allure**, Dockerized execu
77

88
## 📚 Documentation
99

10+
- [ARCHITECTURE](docs/ARCHITECTURE.md)
1011
- [BasePage](docs/BasePage.md)
1112
- [LoginPage](docs/LoginPage.md)
1213
- [HomePage](docs/HomePage.md)
@@ -96,7 +97,20 @@ e2e-playwright-framework/
9697
├── DockerFile.playwright # Dockerfile for CI/CD
9798
├── .github/workflows/ # GitHub Actions workflows
9899
```
100+
## 🌐 Overriding baseURL
99101

102+
- By default, `baseURL` is loaded from your environment file (e.g., `env/.env.dev1`).
103+
- To override for a specific run, set the `BASE_URL` variable:
104+
105+
```sh
106+
BASE_URL=https://another-url.com npm test
107+
```
108+
109+
- Or use a different environment:
110+
111+
```sh
112+
TEST_ENV=dev1 npm test
113+
```
100114
---
101115

102116
## ✅ GitHub Actions CI/CD
@@ -148,6 +162,8 @@ This project uses **GitHub Actions** to automate test execution and reporting.
148162

149163
---
150164

165+
166+
151167
## 📄 License
152168

153169
MIT © 2025 Ramakrishna Jangatisetty

docs/ARCHITECTURE.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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.

env/.env.dev1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
URL=https://saucedemo.com
1+
BASE_URL=https://saucedemo.com
22
USERNAME=standard_user
33
PASSWORD=secret_sauce

env/.env.dev2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
URL=https://saucedemo.com
1+
BASE_URL=https://saucedemo.com
22
USERNAME=standard_user
33
PASSWORD=secret_sauce

env/.env.qa1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
URL=https://saucedemo.com
1+
BASE_URL=https://saucedemo.com
22
USERNAME=standard_user
33
PASSWORD=secret_sauce

env/.env.qa2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
URL=https://saucedemo.com
1+
BASE_URL=https://saucedemo.com
22
USERNAME=standard_user
33
PASSWORD=secret_sauce

global/test-run-context.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"testRunId": "run_20250628182021939",
3-
"startTime": "2025-06-28T18:20:21.939Z",
2+
"testRunId": "run_20250628215003653",
3+
"startTime": "2025-06-28T21:50:03.653Z",
44
"environment": "qa1",
55
"project": "e2e-playwright-typescript-framework",
66
"status": "in-progress"

pages/LoginPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class LoginPage extends BasePage {
2121
}
2222

2323
async goto() {
24-
await this.page.goto(config.url)
24+
await this.page.goto(config.baseUrl)
2525
}
2626

2727
constructor(page: Page) {

0 commit comments

Comments
 (0)