Repository navigation
Expand file tree
/
Copy pathrun-on-browserstack.html
More file actions
482 lines (446 loc) · 24.1 KB
/
Copy pathrun-on-browserstack.html
File metadata and controls
482 lines (446 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/>
<title>Run on BrowserStack — BrowserStack Automate</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet"/>
<script src="https://cdn.tailwindcss.com"></script>
<script>tailwind.config={theme:{extend:{fontFamily:{sans:['Inter','sans-serif']},colors:{brand:{50:'#f5f3ff',600:'#7c3aed',700:'#6d28d9'}}}}}</script>
<link rel="stylesheet" href="style.css"/>
</head>
<body class="bg-gray-50 font-sans antialiased">
<nav class="bg-white border-b border-gray-200 sticky top-0 z-50">
<div class="max-w-3xl mx-auto px-6 h-16 flex items-center gap-3">
<a href="index.html" class="text-gray-500 hover:text-gray-700 text-sm flex items-center gap-1">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/></svg>All demos
</a>
<span class="text-gray-300">|</span>
<span class="font-semibold text-gray-900 text-sm">Run on BrowserStack</span>
</div>
</nav>
<div class="max-w-3xl mx-auto px-6 py-10 space-y-6">
<div class="flex items-center gap-4">
<div class="w-12 h-12 bg-brand-600 rounded-xl flex items-center justify-center shrink-0">
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
</div>
<div>
<h1 class="text-2xl font-bold text-gray-900">Run on BrowserStack</h1>
<p class="text-gray-500 text-sm">Trigger Automate demo pipelines with your BrowserStack credentials</p>
</div>
</div>
<div class="bg-white rounded-2xl border border-gray-200 p-6 space-y-4">
<h2 class="font-semibold text-gray-900">Credentials</h2>
<div>
<label for="username" class="block text-sm font-medium text-gray-700 mb-1">Username</label>
<input id="username" type="text" autocomplete="username" placeholder="BrowserStack username"
class="w-full border border-gray-300 rounded-xl px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-600 focus:border-transparent"/>
</div>
<div>
<label for="accessKey" class="block text-sm font-medium text-gray-700 mb-1">Access Key</label>
<input id="accessKey" type="password" autocomplete="current-password" placeholder="BrowserStack access key"
class="w-full border border-gray-300 rounded-xl px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-600 focus:border-transparent"/>
</div>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer">
<input id="localTesting" type="checkbox" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Local testing (serve on localhost and use BrowserStack Local)
</label>
</div>
<div class="bg-white rounded-2xl border border-gray-200 p-6 space-y-4">
<h2 class="font-semibold text-gray-900">Product</h2>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3" id="product-list">
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="radio" name="product" value="automate" checked class="border-gray-300 text-brand-600 focus:ring-brand-600"/>
Automate (web browsers)
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="radio" name="product" value="app-automate" class="border-gray-300 text-brand-600 focus:ring-brand-600"/>
App Automate (mobile apps)
</label>
</div>
<div id="platform-section" class="hidden space-y-2">
<h3 class="text-sm font-medium text-gray-700">Mobile platform</h3>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3" id="platform-list">
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="radio" name="platform" value="android" checked class="border-gray-300 text-brand-600 focus:ring-brand-600"/>
Android
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="radio" name="platform" value="ios" class="border-gray-300 text-brand-600 focus:ring-brand-600"/>
iOS
</label>
</div>
</div>
</div>
<div id="app-features-card" class="hidden bg-white rounded-2xl border border-gray-200 p-6 space-y-4">
<h2 class="font-semibold text-gray-900">App Features (<span id="app-platform-label">Android</span>)</h2>
<p class="text-sm text-gray-500">Select one or more features to run. Leave all unselected to run the full flow.</p>
<label class="flex items-center gap-2 text-sm font-semibold text-gray-900 cursor-pointer">
<input type="checkbox" id="app-select-all" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Select all
</label>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3" id="app-workflow-list">
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="app-feature" id="app-e2e" value="e2e" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Run E2E flow
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="app-feature" value="image-injection" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Image Injection
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="app-feature" value="biometric" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Biometric
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="app-feature" value="video-injection" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Video Injection
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="app-feature" value="file-upload-download" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
File Upload & Download
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="app-feature" value="audio-injection" data-android-only class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Audio Injection
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="app-feature" value="network" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Network
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="app-feature" value="gps" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
GPS
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="app-feature" value="otp" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
OTP
</label>
</div>
</div>
<div id="features-card" class="bg-white rounded-2xl border border-gray-200 p-6 space-y-4">
<h2 class="font-semibold text-gray-900">Features</h2>
<p class="text-sm text-gray-500">Select one or more features to dispatch.</p>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3" id="workflow-list">
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="workflow" value="apple-pay" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Apple Pay
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="workflow" value="camera" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Camera
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="workflow" value="audio" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Audio
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="workflow" value="network" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Network
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="workflow" value="self-healing" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Self-Healing
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="workflow" value="file-upload" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
File Upload
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="workflow" value="ip-geolocation" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
IP Geolocation
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="workflow" value="timezone" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Timezone
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="workflow" value="iframe" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
iframe
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="workflow" value="permissions" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Permissions
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="workflow" value="visual-regression" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Visual Regression
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer border border-gray-200 rounded-xl px-3 py-2.5 hover:border-brand-300">
<input type="checkbox" name="workflow" value="accessibility" class="rounded border-gray-300 text-brand-600 focus:ring-brand-600"/>
Accessibility
</label>
</div>
</div>
<div class="flex flex-col sm:flex-row gap-3">
<button id="trigger-btn" type="button" class="flex-1 bg-brand-600 hover:bg-brand-700 text-white font-semibold py-2.5 rounded-xl disabled:opacity-50 disabled:cursor-not-allowed">
Trigger pipeline(s)
</button>
<a id="view-bs-btn" href="https://automate.browserstack.com/projects/BrowserStack+Demo" target="_blank" rel="noopener"
class="flex-1 inline-flex items-center justify-center gap-2 bg-white border border-gray-300 hover:border-gray-400 text-gray-700 font-semibold py-2.5 rounded-xl">
View on BrowserStack
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"/></svg>
</a>
</div>
<div id="error-box" class="hidden bg-red-50 border border-red-200 rounded-2xl p-5 text-sm text-red-800"></div>
<div id="status-card" class="hidden bg-white rounded-2xl border border-gray-200 overflow-hidden">
<div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between">
<h2 class="font-semibold text-gray-900">Run status</h2>
<span id="poll-badge" class="text-xs bg-gray-100 text-gray-500 px-2.5 py-1 rounded-full">Idle</span>
</div>
<ul id="run-list" class="divide-y divide-gray-100"></ul>
</div>
</div>
<script>
(function () {
// Defaults to the deployed API. To test against a local API (cd api && npm run dev), open this
// page with ?api=http://localhost:8787
const PAGE_PARAMS = new URLSearchParams(window.location.search);
const API_BASE = PAGE_PARAMS.get('api') || 'https://features-demo-api.vercel.app';
// Branch the workflows are dispatched from; open the page with ?ref=<branch> to test before merging.
const WORKFLOW_REF = PAGE_PARAMS.get('ref') || 'main';
const POLL_MS = 4000;
const usernameEl = document.getElementById('username');
const accessKeyEl = document.getElementById('accessKey');
const localTestingEl = document.getElementById('localTesting');
const triggerBtn = document.getElementById('trigger-btn');
const errorBox = document.getElementById('error-box');
const statusCard = document.getElementById('status-card');
const runList = document.getElementById('run-list');
const pollBadge = document.getElementById('poll-badge');
const platformSection = document.getElementById('platform-section');
const featuresCard = document.getElementById('features-card');
const appFeaturesCard = document.getElementById('app-features-card');
const viewBsBtn = document.getElementById('view-bs-btn');
const DASHBOARD_URLS = {
'automate': 'https://automate.browserstack.com/projects/BrowserStack+Demo',
'app-automate': 'https://app-automate.browserstack.com/'
};
let pollTimer = null;
function selectedProduct() {
return document.querySelector('input[name="product"]:checked').value;
}
function selectedPlatform() {
return selectedProduct() === 'app-automate'
? document.querySelector('input[name="platform"]:checked').value
: null;
}
function syncProduct() {
var isApp = selectedProduct() === 'app-automate';
platformSection.classList.toggle('hidden', !isApp);
featuresCard.classList.toggle('hidden', isApp);
appFeaturesCard.classList.toggle('hidden', !isApp);
// Audio injection exists only on Android: hide and untick it on iOS.
var isIos = isApp && selectedPlatform() === 'ios';
document.getElementById('app-platform-label').textContent = isIos ? 'iOS' : 'Android';
document.querySelectorAll('input[data-android-only]').forEach(function (el) {
if (isIos) el.checked = false;
el.closest('label').classList.toggle('hidden', isIos);
});
// The select-all checkbox is wired up further down; skip it on the first call at load.
if (typeof syncSelectAll === 'function' && selectAllEl) syncSelectAll();
viewBsBtn.href = DASHBOARD_URLS[selectedProduct()];
}
document.querySelectorAll('input[name="product"], input[name="platform"]').forEach(function (el) {
el.addEventListener('change', syncProduct);
});
syncProduct();
var selectAllEl = document.getElementById('app-select-all');
var e2eEl = document.getElementById('app-e2e');
// The individual feature boxes: every app-feature box except the E2E one.
function appFeatureBoxes() {
return Array.from(document.querySelectorAll('input[name="app-feature"]')).filter(function (el) {
return el !== e2eEl;
});
}
// E2E runs the whole flow on its own, so while it is ticked every other option is disabled.
function syncE2e() {
var on = e2eEl.checked;
if (on) {
appFeatureBoxes().forEach(function (el) { el.checked = false; });
selectAllEl.checked = false;
selectAllEl.indeterminate = false;
}
appFeatureBoxes().concat([selectAllEl]).forEach(function (el) { el.disabled = on; });
}
e2eEl.addEventListener('change', syncE2e);
function syncSelectAll() {
var boxes = appFeatureBoxes().filter(function (el) { return !el.hasAttribute('data-android-only') || selectedPlatform() !== 'ios'; });
var checked = boxes.filter(function (el) { return el.checked; }).length;
selectAllEl.checked = boxes.length > 0 && checked === boxes.length;
selectAllEl.indeterminate = checked > 0 && checked < boxes.length;
}
selectAllEl.addEventListener('change', function () {
appFeatureBoxes().forEach(function (el) {
if (el.hasAttribute('data-android-only') && selectedPlatform() === 'ios') return;
el.checked = selectAllEl.checked;
});
selectAllEl.indeterminate = false;
});
appFeatureBoxes().forEach(function (el) {
el.addEventListener('change', syncSelectAll);
});
function selectedWorkflows() {
var name = selectedProduct() === 'app-automate' ? 'app-feature' : 'workflow';
return Array.from(document.querySelectorAll('input[name="' + name + '"]:checked')).map(function (el) {
return el.value;
});
}
function showError(message) {
errorBox.textContent = message;
errorBox.classList.remove('hidden');
}
function clearError() {
errorBox.textContent = '';
errorBox.classList.add('hidden');
}
function stopPolling() {
if (pollTimer) {
clearInterval(pollTimer);
pollTimer = null;
}
}
function statusLabel(run) {
if (run.error) return run.error;
if (run.status === 'completed') return run.conclusion || 'completed';
return run.status || 'queued';
}
function badgeClass(run) {
if (run.error) return 'bg-red-50 text-red-700';
if (run.status === 'completed' && run.conclusion === 'success') return 'bg-green-50 text-green-700';
if (run.status === 'completed') return 'bg-red-50 text-red-700';
if (run.status === 'in_progress') return 'bg-amber-50 text-amber-700';
return 'bg-gray-100 text-gray-600';
}
function renderRuns(runs) {
statusCard.classList.remove('hidden');
runList.innerHTML = '';
runs.forEach(function (run) {
var li = document.createElement('li');
li.className = 'px-6 py-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2';
var left = document.createElement('div');
left.innerHTML = '<p class="font-medium text-gray-900 text-sm">' + escapeHtml(run.workflow || 'unknown') + '</p>';
if (run.htmlUrl) {
left.innerHTML += '<a href="' + escapeAttr(run.htmlUrl) + '" target="_blank" rel="noopener" class="text-xs text-brand-600 hover:text-brand-700">View on GitHub Actions →</a>';
}
var badge = document.createElement('span');
badge.className = 'text-xs font-medium px-2.5 py-1 rounded-full self-start ' + badgeClass(run);
badge.textContent = statusLabel(run);
li.appendChild(left);
li.appendChild(badge);
runList.appendChild(li);
});
}
function escapeHtml(str) {
return String(str)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"');
}
function escapeAttr(str) {
return escapeHtml(str).replace(/'/g, ''');
}
function allDone(runs) {
return runs.every(function (run) {
return run.error || run.status === 'completed';
});
}
async function pollStatus(tokens) {
pollBadge.textContent = 'Polling…';
pollBadge.className = 'text-xs bg-amber-50 text-amber-700 px-2.5 py-1 rounded-full';
async function tick() {
try {
var res = await fetch(API_BASE + '/api/status?tokens=' + encodeURIComponent(tokens.join(',')));
var data = await res.json();
if (!res.ok) {
showError(data.error || 'Status poll failed');
stopPolling();
pollBadge.textContent = 'Error';
pollBadge.className = 'text-xs bg-red-50 text-red-700 px-2.5 py-1 rounded-full';
return;
}
clearError();
renderRuns(data.runs || []);
if (allDone(data.runs || [])) {
stopPolling();
pollBadge.textContent = 'Done';
pollBadge.className = 'text-xs bg-green-50 text-green-700 px-2.5 py-1 rounded-full';
}
} catch (err) {
showError(err.message || String(err));
stopPolling();
pollBadge.textContent = 'Error';
pollBadge.className = 'text-xs bg-red-50 text-red-700 px-2.5 py-1 rounded-full';
}
}
await tick();
stopPolling();
pollTimer = setInterval(tick, POLL_MS);
}
triggerBtn.addEventListener('click', async function () {
clearError();
stopPolling();
var username = usernameEl.value.trim();
var accessKey = accessKeyEl.value.trim();
var workflows = selectedWorkflows();
var product = selectedProduct();
var platform = selectedPlatform();
if (!username || !accessKey) {
showError('Username and access key are required.');
return;
}
// App Automate with nothing selected runs the full flow; Automate needs a selection.
if (workflows.length === 0 && product !== 'app-automate') {
showError('Select at least one pipeline.');
return;
}
triggerBtn.disabled = true;
triggerBtn.textContent = 'Triggering…';
pollBadge.textContent = 'Starting…';
pollBadge.className = 'text-xs bg-gray-100 text-gray-500 px-2.5 py-1 rounded-full';
statusCard.classList.remove('hidden');
runList.innerHTML = '<li class="px-6 py-4 text-sm text-gray-500">Dispatching workflows…</li>';
try {
var res = await fetch(API_BASE + '/api/trigger', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
workflows: product === 'app-automate' ? [] : workflows,
features: product === 'app-automate' ? workflows : [],
username: username,
accessKey: accessKey,
localTesting: localTestingEl.checked,
product: product,
platform: platform,
ref: WORKFLOW_REF
})
});
var data = await res.json();
if (!res.ok) {
showError(data.error || 'Trigger failed');
runList.innerHTML = '';
statusCard.classList.add('hidden');
return;
}
var runs = data.runs || [];
renderRuns(runs);
var tokens = runs.filter(function (r) { return r.token; }).map(function (r) { return r.token; });
if (tokens.length > 0) {
await pollStatus(tokens);
} else {
pollBadge.textContent = 'Failed';
pollBadge.className = 'text-xs bg-red-50 text-red-700 px-2.5 py-1 rounded-full';
}
} catch (err) {
showError(err.message || String(err));
runList.innerHTML = '';
statusCard.classList.add('hidden');
} finally {
triggerBtn.disabled = false;
triggerBtn.textContent = 'Trigger pipeline(s)';
}
});
})();
</script>
</body>
</html>