@zest-pw/test 1.0.5 → 1.0.6
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 +22 -22
- package/README.md +408 -408
- package/dist/zephyr-api/get-results-from-json.d.ts.map +1 -1
- package/dist/zephyr-api/get-results-from-json.js +11 -3
- package/package.json +54 -54
package/LICENSE
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Zest Playwright Team
|
|
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.
|
|
22
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Zest Playwright Team
|
|
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.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -1,408 +1,408 @@
|
|
|
1
|
-
# Zest Playwright Test Framework
|
|
2
|
-
|
|
3
|
-
Advanced Playwright test framework with automatic screenshots, custom reporting, and Zephyr Scale integration.
|
|
4
|
-
|
|
5
|
-
## ✨ Features
|
|
6
|
-
|
|
7
|
-
- 📸 **Automatic Screenshots** - Capture screenshots after each test step
|
|
8
|
-
- 📊 **Custom JSON Reports** - Detailed test results with step information
|
|
9
|
-
- 🔄 **Zephyr Scale Integration** - Automatically update test results in Zephyr
|
|
10
|
-
- ⚙️ **Type-Safe Configuration** - Configure behavior via `zest.config.ts`
|
|
11
|
-
- 🎯 **Step-by-Step Tracking** - Detailed information about each test step
|
|
12
|
-
- 🖼️ **Base64 Screenshots in Reports** - Screenshots embedded directly in JSON
|
|
13
|
-
|
|
14
|
-
## 🚀 Quick Start
|
|
15
|
-
|
|
16
|
-
### Requirements
|
|
17
|
-
|
|
18
|
-
- Node.js >= 18.0.0
|
|
19
|
-
- Playwright (peer dependency)
|
|
20
|
-
|
|
21
|
-
### 1. Install the Package
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install --save-dev @zest-pw/test
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### 2. Configuration
|
|
28
|
-
|
|
29
|
-
The configuration file `zest.config.ts` will be automatically created in your project root after installation.
|
|
30
|
-
|
|
31
|
-
The default configuration:
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
import { defineZestConfig } from '@zest-pw/test';
|
|
35
|
-
|
|
36
|
-
export default defineZestConfig({
|
|
37
|
-
reporter: {
|
|
38
|
-
saveJsonReport: true,
|
|
39
|
-
printToConsole: true,
|
|
40
|
-
outputDir: 'test-results',
|
|
41
|
-
},
|
|
42
|
-
screenshots: {
|
|
43
|
-
enabled: true,
|
|
44
|
-
includeInReport: true,
|
|
45
|
-
onlyOnFailure: false,
|
|
46
|
-
},
|
|
47
|
-
zephyr: {
|
|
48
|
-
enabled: false,
|
|
49
|
-
updateResults: false,
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### 3. Configure Playwright
|
|
55
|
-
|
|
56
|
-
Update your `playwright.config.ts`:
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
import { defineConfig } from '@playwright/test';
|
|
60
|
-
|
|
61
|
-
export default defineConfig({
|
|
62
|
-
reporter: [
|
|
63
|
-
['list'],
|
|
64
|
-
['@zest-pw/test/reporter'], // Add Zest reporter
|
|
65
|
-
],
|
|
66
|
-
// ... other Playwright config
|
|
67
|
-
});
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### 4. Write Your First Test
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
import { test, expect } from '@zest-pw/test';
|
|
74
|
-
|
|
75
|
-
test('TC-001: Check the title', async ({ page }) => {
|
|
76
|
-
|
|
77
|
-
await test.step('Go to the playwright website', async () => {
|
|
78
|
-
await page.goto('https://playwright.dev/');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
await test.step('Check the title', async () => {
|
|
82
|
-
await expect(page).toHaveTitle(/Playwright/);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### 5. Run Tests
|
|
88
|
-
|
|
89
|
-
```bash
|
|
90
|
-
npx playwright test
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## ⚙️ Configuration
|
|
94
|
-
|
|
95
|
-
### Configuration File
|
|
96
|
-
|
|
97
|
-
The `zest.config.ts` file is automatically created when you install the package. You can customize it as needed:
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
import { defineZestConfig } from '@zest-pw/test';
|
|
101
|
-
|
|
102
|
-
export default defineZestConfig({
|
|
103
|
-
reporter: {
|
|
104
|
-
// Save test results to JSON file
|
|
105
|
-
saveJsonReport: true,
|
|
106
|
-
|
|
107
|
-
// Output directory for reports
|
|
108
|
-
outputDir: 'test-results',
|
|
109
|
-
|
|
110
|
-
// Print test results to console
|
|
111
|
-
printToConsole: false,
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
screenshots: {
|
|
115
|
-
// Enable screenshot capture
|
|
116
|
-
enabled: true,
|
|
117
|
-
|
|
118
|
-
// Include screenshots in JSON report
|
|
119
|
-
includeInReport: true,
|
|
120
|
-
|
|
121
|
-
// Capture screenshots only on failure
|
|
122
|
-
onlyOnFailure: false,
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
zephyr: {
|
|
126
|
-
// Enable Zephyr Scale integration
|
|
127
|
-
enabled: false,
|
|
128
|
-
|
|
129
|
-
// Update test results in Zephyr after test run
|
|
130
|
-
updateResults: false,
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
For detailed configuration options, see [CONFIG.md](./CONFIG.md).
|
|
136
|
-
|
|
137
|
-
## 📸 Screenshots
|
|
138
|
-
|
|
139
|
-
Screenshots are automatically captured after each `test.step()` and:
|
|
140
|
-
- **Embedded in JSON report** as base64 (if `includeInReport: true`)
|
|
141
|
-
- **Named descriptively** based on step title and index
|
|
142
|
-
- **Include error screenshots** when tests fail
|
|
143
|
-
|
|
144
|
-
### Screenshot Settings
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
screenshots: {
|
|
148
|
-
enabled: true, // Enable/disable screenshots
|
|
149
|
-
includeInReport: true, // Include in JSON report
|
|
150
|
-
onlyOnFailure: false, // Capture only on test failure
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### Example Screenshot Output
|
|
155
|
-
|
|
156
|
-
```json
|
|
157
|
-
{
|
|
158
|
-
"fileName": "step_1_go_to_the_playwright_website.png",
|
|
159
|
-
"image": "image/png",
|
|
160
|
-
"body": "base64_encoded_screenshot..."
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
## 📊 Test Reports
|
|
165
|
-
|
|
166
|
-
### JSON Report
|
|
167
|
-
|
|
168
|
-
Test results are automatically saved to `test-results/test-results.json`:
|
|
169
|
-
|
|
170
|
-
```json
|
|
171
|
-
{
|
|
172
|
-
"tests": [
|
|
173
|
-
{
|
|
174
|
-
"projectName": "chromium",
|
|
175
|
-
"testTitle": "Check the title",
|
|
176
|
-
"testCaseKey": "TC-001",
|
|
177
|
-
"steps": [
|
|
178
|
-
{
|
|
179
|
-
"stepTitle": "Go to the playwright website",
|
|
180
|
-
"actualResult": [...],
|
|
181
|
-
"statusName": "pass"
|
|
182
|
-
}
|
|
183
|
-
]
|
|
184
|
-
}
|
|
185
|
-
]
|
|
186
|
-
}
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
### Console Output
|
|
190
|
-
|
|
191
|
-
Enable console output in your config:
|
|
192
|
-
|
|
193
|
-
```typescript
|
|
194
|
-
reporter: {
|
|
195
|
-
printToConsole: true,
|
|
196
|
-
}
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
## 🔄 Zephyr Scale Integration
|
|
200
|
-
|
|
201
|
-
### Setup
|
|
202
|
-
|
|
203
|
-
1. Add environment variables:
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
# .env
|
|
207
|
-
ZEPHYR_API_URL=https://api.zephyrscale.smartbear.com/v2/
|
|
208
|
-
ZEPHYR_API_KEY=your-api-key
|
|
209
|
-
ZEPHYR_TEST_CYCLE_KEY=TEST-CYCLE-123
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
2. Enable in configuration:
|
|
213
|
-
|
|
214
|
-
```typescript
|
|
215
|
-
zephyr: {
|
|
216
|
-
enabled: true,
|
|
217
|
-
updateResults: true,
|
|
218
|
-
}
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
3. Run tests - results will be automatically sent to Zephyr!
|
|
222
|
-
|
|
223
|
-
### How it Works
|
|
224
|
-
|
|
225
|
-
- Test case keys are extracted from test file names (e.g., `TC-001.spec.ts` → `TC-001`)
|
|
226
|
-
- After test execution, results are sent to Zephyr Scale
|
|
227
|
-
- Test steps are updated with actual results and screenshots
|
|
228
|
-
|
|
229
|
-
## 🛠️ Project Structure
|
|
230
|
-
|
|
231
|
-
```
|
|
232
|
-
your-project/
|
|
233
|
-
├── node_modules/
|
|
234
|
-
│ └── @zest-pw/
|
|
235
|
-
│ └── test/ # Installed package
|
|
236
|
-
├── tests/ # Test files
|
|
237
|
-
│ ├── TC-001.spec.ts
|
|
238
|
-
│ └── TC-002.spec.ts
|
|
239
|
-
├── test-results/ # Test results
|
|
240
|
-
│ └── test-results.json
|
|
241
|
-
├── zest.config.ts # Zest configuration (auto-created)
|
|
242
|
-
├── playwright.config.ts # Playwright configuration
|
|
243
|
-
└── package.json
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
## 📝 Writing Tests
|
|
247
|
-
|
|
248
|
-
### Basic Test Structure
|
|
249
|
-
|
|
250
|
-
```typescript
|
|
251
|
-
import { test, expect } from '@zest-pw/test';
|
|
252
|
-
|
|
253
|
-
test('TC-001: Test description', async ({ page }) => {
|
|
254
|
-
|
|
255
|
-
await test.step('Step 1 description', async () => {
|
|
256
|
-
// Your test code
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
await test.step('Step 2 description', async () => {
|
|
260
|
-
// Your test code
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
### Test Naming Convention
|
|
266
|
-
|
|
267
|
-
Name your test files with test case keys for Zephyr integration:
|
|
268
|
-
|
|
269
|
-
```
|
|
270
|
-
tests/
|
|
271
|
-
├── TC-001.spec.ts ✅ Good - extracts "TC-001"
|
|
272
|
-
├── TC-002.spec.ts ✅ Good - extracts "TC-002"
|
|
273
|
-
└── login.spec.ts ⚠️ Will not sync with Zephyr
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
### Best Practices
|
|
277
|
-
|
|
278
|
-
1. **Use descriptive step names** - they become screenshot filenames
|
|
279
|
-
2. **One test per file** - easier to manage and sync with Zephyr
|
|
280
|
-
3. **Keep steps atomic** - each step should be a single action or assertion
|
|
281
|
-
4. **Use test case keys** - for Zephyr integration
|
|
282
|
-
|
|
283
|
-
## 💡 Commands
|
|
284
|
-
|
|
285
|
-
```bash
|
|
286
|
-
# Run all tests
|
|
287
|
-
npx playwright test
|
|
288
|
-
|
|
289
|
-
# Run specific test
|
|
290
|
-
npx playwright test tests/TC-001.spec.ts
|
|
291
|
-
|
|
292
|
-
# Run in headed mode
|
|
293
|
-
npx playwright test --headed
|
|
294
|
-
|
|
295
|
-
# Run in debug mode
|
|
296
|
-
npx playwright test --debug
|
|
297
|
-
|
|
298
|
-
# Run with UI
|
|
299
|
-
npx playwright test --ui
|
|
300
|
-
|
|
301
|
-
# Generate Playwright report
|
|
302
|
-
npx playwright show-report
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
## 🔧 Advanced Usage
|
|
306
|
-
|
|
307
|
-
### Custom Configuration per Environment
|
|
308
|
-
|
|
309
|
-
```typescript
|
|
310
|
-
const isDev = process.env.NODE_ENV === 'development';
|
|
311
|
-
const isCI = process.env.CI === 'true';
|
|
312
|
-
|
|
313
|
-
export default defineZestConfig({
|
|
314
|
-
reporter: {
|
|
315
|
-
printToConsole: isDev,
|
|
316
|
-
},
|
|
317
|
-
screenshots: {
|
|
318
|
-
onlyOnFailure: isCI,
|
|
319
|
-
},
|
|
320
|
-
zephyr: {
|
|
321
|
-
enabled: isCI,
|
|
322
|
-
updateResults: isCI,
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
### Accessing Configuration in Code
|
|
328
|
-
|
|
329
|
-
```typescript
|
|
330
|
-
import { getZestConfig } from '@zest-pw/test';
|
|
331
|
-
|
|
332
|
-
const config = getZestConfig();
|
|
333
|
-
console.log('Screenshots enabled:', config.screenshots.enabled);
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
### Programmatic Configuration
|
|
337
|
-
|
|
338
|
-
```typescript
|
|
339
|
-
import { defineZestConfig } from '@zest-pw/test';
|
|
340
|
-
|
|
341
|
-
export default defineZestConfig({
|
|
342
|
-
reporter: {
|
|
343
|
-
saveJsonReport: process.env.SAVE_REPORTS !== 'false',
|
|
344
|
-
outputDir: process.env.REPORT_DIR || 'test-results',
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
## 🐛 Troubleshooting
|
|
350
|
-
|
|
351
|
-
### Configuration file setup
|
|
352
|
-
|
|
353
|
-
The `zest.config.ts` file is automatically created when you install the package. If it wasn't created, you can create it manually using the template from the Configuration section.
|
|
354
|
-
|
|
355
|
-
### Screenshots not appearing in report
|
|
356
|
-
|
|
357
|
-
Check your configuration:
|
|
358
|
-
```typescript
|
|
359
|
-
screenshots: {
|
|
360
|
-
enabled: true,
|
|
361
|
-
includeInReport: true,
|
|
362
|
-
}
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
### Zephyr integration not working
|
|
366
|
-
|
|
367
|
-
1. Verify environment variables are set
|
|
368
|
-
2. Check test case keys match Zephyr format
|
|
369
|
-
3. Enable Zephyr in configuration
|
|
370
|
-
4. Check API credentials and permissions
|
|
371
|
-
|
|
372
|
-
### JSON report not saved
|
|
373
|
-
|
|
374
|
-
Ensure configuration allows saving:
|
|
375
|
-
```typescript
|
|
376
|
-
reporter: {
|
|
377
|
-
saveJsonReport: true,
|
|
378
|
-
}
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
### Import errors
|
|
382
|
-
|
|
383
|
-
Make sure you're importing from the installed package:
|
|
384
|
-
|
|
385
|
-
```typescript
|
|
386
|
-
// ✅ Correct
|
|
387
|
-
import { test, expect, defineZestConfig } from '@zest-pw/test';
|
|
388
|
-
|
|
389
|
-
// ❌ Incorrect (old local paths)
|
|
390
|
-
import { test, expect } from './zest-pw/fixtures/fixtures';
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
## 📚 Documentation
|
|
394
|
-
|
|
395
|
-
- [Configuration Guide](./CONFIG.md) - Detailed configuration options
|
|
396
|
-
- [Playwright Documentation](https://playwright.dev/) - Official Playwright docs
|
|
397
|
-
- [Zephyr Scale API](https://support.smartbear.com/zephyr-scale-cloud/api-docs/) - Zephyr API reference
|
|
398
|
-
|
|
399
|
-
## 🤝 Contributing
|
|
400
|
-
|
|
401
|
-
1. Fork the repository
|
|
402
|
-
2. Create a feature branch
|
|
403
|
-
3. Make your changes
|
|
404
|
-
4. Submit a pull request
|
|
405
|
-
|
|
406
|
-
## 📄 License
|
|
407
|
-
|
|
408
|
-
MIT License - see LICENSE file for details
|
|
1
|
+
# Zest Playwright Test Framework
|
|
2
|
+
|
|
3
|
+
Advanced Playwright test framework with automatic screenshots, custom reporting, and Zephyr Scale integration.
|
|
4
|
+
|
|
5
|
+
## ✨ Features
|
|
6
|
+
|
|
7
|
+
- 📸 **Automatic Screenshots** - Capture screenshots after each test step
|
|
8
|
+
- 📊 **Custom JSON Reports** - Detailed test results with step information
|
|
9
|
+
- 🔄 **Zephyr Scale Integration** - Automatically update test results in Zephyr
|
|
10
|
+
- ⚙️ **Type-Safe Configuration** - Configure behavior via `zest.config.ts`
|
|
11
|
+
- 🎯 **Step-by-Step Tracking** - Detailed information about each test step
|
|
12
|
+
- 🖼️ **Base64 Screenshots in Reports** - Screenshots embedded directly in JSON
|
|
13
|
+
|
|
14
|
+
## 🚀 Quick Start
|
|
15
|
+
|
|
16
|
+
### Requirements
|
|
17
|
+
|
|
18
|
+
- Node.js >= 18.0.0
|
|
19
|
+
- Playwright (peer dependency)
|
|
20
|
+
|
|
21
|
+
### 1. Install the Package
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install --save-dev @zest-pw/test
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 2. Configuration
|
|
28
|
+
|
|
29
|
+
The configuration file `zest.config.ts` will be automatically created in your project root after installation.
|
|
30
|
+
|
|
31
|
+
The default configuration:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { defineZestConfig } from '@zest-pw/test';
|
|
35
|
+
|
|
36
|
+
export default defineZestConfig({
|
|
37
|
+
reporter: {
|
|
38
|
+
saveJsonReport: true,
|
|
39
|
+
printToConsole: true,
|
|
40
|
+
outputDir: 'test-results',
|
|
41
|
+
},
|
|
42
|
+
screenshots: {
|
|
43
|
+
enabled: true,
|
|
44
|
+
includeInReport: true,
|
|
45
|
+
onlyOnFailure: false,
|
|
46
|
+
},
|
|
47
|
+
zephyr: {
|
|
48
|
+
enabled: false,
|
|
49
|
+
updateResults: false,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 3. Configure Playwright
|
|
55
|
+
|
|
56
|
+
Update your `playwright.config.ts`:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { defineConfig } from '@playwright/test';
|
|
60
|
+
|
|
61
|
+
export default defineConfig({
|
|
62
|
+
reporter: [
|
|
63
|
+
['list'],
|
|
64
|
+
['@zest-pw/test/reporter'], // Add Zest reporter
|
|
65
|
+
],
|
|
66
|
+
// ... other Playwright config
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 4. Write Your First Test
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { test, expect } from '@zest-pw/test';
|
|
74
|
+
|
|
75
|
+
test('TC-001: Check the title', async ({ page }) => {
|
|
76
|
+
|
|
77
|
+
await test.step('Go to the playwright website', async () => {
|
|
78
|
+
await page.goto('https://playwright.dev/');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
await test.step('Check the title', async () => {
|
|
82
|
+
await expect(page).toHaveTitle(/Playwright/);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 5. Run Tests
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npx playwright test
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## ⚙️ Configuration
|
|
94
|
+
|
|
95
|
+
### Configuration File
|
|
96
|
+
|
|
97
|
+
The `zest.config.ts` file is automatically created when you install the package. You can customize it as needed:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { defineZestConfig } from '@zest-pw/test';
|
|
101
|
+
|
|
102
|
+
export default defineZestConfig({
|
|
103
|
+
reporter: {
|
|
104
|
+
// Save test results to JSON file
|
|
105
|
+
saveJsonReport: true,
|
|
106
|
+
|
|
107
|
+
// Output directory for reports
|
|
108
|
+
outputDir: 'test-results',
|
|
109
|
+
|
|
110
|
+
// Print test results to console
|
|
111
|
+
printToConsole: false,
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
screenshots: {
|
|
115
|
+
// Enable screenshot capture
|
|
116
|
+
enabled: true,
|
|
117
|
+
|
|
118
|
+
// Include screenshots in JSON report
|
|
119
|
+
includeInReport: true,
|
|
120
|
+
|
|
121
|
+
// Capture screenshots only on failure
|
|
122
|
+
onlyOnFailure: false,
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
zephyr: {
|
|
126
|
+
// Enable Zephyr Scale integration
|
|
127
|
+
enabled: false,
|
|
128
|
+
|
|
129
|
+
// Update test results in Zephyr after test run
|
|
130
|
+
updateResults: false,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
For detailed configuration options, see [CONFIG.md](./CONFIG.md).
|
|
136
|
+
|
|
137
|
+
## 📸 Screenshots
|
|
138
|
+
|
|
139
|
+
Screenshots are automatically captured after each `test.step()` and:
|
|
140
|
+
- **Embedded in JSON report** as base64 (if `includeInReport: true`)
|
|
141
|
+
- **Named descriptively** based on step title and index
|
|
142
|
+
- **Include error screenshots** when tests fail
|
|
143
|
+
|
|
144
|
+
### Screenshot Settings
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
screenshots: {
|
|
148
|
+
enabled: true, // Enable/disable screenshots
|
|
149
|
+
includeInReport: true, // Include in JSON report
|
|
150
|
+
onlyOnFailure: false, // Capture only on test failure
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Example Screenshot Output
|
|
155
|
+
|
|
156
|
+
```json
|
|
157
|
+
{
|
|
158
|
+
"fileName": "step_1_go_to_the_playwright_website.png",
|
|
159
|
+
"image": "image/png",
|
|
160
|
+
"body": "base64_encoded_screenshot..."
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 📊 Test Reports
|
|
165
|
+
|
|
166
|
+
### JSON Report
|
|
167
|
+
|
|
168
|
+
Test results are automatically saved to `test-results/test-results.json`:
|
|
169
|
+
|
|
170
|
+
```json
|
|
171
|
+
{
|
|
172
|
+
"tests": [
|
|
173
|
+
{
|
|
174
|
+
"projectName": "chromium",
|
|
175
|
+
"testTitle": "Check the title",
|
|
176
|
+
"testCaseKey": "TC-001",
|
|
177
|
+
"steps": [
|
|
178
|
+
{
|
|
179
|
+
"stepTitle": "Go to the playwright website",
|
|
180
|
+
"actualResult": [...],
|
|
181
|
+
"statusName": "pass"
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Console Output
|
|
190
|
+
|
|
191
|
+
Enable console output in your config:
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
reporter: {
|
|
195
|
+
printToConsole: true,
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## 🔄 Zephyr Scale Integration
|
|
200
|
+
|
|
201
|
+
### Setup
|
|
202
|
+
|
|
203
|
+
1. Add environment variables:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# .env
|
|
207
|
+
ZEPHYR_API_URL=https://api.zephyrscale.smartbear.com/v2/
|
|
208
|
+
ZEPHYR_API_KEY=your-api-key
|
|
209
|
+
ZEPHYR_TEST_CYCLE_KEY=TEST-CYCLE-123
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
2. Enable in configuration:
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
zephyr: {
|
|
216
|
+
enabled: true,
|
|
217
|
+
updateResults: true,
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
3. Run tests - results will be automatically sent to Zephyr!
|
|
222
|
+
|
|
223
|
+
### How it Works
|
|
224
|
+
|
|
225
|
+
- Test case keys are extracted from test file names (e.g., `TC-001.spec.ts` → `TC-001`)
|
|
226
|
+
- After test execution, results are sent to Zephyr Scale
|
|
227
|
+
- Test steps are updated with actual results and screenshots
|
|
228
|
+
|
|
229
|
+
## 🛠️ Project Structure
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
your-project/
|
|
233
|
+
├── node_modules/
|
|
234
|
+
│ └── @zest-pw/
|
|
235
|
+
│ └── test/ # Installed package
|
|
236
|
+
├── tests/ # Test files
|
|
237
|
+
│ ├── TC-001.spec.ts
|
|
238
|
+
│ └── TC-002.spec.ts
|
|
239
|
+
├── test-results/ # Test results
|
|
240
|
+
│ └── test-results.json
|
|
241
|
+
├── zest.config.ts # Zest configuration (auto-created)
|
|
242
|
+
├── playwright.config.ts # Playwright configuration
|
|
243
|
+
└── package.json
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## 📝 Writing Tests
|
|
247
|
+
|
|
248
|
+
### Basic Test Structure
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
import { test, expect } from '@zest-pw/test';
|
|
252
|
+
|
|
253
|
+
test('TC-001: Test description', async ({ page }) => {
|
|
254
|
+
|
|
255
|
+
await test.step('Step 1 description', async () => {
|
|
256
|
+
// Your test code
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
await test.step('Step 2 description', async () => {
|
|
260
|
+
// Your test code
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Test Naming Convention
|
|
266
|
+
|
|
267
|
+
Name your test files with test case keys for Zephyr integration:
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
tests/
|
|
271
|
+
├── TC-001.spec.ts ✅ Good - extracts "TC-001"
|
|
272
|
+
├── TC-002.spec.ts ✅ Good - extracts "TC-002"
|
|
273
|
+
└── login.spec.ts ⚠️ Will not sync with Zephyr
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Best Practices
|
|
277
|
+
|
|
278
|
+
1. **Use descriptive step names** - they become screenshot filenames
|
|
279
|
+
2. **One test per file** - easier to manage and sync with Zephyr
|
|
280
|
+
3. **Keep steps atomic** - each step should be a single action or assertion
|
|
281
|
+
4. **Use test case keys** - for Zephyr integration
|
|
282
|
+
|
|
283
|
+
## 💡 Commands
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
# Run all tests
|
|
287
|
+
npx playwright test
|
|
288
|
+
|
|
289
|
+
# Run specific test
|
|
290
|
+
npx playwright test tests/TC-001.spec.ts
|
|
291
|
+
|
|
292
|
+
# Run in headed mode
|
|
293
|
+
npx playwright test --headed
|
|
294
|
+
|
|
295
|
+
# Run in debug mode
|
|
296
|
+
npx playwright test --debug
|
|
297
|
+
|
|
298
|
+
# Run with UI
|
|
299
|
+
npx playwright test --ui
|
|
300
|
+
|
|
301
|
+
# Generate Playwright report
|
|
302
|
+
npx playwright show-report
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## 🔧 Advanced Usage
|
|
306
|
+
|
|
307
|
+
### Custom Configuration per Environment
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
const isDev = process.env.NODE_ENV === 'development';
|
|
311
|
+
const isCI = process.env.CI === 'true';
|
|
312
|
+
|
|
313
|
+
export default defineZestConfig({
|
|
314
|
+
reporter: {
|
|
315
|
+
printToConsole: isDev,
|
|
316
|
+
},
|
|
317
|
+
screenshots: {
|
|
318
|
+
onlyOnFailure: isCI,
|
|
319
|
+
},
|
|
320
|
+
zephyr: {
|
|
321
|
+
enabled: isCI,
|
|
322
|
+
updateResults: isCI,
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Accessing Configuration in Code
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
import { getZestConfig } from '@zest-pw/test';
|
|
331
|
+
|
|
332
|
+
const config = getZestConfig();
|
|
333
|
+
console.log('Screenshots enabled:', config.screenshots.enabled);
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Programmatic Configuration
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
import { defineZestConfig } from '@zest-pw/test';
|
|
340
|
+
|
|
341
|
+
export default defineZestConfig({
|
|
342
|
+
reporter: {
|
|
343
|
+
saveJsonReport: process.env.SAVE_REPORTS !== 'false',
|
|
344
|
+
outputDir: process.env.REPORT_DIR || 'test-results',
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## 🐛 Troubleshooting
|
|
350
|
+
|
|
351
|
+
### Configuration file setup
|
|
352
|
+
|
|
353
|
+
The `zest.config.ts` file is automatically created when you install the package. If it wasn't created, you can create it manually using the template from the Configuration section.
|
|
354
|
+
|
|
355
|
+
### Screenshots not appearing in report
|
|
356
|
+
|
|
357
|
+
Check your configuration:
|
|
358
|
+
```typescript
|
|
359
|
+
screenshots: {
|
|
360
|
+
enabled: true,
|
|
361
|
+
includeInReport: true,
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Zephyr integration not working
|
|
366
|
+
|
|
367
|
+
1. Verify environment variables are set
|
|
368
|
+
2. Check test case keys match Zephyr format
|
|
369
|
+
3. Enable Zephyr in configuration
|
|
370
|
+
4. Check API credentials and permissions
|
|
371
|
+
|
|
372
|
+
### JSON report not saved
|
|
373
|
+
|
|
374
|
+
Ensure configuration allows saving:
|
|
375
|
+
```typescript
|
|
376
|
+
reporter: {
|
|
377
|
+
saveJsonReport: true,
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### Import errors
|
|
382
|
+
|
|
383
|
+
Make sure you're importing from the installed package:
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
// ✅ Correct
|
|
387
|
+
import { test, expect, defineZestConfig } from '@zest-pw/test';
|
|
388
|
+
|
|
389
|
+
// ❌ Incorrect (old local paths)
|
|
390
|
+
import { test, expect } from './zest-pw/fixtures/fixtures';
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
## 📚 Documentation
|
|
394
|
+
|
|
395
|
+
- [Configuration Guide](./CONFIG.md) - Detailed configuration options
|
|
396
|
+
- [Playwright Documentation](https://playwright.dev/) - Official Playwright docs
|
|
397
|
+
- [Zephyr Scale API](https://support.smartbear.com/zephyr-scale-cloud/api-docs/) - Zephyr API reference
|
|
398
|
+
|
|
399
|
+
## 🤝 Contributing
|
|
400
|
+
|
|
401
|
+
1. Fork the repository
|
|
402
|
+
2. Create a feature branch
|
|
403
|
+
3. Make your changes
|
|
404
|
+
4. Submit a pull request
|
|
405
|
+
|
|
406
|
+
## 📄 License
|
|
407
|
+
|
|
408
|
+
MIT License - see LICENSE file for details
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-results-from-json.d.ts","sourceRoot":"","sources":["../../zephyr-api/get-results-from-json.ts"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,wBAAsB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"get-results-from-json.d.ts","sourceRoot":"","sources":["../../zephyr-api/get-results-from-json.ts"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,wBAAsB,kBAAkB,iBAwCvC"}
|
|
@@ -67,15 +67,23 @@ async function getResultsFromJson() {
|
|
|
67
67
|
const { projectName, testTitle, testCaseKey, ...testData } = test;
|
|
68
68
|
acc[testCaseKey] = {
|
|
69
69
|
...testData,
|
|
70
|
-
steps: test.steps.map(({ stepTitle, actualResult, ...step }) => {
|
|
70
|
+
steps: test.steps.map(({ stepTitle, actualResult, error, ...step }) => {
|
|
71
71
|
let processedActualResult = actualResult;
|
|
72
|
+
let processedError = error;
|
|
72
73
|
if (actualResult && Array.isArray(actualResult)) {
|
|
73
74
|
processedActualResult = actualResult.map(item => {
|
|
74
|
-
return `<img src="data:${item.image || ''};base64,${item.body || ''}" alt="${item.fileName || ''}">`;
|
|
75
|
+
return `<img src="data:${item.image || ''};base64,${item.body || ''}" alt="${item.fileName || ''}" style="margin-left: 0!important; max-width: 900px;">`;
|
|
75
76
|
}).join('');
|
|
76
77
|
}
|
|
78
|
+
if (error) {
|
|
79
|
+
let cleanMessage = error.message.replace(/\x1b\[[0-9;]*m/g, '');
|
|
80
|
+
cleanMessage = cleanMessage.split('Call log:')[0].trim();
|
|
81
|
+
const errorMessage = cleanMessage.split('\n').map(line => line.trimStart()).join('<br>');
|
|
82
|
+
const errorHtml = `<div style="min-width: 800px; margin: 5px; max-width: 900px;"><div style="background-color: #d32f2f; color: white; text-align: center; font-family: monospace; font-size: 16px;">ERROR</div><div style="padding: 15px; font-family: monospace; white-space: pre-wrap;">${errorMessage}</div><div style="background-color: #d32f2f; color: white; text-align: center; font-family: monospace; font-size: 16px;">ERROR</div></div>`;
|
|
83
|
+
processedError = errorHtml;
|
|
84
|
+
}
|
|
77
85
|
return {
|
|
78
|
-
actualResult: processedActualResult,
|
|
86
|
+
actualResult: processedError + '\n' + processedActualResult,
|
|
79
87
|
...step
|
|
80
88
|
};
|
|
81
89
|
})
|
package/package.json
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@zest-pw/test",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Advanced Playwright test framework with automatic screenshots, custom reporting, and Zephyr Scale integration",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"default": "./dist/index.js",
|
|
10
|
-
"types": "./dist/index.d.ts"
|
|
11
|
-
},
|
|
12
|
-
"./reporter": "./dist/reporter/custom-reporter.js"
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"dist",
|
|
16
|
-
"README.md",
|
|
17
|
-
"LICENSE"
|
|
18
|
-
],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsc",
|
|
21
|
-
"prepublishOnly": "npm run build",
|
|
22
|
-
"type-check": "tsc --noEmit"
|
|
23
|
-
},
|
|
24
|
-
"keywords": [
|
|
25
|
-
"playwright",
|
|
26
|
-
"testing",
|
|
27
|
-
"automation",
|
|
28
|
-
"zephyr",
|
|
29
|
-
"zephyr-scale",
|
|
30
|
-
"screenshots",
|
|
31
|
-
"test-framework",
|
|
32
|
-
"test-reporter",
|
|
33
|
-
"e2e",
|
|
34
|
-
"end-to-end"
|
|
35
|
-
],
|
|
36
|
-
"author": "",
|
|
37
|
-
"license": "MIT",
|
|
38
|
-
"repository": {
|
|
39
|
-
"type": "git",
|
|
40
|
-
"url": "git+https://github.com/Capuchin33/zest-pw.git"
|
|
41
|
-
},
|
|
42
|
-
"homepage": "https://github.com/Capuchin33/zest-pw#readme",
|
|
43
|
-
"bugs": {
|
|
44
|
-
"url": "https://github.com/Capuchin33/zest-pw/issues"
|
|
45
|
-
},
|
|
46
|
-
"engines": {
|
|
47
|
-
"node": ">=18.0.0"
|
|
48
|
-
},
|
|
49
|
-
"devDependencies": {
|
|
50
|
-
"@playwright/test": "^1.40.0",
|
|
51
|
-
"@types/node": "^20.0.0",
|
|
52
|
-
"typescript": "^5.0.0"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@zest-pw/test",
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "Advanced Playwright test framework with automatic screenshots, custom reporting, and Zephyr Scale integration",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"default": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./reporter": "./dist/reporter/custom-reporter.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"prepublishOnly": "npm run build",
|
|
22
|
+
"type-check": "tsc --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"playwright",
|
|
26
|
+
"testing",
|
|
27
|
+
"automation",
|
|
28
|
+
"zephyr",
|
|
29
|
+
"zephyr-scale",
|
|
30
|
+
"screenshots",
|
|
31
|
+
"test-framework",
|
|
32
|
+
"test-reporter",
|
|
33
|
+
"e2e",
|
|
34
|
+
"end-to-end"
|
|
35
|
+
],
|
|
36
|
+
"author": "",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/Capuchin33/zest-pw.git"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/Capuchin33/zest-pw#readme",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/Capuchin33/zest-pw/issues"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@playwright/test": "^1.40.0",
|
|
51
|
+
"@types/node": "^20.0.0",
|
|
52
|
+
"typescript": "^5.0.0"
|
|
53
|
+
}
|
|
54
|
+
}
|