fair-playwright 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Baran Aytas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,262 @@
1
+ # fair-playwright
2
+
3
+ > AI-optimized Playwright test reporter with progressive terminal output and hierarchical step management
4
+
5
+ [![npm version](https://img.shields.io/npm/v/fair-playwright.svg)](https://www.npmjs.com/package/fair-playwright)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Features
9
+
10
+ - ðŸĪ– **AI-First Design** - Structured output optimized for LLM context and AI code assistants
11
+ - 📊 **MAJOR/MINOR Step Hierarchy** - Track test flows at two levels for better organization
12
+ - ⚡ **Progressive Terminal Output** - Live updates with smart compression
13
+ - ðŸŽŊ **Zero Config** - Sensible defaults, works out of the box
14
+ - ðŸŠķ **Lightweight** - Minimal dependencies, <100KB bundle size
15
+ - 🔒 **Type Safe** - Full TypeScript support with exported types
16
+ - 🔌 **MCP Server** - Built-in integration for AI coding assistants
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install -D fair-playwright
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ### 1. Configure Playwright
27
+
28
+ ```typescript
29
+ // playwright.config.ts
30
+ import { defineConfig } from '@playwright/test';
31
+
32
+ export default defineConfig({
33
+ reporter: [['fair-playwright']]
34
+ });
35
+ ```
36
+
37
+ ### 2. Write Tests with Step Hierarchy
38
+
39
+ **Inline Mode (Quick tests):**
40
+
41
+ ```typescript
42
+ import { test } from '@playwright/test';
43
+ import { e2e } from 'fair-playwright';
44
+
45
+ test('user login', async ({ page }) => {
46
+ await e2e.minor('Open login page', async () => {
47
+ await page.goto('/login');
48
+ }, { success: 'Page opened', failure: 'Failed to open' });
49
+
50
+ await e2e.minor('Fill credentials', async () => {
51
+ await page.getByLabel('Email').fill('test@example.com');
52
+ await page.getByLabel('Password').fill('password123');
53
+ }, { success: 'Filled', failure: 'Failed to fill' });
54
+
55
+ await e2e.minor('Submit form', async () => {
56
+ await page.getByRole('button', { name: 'Login' }).click();
57
+ }, { success: 'Submitted', failure: 'Failed to submit' });
58
+ });
59
+ ```
60
+
61
+ **Declarative Mode (Complex flows):**
62
+
63
+ ```typescript
64
+ await e2e.major('User login flow', {
65
+ success: 'User logged in successfully',
66
+ failure: 'Login failed',
67
+ steps: [
68
+ {
69
+ title: 'Open login page',
70
+ success: 'Page opened',
71
+ failure: 'Failed to open',
72
+ action: async () => {
73
+ await page.goto('/login');
74
+ }
75
+ },
76
+ {
77
+ title: 'Fill credentials',
78
+ success: 'Credentials filled',
79
+ failure: 'Failed to fill',
80
+ action: async () => {
81
+ await page.getByLabel('Email').fill('test@example.com');
82
+ await page.getByLabel('Password').fill('password123');
83
+ }
84
+ },
85
+ {
86
+ title: 'Submit form',
87
+ success: 'Form submitted',
88
+ failure: 'Failed to submit',
89
+ action: async () => {
90
+ await page.getByRole('button', { name: 'Login' }).click();
91
+ }
92
+ }
93
+ ]
94
+ });
95
+ ```
96
+
97
+ ## Configuration
98
+
99
+ ```typescript
100
+ // playwright.config.ts
101
+ export default defineConfig({
102
+ reporter: [
103
+ ['fair-playwright', {
104
+ mode: 'progressive', // 'progressive' | 'full' | 'minimal'
105
+ aiOptimized: true,
106
+ output: {
107
+ console: true,
108
+ ai: './test-results/ai-summary.md',
109
+ json: './test-results/results.json'
110
+ },
111
+ stepClassification: {
112
+ durationThreshold: 1000, // Steps > 1s are MAJOR
113
+ autoDetect: true
114
+ },
115
+ progressive: {
116
+ clearCompleted: true,
117
+ updateInterval: 100 // ms
118
+ }
119
+ }]
120
+ ]
121
+ });
122
+ ```
123
+
124
+ ## MAJOR vs MINOR Steps
125
+
126
+ - **MAJOR steps**: High-level user flows (e.g., "User logs in", "Checkout process")
127
+ - **MINOR steps**: Detailed actions within a major step (e.g., "Fill email", "Click submit")
128
+
129
+ This two-level hierarchy helps both humans and AI understand test structure at a glance.
130
+
131
+ ## MCP Server Integration
132
+
133
+ Fair-playwright includes a full **Model Context Protocol (MCP)** server for AI assistant integration.
134
+
135
+ ### Features
136
+
137
+ The MCP server exposes:
138
+ - **3 Resources**: Test results, summary, and failure details
139
+ - **5 Tools**: Query tests, filter by status, get step details, and more
140
+ - **Streaming Support**: Real-time test result updates
141
+
142
+ ### Setup with Claude Desktop
143
+
144
+ Add to `claude_desktop_config.json`:
145
+
146
+ ```json
147
+ {
148
+ "mcpServers": {
149
+ "fair-playwright": {
150
+ "command": "npx",
151
+ "args": ["fair-playwright-mcp"],
152
+ "env": {
153
+ "FAIR_PLAYWRIGHT_RESULTS": "./test-results/results.json"
154
+ }
155
+ }
156
+ }
157
+ }
158
+ ```
159
+
160
+ ### Available Resources
161
+
162
+ - `fair-playwright://test-results` - Complete test execution data (JSON)
163
+ - `fair-playwright://test-summary` - AI-optimized summary (Markdown)
164
+ - `fair-playwright://failures` - Detailed failure information (Markdown)
165
+
166
+ ### Available Tools
167
+
168
+ - `get_test_results` - Get all test results with full details
169
+ - `get_failure_summary` - Get AI-optimized failure summary
170
+ - `query_test` - Search for specific test by title
171
+ - `get_tests_by_status` - Filter tests by passed/failed/skipped
172
+ - `get_step_details` - Get MAJOR/MINOR step details for a test
173
+
174
+ ### CLI Options
175
+
176
+ ```bash
177
+ npx fair-playwright-mcp --help
178
+ npx fair-playwright-mcp --results-path ./custom-results.json --verbose
179
+ ```
180
+
181
+ ## Output Examples
182
+
183
+ ### Terminal (Progressive Mode)
184
+
185
+ ```
186
+ ✓ Authentication (2/2 tests, 1.2s)
187
+
188
+ âģ Payment Processing (1/3 tests)
189
+ ✓ Validate cart (234ms)
190
+ âŸģ Process payment (running 2.1s)
191
+ Step 1/4: Navigate to checkout ✓
192
+ Step 2/4: Fill payment form ✓
193
+ Step 3/4: Submit payment âŸģ
194
+
195
+ âļ Remaining: Order Confirmation (0/2 tests)
196
+ ```
197
+
198
+ ### AI-Optimized Output (Markdown)
199
+
200
+ Generates structured markdown summaries perfect for AI analysis:
201
+
202
+ ```markdown
203
+ # Test Results: E2E Payment Flow
204
+
205
+ **Status**: ❌ FAILED (2/3 test suites passed)
206
+ **Duration**: 15.4s
207
+
208
+ ## ✅ Authentication Suite (2/2 tests, 1.2s)
209
+ All tests passed.
210
+
211
+ ## ❌ Payment Processing (1/2 tests, 8.3s)
212
+
213
+ ### ❌ Payment Submission (5.1s - FAILED)
214
+
215
+ **Error**: Timeout waiting for element
216
+ **Location**: tests/payment.spec.ts:45:12
217
+
218
+ **Steps Executed**:
219
+ 1. ✅ Navigate to /checkout (189ms)
220
+ 2. ✅ Fill payment form (456ms)
221
+ 3. ❌ Click submit button - Element not found
222
+
223
+ **Artifacts**:
224
+ - Screenshot: ./test-results/payment-fail-001.png
225
+ - Trace: ./test-results/trace.zip
226
+ ```
227
+
228
+ ## Why fair-playwright?
229
+
230
+ - **For Developers**: Progressive output keeps you focused on what matters
231
+ - **For AI**: Structured markdown summaries help AI understand test failures instantly
232
+ - **For Teams**: Hierarchical steps document test flows automatically
233
+
234
+ ## Development
235
+
236
+ ```bash
237
+ # Install dependencies
238
+ npm install
239
+
240
+ # Build
241
+ npm run build
242
+
243
+ # Run tests
244
+ npm test
245
+
246
+ # Run integration tests
247
+ npm run test:integration
248
+ ```
249
+
250
+ ## License
251
+
252
+ MIT ÂĐ [Baran Aytas](https://github.com/baranaytass)
253
+
254
+ ## Contributing
255
+
256
+ Contributions are welcome! Please feel free to submit a Pull Request.
257
+
258
+ ## Links
259
+
260
+ - [GitHub Repository](https://github.com/baranaytass/fair-playwright)
261
+ - [Issue Tracker](https://github.com/baranaytass/fair-playwright/issues)
262
+ - [npm Package](https://www.npmjs.com/package/fair-playwright)