Skip to content

Commit cd124eb

Browse files
Added entire cucumber boiler plate with tests
1 parent 857665c commit cd124eb

22 files changed

+1604
-0
lines changed

.github/instructions.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copilot Instructions for Playwright Test Framework
2+
3+
## Project Context
4+
This is a comprehensive Playwright testing library supporting web, API, BDD, and Mocha testing.
5+
6+
## Code Style Guidelines
7+
- Use TypeScript strict mode
8+
- Follow async/await patterns
9+
- Use descriptive variable names
10+
- Add JSDoc comments for public methods
11+
- Export types and interfaces
12+
- Use factory patterns for object creation
13+
14+
## When Adding New Features
15+
1. Create in appropriate src/ subdirectory
16+
2. Export from src/index.ts
17+
3. Add TypeScript types/interfaces
18+
4. Include error handling with custom errors
19+
5. Add logging with appropriate level
20+
6. Create example in tests/ directory
21+
7. Update README.md with usage
22+
8. Add unit tests if applicable
23+
24+
## Testing Patterns
25+
- Use Page Object Model for web tests
26+
- Keep step definitions reusable
27+
- Use fixtures for test data
28+
- Implement proper cleanup in afterEach
29+
- Add tags for test categorization
30+
31+
## Error Handling
32+
- Always use try-catch for async operations
33+
- Log errors with context
34+
- Throw custom error types
35+
- Attach screenshots on failures
36+
37+
## Performance
38+
- Reuse browser contexts when possible
39+
- Implement connection pooling for API
40+
- Use Promise.all for parallel operations
41+
- Clean up resources in finally blocks
42+
43+
## Commit Message Format
44+
- feat: New feature
45+
- fix: Bug fix
46+
- docs: Documentation changes
47+
- test: Test additions/changes
48+
- refactor: Code refactoring

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Node dependencies
2+
node_modules/
3+
4+
# Lockfiles (keep lockfile in repo - do NOT ignore package-lock.json or yarn.lock unless intentional)
5+
package-lock.json
6+
# yarn.lock
7+
8+
9+
# Logs created during execution
10+
logs/
11+
12+
# # Test outputs and artifacts (generated by cucumber/playwright)
13+
# tests/test-results/
14+
# tests/test-results/**/*
15+
# tests/reports/
16+
# tests/playwright-report/
17+
# tests/logs/
18+
# tests/.cache/
19+
# tests/reports/**/*.*
20+
# tests/test-results/videos/
21+
# tests/test-results/videos/**/*.*
22+
# tests/test-results/screenshots/
23+
# tests/test-results/screenshots/**/*

CONTRIBUTING.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Contributing to Playwright Test Framework
2+
3+
We love your input! We want to make contributing to this framework as easy and transparent as possible, whether it's:
4+
5+
- Reporting a bug
6+
- Discussing the current state of the code
7+
- Submitting a fix
8+
- Proposing new features
9+
- Becoming a maintainer
10+
11+
## Development Process
12+
13+
We use GitHub to host code, to track issues and feature requests, as well as accept pull requests.
14+
15+
1. Fork the repo and create your branch from `main`
16+
2. Add tests for any new functionality
17+
3. Ensure tests pass (`npm test`)
18+
4. Update documentation
19+
5. Submit pull request
20+
21+
## Code Style Guidelines
22+
23+
- Use TypeScript strict mode
24+
- Follow async/await patterns
25+
- Use descriptive variable names
26+
- Add JSDoc comments for public methods
27+
- Follow the existing coding style
28+
- Keep functions small and focused
29+
30+
## Testing Guidelines
31+
32+
- Add tests for any new features
33+
- Update existing tests for modifications
34+
- Use appropriate test categories (web/api/accessibility)
35+
- Include both positive and negative test cases
36+
- Follow the Page Object Model for web tests
37+
38+
## Pull Request Process
39+
40+
1. Update the README.md with details of changes if applicable
41+
2. Update the version number following semantic versioning
42+
3. Add entry to CHANGELOG.md
43+
4. The PR may be merged once you have the sign-off of another developer
44+
45+
## License
46+
47+
By contributing, you agree that your contributions will be licensed under its MIT License.

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Playwright + Cucumber Test Framework
2+
3+
Quick notes and how-to.
4+
5+
## Prerequisites
6+
- Node.js (recommended LTS)
7+
- npm install run before using scripts: npm ci or npm install
8+
9+
## Install
10+
- npm ci
11+
12+
## Run tests (single-worker)
13+
- node tests/run-cucumber.js
14+
- or: npx cucumber-js --require-module ts-node/register tests/features/**/*.feature
15+
16+
## Run tests (parallel)
17+
- node tests/run-cucumber.js --parallel=2
18+
- OR set env: PARALLEL=2 or PARALLEL_WORKERS=2
19+
- run-cucumber script will auto-limit workers to CPU and disable heavy artifacts
20+
21+
## Important environment variables
22+
- HEADLESS (true|false) — browser headless mode
23+
- RECORD_VIDEO (true|false) — video recording (disabled automatically for parallel runs)
24+
- PARALLEL or PARALLEL_WORKERS — number of workers for cucumber-js
25+
- BROWSER_WS_ENDPOINT — used when a shared browser server is launched for parallel runs
26+
27+
## Performance tips
28+
- Video recording per-worker is expensive. Keep RECORD_VIDEO off for parallel runs.
29+
- Choose parallel count based on CPU cores (2–4 recommended on small machines).
30+
- To avoid overhead at start/end, run-cucumber can launch a single BrowserServer and workers will connect to it (see tests/run-cucumber.backup.js).
31+
- If scenarios are very short, parallel overhead may outweigh benefits — run with 1 or 2 workers.
32+
33+
## Troubleshooting
34+
- If AfterAll hooks time out in parallel runs, increase setDefaultTimeout or specify hook timeout in tests/support/hooks.ts.
35+
- Ensure reporter output files are unique per worker; run-cucumber sets unique names for parallel runs.
36+
- To inspect the actual command run, the runner logs the computed cucumber-js command.
37+
38+
## Do not commit
39+
- Test artifacts (videos, screenshots, test-results) are gitignored by default.
40+
41+
If you want, I can:
42+
- Add a short npm script set in package.json for running with common flags.
43+
- Add a sample .env.example with recommended env settings.

package.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "@yourorg/playwright-framework",
3+
"version": "1.0.0",
4+
"description": "Comprehensive Playwright testing framework with web, API, BDD, and Mocha support",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"scripts": {
8+
"build": "tsc",
9+
"test:bdd:ui": "cross-env node tests/run-cucumber.js",
10+
"test:ui:parallel": "cross-env node tests/run-cucumber.parallel.js",
11+
"lint": "eslint src tests",
12+
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
13+
"init": "playwright install && npm install"
14+
},
15+
"keywords": [
16+
"playwright",
17+
"testing",
18+
"automation",
19+
"bdd",
20+
"cucumber",
21+
"mocha",
22+
"typescript"
23+
],
24+
"author": "",
25+
"license": "MIT",
26+
"dependencies": {
27+
"@axe-core/playwright": "^4.7.0",
28+
"@playwright/test": "^1.39.0",
29+
"dotenv": "^16.0.3",
30+
"winston": "^3.10.0",
31+
"zod": "^3.22.0"
32+
},
33+
"devDependencies": {
34+
"@cucumber/cucumber": "^12.2.0",
35+
"@types/chai": "^4.3.0",
36+
"@types/mocha": "^10.0.0",
37+
"@types/node": "^18.0.0",
38+
"@typescript-eslint/eslint-plugin": "^5.0.0",
39+
"@typescript-eslint/parser": "^5.0.0",
40+
"allure-cucumberjs": "^3.4.1",
41+
"allure-js-commons": "^3.4.1",
42+
"chai": "^4.3.0",
43+
"cross-env": "^10.1.0",
44+
"eslint": "^8.0.0",
45+
"mocha": "^10.0.0",
46+
"prettier": "^2.8.0",
47+
"rimraf": "^6.0.1",
48+
"ts-node": "^10.9.0",
49+
"typescript": "^5.0.0"
50+
},
51+
"engines": {
52+
"node": ">=16.0.0"
53+
}
54+
}

src/reporting/logger.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import winston from 'winston';
2+
3+
export class Logger {
4+
private logger: winston.Logger;
5+
6+
constructor(context: string) {
7+
this.logger = winston.createLogger({
8+
level: process.env.LOG_LEVEL || 'info',
9+
format: winston.format.combine(
10+
winston.format.timestamp(),
11+
winston.format.json(),
12+
winston.format.printf(({ timestamp, level, message, ...meta }) => {
13+
return JSON.stringify({
14+
timestamp,
15+
level,
16+
context,
17+
message,
18+
...meta,
19+
});
20+
})
21+
),
22+
transports: [
23+
new winston.transports.Console({
24+
format: winston.format.combine(
25+
winston.format.colorize(),
26+
winston.format.simple()
27+
),
28+
}),
29+
new winston.transports.File({
30+
filename: 'logs/error.log',
31+
level: 'error',
32+
}),
33+
new winston.transports.File({
34+
filename: 'logs/combined.log',
35+
}),
36+
],
37+
});
38+
}
39+
40+
info(message: string, meta?: Record<string, unknown>): void {
41+
this.logger.info(message, meta);
42+
}
43+
44+
error(message: string, error?: Error, meta?: Record<string, unknown>): void {
45+
this.logger.error(message, {
46+
error: error?.message,
47+
stack: error?.stack,
48+
...meta,
49+
});
50+
}
51+
52+
warn(message: string, meta?: Record<string, unknown>): void {
53+
this.logger.warn(message, meta);
54+
}
55+
56+
debug(message: string, meta?: Record<string, unknown>): void {
57+
this.logger.debug(message, meta);
58+
}
59+
60+
trace(message: string, meta?: Record<string, unknown>): void {
61+
this.logger.silly(message, meta);
62+
}
63+
}

0 commit comments

Comments
 (0)