@ash-mallick/browserstack-sync 1.3.0 → 1.3.1
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/README.md +100 -333
- package/lib/browserstack.js +106 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,188 +1,151 @@
|
|
|
1
1
|
# @ash-mallick/browserstack-sync
|
|
2
2
|
|
|
3
|
-
Sync
|
|
4
|
-
|
|
5
|
-
**🦙 FREE AI analysis** using **Ollama** — runs 100% locally, no data sent to cloud!
|
|
3
|
+
Sync Playwright/Cypress tests to BrowserStack Test Management with AI-powered test step extraction.
|
|
6
4
|
|
|
7
5
|
**By Ashutosh Mallick**
|
|
8
6
|
|
|
9
7
|
---
|
|
10
8
|
|
|
11
|
-
##
|
|
9
|
+
## Install
|
|
12
10
|
|
|
13
|
-
### Step 1: Install
|
|
14
11
|
```bash
|
|
15
12
|
npm install @ash-mallick/browserstack-sync
|
|
16
13
|
```
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Quick Setup
|
|
18
|
+
|
|
19
|
+
Create `.env` file:
|
|
20
|
+
|
|
20
21
|
```env
|
|
21
22
|
BROWSERSTACK_USERNAME=your_username
|
|
22
23
|
BROWSERSTACK_ACCESS_KEY=your_access_key
|
|
23
24
|
BROWSERSTACK_PROJECT_ID=PR-XXXX
|
|
24
25
|
```
|
|
25
26
|
|
|
26
|
-
### Step 3: Onboard Tests to BrowserStack
|
|
27
|
-
```bash
|
|
28
|
-
npx am-browserstack-sync --all
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
This will:
|
|
32
|
-
- ✅ Generate CSV files with test cases
|
|
33
|
-
- ✅ Create folders in BrowserStack (one per spec file)
|
|
34
|
-
- ✅ Create/update test cases with AI-generated steps
|
|
35
|
-
|
|
36
27
|
---
|
|
37
28
|
|
|
38
|
-
##
|
|
29
|
+
## Commands
|
|
39
30
|
|
|
40
|
-
|
|
31
|
+
### 1. Generate CSV Files Only (No BrowserStack)
|
|
41
32
|
|
|
42
33
|
```bash
|
|
43
|
-
npx am-browserstack-sync-
|
|
34
|
+
npx am-browserstack-sync --csv-only
|
|
44
35
|
```
|
|
45
36
|
|
|
46
|
-
|
|
37
|
+
Creates CSV files with test cases in `playwright/e2e-csv/` folder.
|
|
47
38
|
|
|
48
|
-
|
|
49
|
-
test:
|
|
50
|
-
script:
|
|
51
|
-
# Your existing test command (add JSON reporter)
|
|
52
|
-
- npx playwright test --reporter=json --output-file=test-results.json
|
|
53
|
-
# Sync results to BrowserStack (add this line)
|
|
54
|
-
- npx am-browserstack-sync-runs --run-name="Pipeline #$CI_PIPELINE_ID"
|
|
55
|
-
```
|
|
39
|
+
---
|
|
56
40
|
|
|
57
|
-
###
|
|
41
|
+
### 2. Onboard Single Spec to BrowserStack
|
|
58
42
|
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
- run: npx am-browserstack-sync-runs --run-name="Build #${{ github.run_number }}"
|
|
43
|
+
```bash
|
|
44
|
+
npx am-browserstack-sync --spec=login.spec
|
|
62
45
|
```
|
|
63
46
|
|
|
64
|
-
|
|
65
|
-
- 📄 Auto-detect your test report file
|
|
66
|
-
- 📊 Parse test results (pass/fail/skip)
|
|
67
|
-
- 🔗 Create a Test Run in BrowserStack
|
|
68
|
-
- ✅ Sync each test result
|
|
69
|
-
- 🔗 Provide a link to view results
|
|
47
|
+
Creates folder and test cases for the specified spec file.
|
|
70
48
|
|
|
71
49
|
---
|
|
72
50
|
|
|
73
|
-
|
|
51
|
+
### 3. Onboard All Specs to BrowserStack
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx am-browserstack-sync --all
|
|
55
|
+
```
|
|
74
56
|
|
|
75
|
-
|
|
76
|
-
|---------|---------|
|
|
77
|
-
| `npx am-browserstack-sync --all` | Onboard tests to BrowserStack (one-time setup) |
|
|
78
|
-
| `npx am-browserstack-sync-runs` | Sync test run results (add to CI pipeline) |
|
|
79
|
-
| `npx am-browserstack-sync --csv-only` | Generate CSVs only (no BrowserStack sync) |
|
|
57
|
+
Creates folders and test cases for all spec files in your project.
|
|
80
58
|
|
|
81
59
|
---
|
|
82
60
|
|
|
83
|
-
|
|
61
|
+
### 4. Sync Test Run Results to BrowserStack
|
|
84
62
|
|
|
85
|
-
|
|
63
|
+
First, run your tests with JSON reporter:
|
|
86
64
|
|
|
87
65
|
```bash
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
# Onboard specific specs
|
|
92
|
-
npx am-browserstack-sync --spec=login.spec,checkout.spec
|
|
93
|
-
|
|
94
|
-
# Generate CSVs only (no BrowserStack)
|
|
95
|
-
npx am-browserstack-sync --csv-only
|
|
66
|
+
npx playwright test --reporter=list,json --output-file=test-results.json
|
|
67
|
+
```
|
|
96
68
|
|
|
97
|
-
|
|
98
|
-
npx am-browserstack-sync --no-ai
|
|
69
|
+
Then sync results:
|
|
99
70
|
|
|
100
|
-
|
|
101
|
-
npx am-browserstack-sync
|
|
71
|
+
```bash
|
|
72
|
+
npx am-browserstack-sync-runs
|
|
102
73
|
```
|
|
103
74
|
|
|
104
|
-
|
|
75
|
+
Or with custom run name:
|
|
105
76
|
|
|
106
77
|
```bash
|
|
107
|
-
|
|
108
|
-
|
|
78
|
+
npx am-browserstack-sync-runs --run-name="Nightly Run"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
109
82
|
|
|
110
|
-
|
|
111
|
-
npx am-browserstack-sync-runs --report=test-results.json
|
|
83
|
+
## GitLab CI Scheduled Job
|
|
112
84
|
|
|
113
|
-
|
|
114
|
-
npx am-browserstack-sync-runs --run-name="Nightly Regression"
|
|
85
|
+
Add to `.gitlab-ci.yml`:
|
|
115
86
|
|
|
116
|
-
|
|
117
|
-
|
|
87
|
+
```yaml
|
|
88
|
+
scheduled_browserstack_sync:
|
|
89
|
+
rules:
|
|
90
|
+
- if: $CI_PIPELINE_SOURCE == "schedule"
|
|
91
|
+
script:
|
|
92
|
+
- npm ci
|
|
93
|
+
- npx playwright test --reporter=list,json --output-file=test-results.json || true
|
|
94
|
+
- npm install @ash-mallick/browserstack-sync
|
|
95
|
+
- npx am-browserstack-sync-runs
|
|
118
96
|
```
|
|
119
97
|
|
|
120
|
-
|
|
98
|
+
Add CI/CD Variables in GitLab (**Settings → CI/CD → Variables**):
|
|
121
99
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
```
|
|
100
|
+
| Key | Value |
|
|
101
|
+
|-----|-------|
|
|
102
|
+
| `BROWSERSTACK_USERNAME` | your_username |
|
|
103
|
+
| `BROWSERSTACK_ACCESS_KEY` | your_access_key |
|
|
104
|
+
| `BROWSERSTACK_PROJECT_ID` | PR-XXXX |
|
|
105
|
+
|
|
106
|
+
Create schedule in **CI/CD → Schedules → New Schedule**.
|
|
131
107
|
|
|
132
108
|
---
|
|
133
109
|
|
|
134
|
-
##
|
|
110
|
+
## All Options Reference
|
|
135
111
|
|
|
136
|
-
|
|
112
|
+
### Onboarding Command (`am-browserstack-sync`)
|
|
137
113
|
|
|
138
|
-
|
|
114
|
+
| Option | Description |
|
|
115
|
+
|--------|-------------|
|
|
116
|
+
| `--csv-only` | Generate CSVs only, do not sync to BrowserStack |
|
|
117
|
+
| `--all` | Sync all spec files without prompting |
|
|
118
|
+
| `--spec=name` | Sync specific spec(s), comma-separated |
|
|
119
|
+
| `--no-ai` | Disable AI step analysis, use regex extraction |
|
|
120
|
+
| `--model=name` | Ollama model to use (default: llama3.2) |
|
|
139
121
|
|
|
140
|
-
|
|
141
|
-
// Your test code:
|
|
142
|
-
test('should log in successfully', async ({ page }) => {
|
|
143
|
-
await page.goto('/login');
|
|
144
|
-
await page.getByLabel(/email/i).fill('user@example.com');
|
|
145
|
-
await page.getByLabel(/password/i).fill('validpassword');
|
|
146
|
-
await page.getByRole('button', { name: /sign in/i }).click();
|
|
147
|
-
await expect(page).toHaveURL(/\/dashboard/);
|
|
148
|
-
});
|
|
149
|
-
```
|
|
122
|
+
### Run Sync Command (`am-browserstack-sync-runs`)
|
|
150
123
|
|
|
151
|
-
|
|
124
|
+
| Option | Description |
|
|
125
|
+
|--------|-------------|
|
|
126
|
+
| `--report=path` | Path to test report file (auto-detects if not specified) |
|
|
127
|
+
| `--run-name=name` | Custom name for the test run |
|
|
128
|
+
| `--format=type` | Report format: `playwright-json` or `junit` |
|
|
152
129
|
|
|
153
|
-
|
|
154
|
-
|------|-----------------|
|
|
155
|
-
| Navigate to /login page | Login page loads successfully |
|
|
156
|
-
| Enter 'user@example.com' in the Email field | Email is entered |
|
|
157
|
-
| Enter 'validpassword' in the Password field | Password is masked and entered |
|
|
158
|
-
| Click the 'Sign In' button | Form is submitted |
|
|
159
|
-
| Verify URL | URL matches /dashboard |
|
|
130
|
+
---
|
|
160
131
|
|
|
161
|
-
|
|
132
|
+
## AI-Powered Test Steps (Optional)
|
|
162
133
|
|
|
163
|
-
|
|
134
|
+
The tool uses Ollama to analyze your test code and generate human-readable test steps. Ollama runs locally - no data sent to cloud, completely free.
|
|
135
|
+
|
|
136
|
+
### Setup Ollama
|
|
164
137
|
|
|
165
|
-
|
|
138
|
+
1. Download from [ollama.ai](https://ollama.ai)
|
|
139
|
+
2. Pull a model:
|
|
166
140
|
```bash
|
|
167
141
|
ollama pull llama3.2
|
|
168
142
|
```
|
|
169
|
-
|
|
170
|
-
3. Start Ollama (runs automatically on macOS, or run manually):
|
|
143
|
+
3. Start Ollama:
|
|
171
144
|
```bash
|
|
172
145
|
ollama serve
|
|
173
146
|
```
|
|
174
147
|
|
|
175
|
-
|
|
176
|
-
```bash
|
|
177
|
-
npx am-browserstack-sync --csv-only
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### Options
|
|
181
|
-
|
|
182
|
-
- `--no-ai` — Disable AI, use regex-based extraction instead
|
|
183
|
-
- `--model=llama3.2` — Use a different Ollama model
|
|
184
|
-
- `OLLAMA_MODEL=llama3.2` — Set default model via env variable
|
|
185
|
-
- `OLLAMA_HOST=http://localhost:11434` — Custom Ollama host
|
|
148
|
+
AI analysis runs automatically when Ollama is running. Use `--no-ai` to disable.
|
|
186
149
|
|
|
187
150
|
### Recommended Models
|
|
188
151
|
|
|
@@ -191,17 +154,16 @@ test('should log in successfully', async ({ page }) => {
|
|
|
191
154
|
| `llama3.2` | 2GB | General purpose, fast (default) |
|
|
192
155
|
| `codellama` | 4GB | Better code understanding |
|
|
193
156
|
| `llama3.2:1b` | 1GB | Fastest, lower quality |
|
|
194
|
-
| `mistral` | 4GB | Good balance |
|
|
195
|
-
|
|
196
|
-
**Fallback:** If Ollama is not running, the tool automatically uses regex-based step extraction, which still provides meaningful steps.
|
|
197
157
|
|
|
198
158
|
---
|
|
199
159
|
|
|
200
|
-
##
|
|
160
|
+
## Configuration (Optional)
|
|
201
161
|
|
|
202
|
-
|
|
162
|
+
Default directories:
|
|
163
|
+
- e2e specs: `playwright/e2e`
|
|
164
|
+
- CSV output: `playwright/e2e-csv`
|
|
203
165
|
|
|
204
|
-
Override via
|
|
166
|
+
Override via `.am-browserstack-sync.json`:
|
|
205
167
|
|
|
206
168
|
```json
|
|
207
169
|
{
|
|
@@ -210,222 +172,27 @@ Override via **`.am-browserstack-sync.json`** in project root:
|
|
|
210
172
|
}
|
|
211
173
|
```
|
|
212
174
|
|
|
213
|
-
Or
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
---
|
|
217
|
-
|
|
218
|
-
## BrowserStack sync
|
|
219
|
-
|
|
220
|
-
Sync pushes your e2e tests into **BrowserStack Test Management** so you can track test cases, link runs, and keep specs in sync with one source of truth. Under your chosen project it creates **one folder per spec file** (e.g. `login.spec`, `checkout.spec`) and one **test case** per test, with title, description, steps, state (Active), type (Functional), automation status, and tags. Existing test cases are matched by title or TC-id and **updated**; new ones are **created**. No duplicates.
|
|
221
|
-
|
|
222
|
-
**Setup:**
|
|
223
|
-
|
|
224
|
-
1. In project root, create **`.env`** (do not commit):
|
|
225
|
-
|
|
226
|
-
```env
|
|
227
|
-
BROWSERSTACK_USERNAME=your_username
|
|
228
|
-
BROWSERSTACK_ACCESS_KEY=your_access_key
|
|
229
|
-
BROWSERSTACK_PROJECT_ID=PR-XXXX
|
|
230
|
-
```
|
|
231
|
-
Or use a single token: `BROWSERSTACK_API_TOKEN=your_token`
|
|
232
|
-
|
|
233
|
-
2. Get credentials and project ID from [Test Management → API keys](https://test-management.browserstack.com/settings/api-keys). The project ID is in the project URL (e.g. `PR-1234`).
|
|
234
|
-
|
|
235
|
-
3. **Install Ollama** for AI-powered step analysis (optional but recommended).
|
|
236
|
-
|
|
237
|
-
4. Run **`npx am-browserstack-sync`** (without `--csv-only`). You'll be prompted to sync all specs or pick specific ones (unless you use `--all` or `--spec=...`). After sync, open your project in BrowserStack to see the new folders and test cases.
|
|
238
|
-
|
|
239
|
-
---
|
|
240
|
-
|
|
241
|
-
## What it does
|
|
242
|
-
|
|
243
|
-
- Finds **Playwright** (`*.spec.*`, `*.test.*`) and **Cypress** (`*.cy.*`) spec files in your e2e dir.
|
|
244
|
-
- Extracts test titles from `test('...')` / `it('...')`, assigns TC-001, TC-002, …
|
|
245
|
-
- **Analyzes test code** with Ollama AI (local, free) or regex to generate human-readable steps and expected results.
|
|
246
|
-
- Enriches with state (Active), type (Functional), automation (automated), tags (from spec + title).
|
|
247
|
-
- Writes **one CSV per spec** (test_case_id, title, state, case_type, steps, expected_results, jira_issues, automation_status, tags, description, spec_file).
|
|
248
|
-
- Optionally syncs to BrowserStack with description, steps, and tags.
|
|
249
|
-
|
|
250
|
-
---
|
|
251
|
-
|
|
252
|
-
## 📊 Test Run Tracking (NEW!)
|
|
253
|
-
|
|
254
|
-
Run your Playwright tests and **automatically track results on BrowserStack**. Each test run is recorded with pass/fail status, duration, and links back to your test cases.
|
|
255
|
-
|
|
256
|
-
### Quick Start
|
|
257
|
-
|
|
258
|
-
```bash
|
|
259
|
-
# Run all tests with BrowserStack tracking
|
|
260
|
-
npx am-browserstack-sync --run
|
|
261
|
-
|
|
262
|
-
# Run with a custom run name
|
|
263
|
-
npx am-browserstack-sync --run --run-name="Nightly Regression"
|
|
264
|
-
|
|
265
|
-
# Run specific spec files
|
|
266
|
-
npx am-browserstack-sync --run --spec=login.spec.js,checkout.spec.js
|
|
267
|
-
|
|
268
|
-
# Run tests matching a pattern
|
|
269
|
-
npx am-browserstack-sync --run --grep="login"
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
### Setup
|
|
273
|
-
|
|
274
|
-
1. First, **sync your test cases** to BrowserStack (one-time or when tests change):
|
|
275
|
-
```bash
|
|
276
|
-
npx am-browserstack-sync --all
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
2. Ensure your `.env` has the required credentials:
|
|
280
|
-
```env
|
|
281
|
-
BROWSERSTACK_USERNAME=your_username
|
|
282
|
-
BROWSERSTACK_ACCESS_KEY=your_access_key
|
|
283
|
-
BROWSERSTACK_PROJECT_ID=PR-XXXX
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
3. Run tests with tracking:
|
|
287
|
-
```bash
|
|
288
|
-
npx am-browserstack-sync --run
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
### What happens during a test run
|
|
292
|
-
|
|
293
|
-
1. **Creates a Test Run** in BrowserStack with your specified name
|
|
294
|
-
2. **Maps tests** to existing test cases by title
|
|
295
|
-
3. **Updates results in real-time** as each test passes/fails/skips
|
|
296
|
-
4. **Completes the run** with a summary and link to view results
|
|
297
|
-
|
|
298
|
-
### Example Output
|
|
299
|
-
|
|
300
|
-
```
|
|
301
|
-
🚀 Running Playwright tests with BrowserStack tracking...
|
|
302
|
-
Run Name: Nightly Regression
|
|
303
|
-
|
|
304
|
-
🔗 BrowserStack Test Management - Initializing...
|
|
305
|
-
Fetching test cases from BrowserStack...
|
|
306
|
-
Found 15 test case(s) in project PR-1234
|
|
307
|
-
Creating test run: "Nightly Regression"...
|
|
308
|
-
✓ Test run created: TR-42 (ID: 12345)
|
|
309
|
-
Adding 15 test case(s) to the run...
|
|
310
|
-
✓ Test cases added to run
|
|
311
|
-
🚀 Starting test execution with BrowserStack tracking
|
|
312
|
-
|
|
313
|
-
✓ [BS] should display login form → passed
|
|
314
|
-
✓ [BS] should log in successfully → passed
|
|
315
|
-
✗ [BS] should show error for invalid credentials → failed
|
|
316
|
-
|
|
317
|
-
🔗 BrowserStack Test Management - Completing run...
|
|
318
|
-
|
|
319
|
-
✓ Test run completed: TR-42
|
|
320
|
-
📊 Results: 2 passed, 1 failed, 0 skipped (3 total)
|
|
321
|
-
🔗 View in BrowserStack: https://test-management.browserstack.com/projects/PR-1234/runs/12345
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
### Using as a Playwright Reporter
|
|
325
|
-
|
|
326
|
-
You can also use the BrowserStack reporter directly in your `playwright.config.js`:
|
|
327
|
-
|
|
328
|
-
```javascript
|
|
329
|
-
// playwright.config.js
|
|
330
|
-
export default {
|
|
331
|
-
reporter: [
|
|
332
|
-
['list'],
|
|
333
|
-
['@ash-mallick/browserstack-sync/reporter', {
|
|
334
|
-
projectId: 'PR-1234',
|
|
335
|
-
runName: 'CI Pipeline Run',
|
|
336
|
-
}],
|
|
337
|
-
],
|
|
338
|
-
};
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
### CI/CD Integration - GitLab
|
|
342
|
-
|
|
343
|
-
**Sync test results from GitLab CI pipelines to BrowserStack!**
|
|
344
|
-
|
|
345
|
-
#### Quick Setup
|
|
346
|
-
|
|
347
|
-
1. Add CI/CD variables in GitLab (Settings > CI/CD > Variables):
|
|
348
|
-
- `BROWSERSTACK_USERNAME`
|
|
349
|
-
- `BROWSERSTACK_ACCESS_KEY`
|
|
350
|
-
- `BROWSERSTACK_PROJECT_ID`
|
|
351
|
-
|
|
352
|
-
2. Run tests with JSON reporter and sync results:
|
|
353
|
-
|
|
354
|
-
```yaml
|
|
355
|
-
# .gitlab-ci.yml
|
|
356
|
-
test_and_sync:
|
|
357
|
-
image: mcr.microsoft.com/playwright:v1.40.0-jammy
|
|
358
|
-
script:
|
|
359
|
-
- npm ci
|
|
360
|
-
- npm install @ash-mallick/browserstack-sync
|
|
361
|
-
# Run tests with JSON reporter
|
|
362
|
-
- npx playwright test --reporter=json --output-file=test-results.json || true
|
|
363
|
-
# Sync results to BrowserStack
|
|
364
|
-
- npx am-browserstack-sync-runs --run-name="CI Pipeline #$CI_PIPELINE_ID"
|
|
365
|
-
artifacts:
|
|
366
|
-
paths:
|
|
367
|
-
- test-results.json
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
#### Scheduled Runs (Nightly/Weekly)
|
|
371
|
-
|
|
372
|
-
```yaml
|
|
373
|
-
nightly_tests:
|
|
374
|
-
rules:
|
|
375
|
-
- if: $CI_PIPELINE_SOURCE == "schedule"
|
|
376
|
-
variables:
|
|
377
|
-
BROWSERSTACK_RUN_NAME: "Nightly Regression - $CI_COMMIT_SHORT_SHA"
|
|
378
|
-
script:
|
|
379
|
-
- npx playwright test --reporter=json --output-file=test-results.json || true
|
|
380
|
-
- npx am-browserstack-sync-runs
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
#### CLI Options
|
|
384
|
-
|
|
385
|
-
```bash
|
|
386
|
-
# Auto-detect report and sync
|
|
387
|
-
npx am-browserstack-sync-runs
|
|
388
|
-
|
|
389
|
-
# Specify report file
|
|
390
|
-
npx am-browserstack-sync-runs --report=custom-results.json
|
|
391
|
-
|
|
392
|
-
# Custom run name
|
|
393
|
-
npx am-browserstack-sync-runs --run-name="Nightly Build"
|
|
394
|
-
|
|
395
|
-
# JUnit XML format
|
|
396
|
-
npx am-browserstack-sync-runs --report=junit.xml --format=junit
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
### GitHub Actions Example
|
|
400
|
-
|
|
401
|
-
```yaml
|
|
402
|
-
- name: Run tests and sync to BrowserStack
|
|
403
|
-
env:
|
|
404
|
-
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
|
|
405
|
-
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
|
|
406
|
-
BROWSERSTACK_PROJECT_ID: PR-1234
|
|
407
|
-
run: |
|
|
408
|
-
npx playwright test --reporter=json --output-file=test-results.json || true
|
|
409
|
-
npx am-browserstack-sync-runs --run-name="Build #${{ github.run_number }}"
|
|
410
|
-
```
|
|
175
|
+
Or via environment variables:
|
|
176
|
+
- `PLAYWRIGHT_BROWSERSTACK_E2E_DIR`
|
|
177
|
+
- `PLAYWRIGHT_BROWSERSTACK_CSV_DIR`
|
|
411
178
|
|
|
412
179
|
---
|
|
413
180
|
|
|
414
|
-
##
|
|
181
|
+
## What Gets Created
|
|
415
182
|
|
|
416
|
-
|
|
417
|
-
import { runSync } from '@ash-mallick/browserstack-sync';
|
|
183
|
+
When you run `npx am-browserstack-sync --all`:
|
|
418
184
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
```
|
|
185
|
+
1. **CSV files** - One per spec file with test case details
|
|
186
|
+
2. **BrowserStack folders** - One folder per spec file
|
|
187
|
+
3. **Test cases** - Each test becomes a test case with:
|
|
188
|
+
- Title
|
|
189
|
+
- AI-generated steps (or regex-extracted)
|
|
190
|
+
- Expected results
|
|
191
|
+
- Tags
|
|
192
|
+
- Automation status
|
|
428
193
|
|
|
429
|
-
|
|
194
|
+
When you run `npx am-browserstack-sync-runs`:
|
|
430
195
|
|
|
431
|
-
**
|
|
196
|
+
1. **Test Run** - Created in BrowserStack
|
|
197
|
+
2. **Results** - Pass/fail status for each test
|
|
198
|
+
3. **Link** - URL to view results in BrowserStack
|
package/lib/browserstack.js
CHANGED
|
@@ -200,3 +200,109 @@ export async function syncToBrowserStack(specsMap, projectId, auth) {
|
|
|
200
200
|
console.log(` Updated: ${totalUpdated} test case(s)`);
|
|
201
201
|
console.log(` Skipped: ${totalSkipped} test case(s) (no changes)`);
|
|
202
202
|
}
|
|
203
|
+
|
|
204
|
+
// ============================================================================
|
|
205
|
+
// TEST RUN API - For syncing test execution results
|
|
206
|
+
// ============================================================================
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Create a new Test Run in BrowserStack.
|
|
210
|
+
*/
|
|
211
|
+
export async function createTestRun(projectId, runName, description, auth) {
|
|
212
|
+
const url = `${BS_BASE}/projects/${encodeURIComponent(projectId)}/test-runs`;
|
|
213
|
+
const body = {
|
|
214
|
+
test_run: {
|
|
215
|
+
name: runName,
|
|
216
|
+
description: description || `Automated test run: ${runName}`,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
const res = await bsRequest('POST', url, auth, body);
|
|
220
|
+
return {
|
|
221
|
+
runId: res.test_run?.id || res.id,
|
|
222
|
+
identifier: res.test_run?.identifier || res.identifier,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Add test cases to a Test Run.
|
|
228
|
+
*/
|
|
229
|
+
export async function addTestCasesToRun(projectId, runId, testCaseIds, auth) {
|
|
230
|
+
const url = `${BS_BASE}/projects/${encodeURIComponent(projectId)}/test-runs/${runId}/test-cases`;
|
|
231
|
+
const body = {
|
|
232
|
+
test_case_identifiers: testCaseIds,
|
|
233
|
+
};
|
|
234
|
+
return bsRequest('POST', url, auth, body);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Update test result in a Test Run.
|
|
239
|
+
*/
|
|
240
|
+
export async function updateTestResult(projectId, runId, testCaseId, status, options = {}, auth) {
|
|
241
|
+
const url = `${BS_BASE}/projects/${encodeURIComponent(projectId)}/test-runs/${runId}/test-results`;
|
|
242
|
+
|
|
243
|
+
const statusMap = {
|
|
244
|
+
passed: 'passed',
|
|
245
|
+
failed: 'failed',
|
|
246
|
+
skipped: 'skipped',
|
|
247
|
+
timedOut: 'failed',
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const body = {
|
|
251
|
+
test_result: {
|
|
252
|
+
test_case_identifier: testCaseId,
|
|
253
|
+
status: statusMap[status] || status,
|
|
254
|
+
comment: options.comment || '',
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
if (options.duration) {
|
|
259
|
+
body.test_result.duration = Math.round(options.duration / 1000);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return bsRequest('POST', url, auth, body);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Complete a Test Run.
|
|
267
|
+
*/
|
|
268
|
+
export async function completeTestRun(projectId, runId, auth) {
|
|
269
|
+
const url = `${BS_BASE}/projects/${encodeURIComponent(projectId)}/test-runs/${runId}`;
|
|
270
|
+
const body = {
|
|
271
|
+
test_run: {
|
|
272
|
+
state: 'done',
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
return bsRequest('PATCH', url, auth, body);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Get all test cases in a project.
|
|
280
|
+
*/
|
|
281
|
+
export async function getAllTestCases(projectId, auth) {
|
|
282
|
+
const all = [];
|
|
283
|
+
let page = 1;
|
|
284
|
+
let hasMore = true;
|
|
285
|
+
|
|
286
|
+
while (hasMore) {
|
|
287
|
+
const url = `${BS_BASE}/projects/${encodeURIComponent(projectId)}/test-cases?p=${page}`;
|
|
288
|
+
const res = await bsRequest('GET', url, auth);
|
|
289
|
+
const list = res.test_cases || [];
|
|
290
|
+
all.push(...list);
|
|
291
|
+
const info = res.info || {};
|
|
292
|
+
hasMore = info.next != null;
|
|
293
|
+
page += 1;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return all;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Find test case by title.
|
|
301
|
+
*/
|
|
302
|
+
export function findTestCaseByTitle(testCases, title) {
|
|
303
|
+
const normalizedTitle = (title || '').trim().toLowerCase();
|
|
304
|
+
return testCases.find((tc) => {
|
|
305
|
+
const tcTitle = (tc.name || tc.title || '').trim().toLowerCase();
|
|
306
|
+
return tcTitle === normalizedTitle;
|
|
307
|
+
});
|
|
308
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ash-mallick/browserstack-sync",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Sync Playwright & Cypress e2e specs to CSV and BrowserStack Test Management with FREE AI-powered test step extraction using Ollama (local).",
|
|
5
5
|
"author": "Ashutosh Mallick",
|
|
6
6
|
"type": "module",
|