gz-laya-pilot 0.1.1 → 0.1.2
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/NOTICE.md +14 -0
- package/README.md +25 -3
- package/dist/agent/bridge.js +1 -1
- package/dist/agent/bridge.js.map +1 -1
- package/dist/agent/report.d.ts +3 -0
- package/dist/agent/report.js +11 -2
- package/dist/agent/report.js.map +1 -1
- package/dist/agent/schema.d.ts +10 -0
- package/dist/agent/schema.js.map +1 -1
- package/package.json +1 -1
- package/src/agent/bridge.ts +1 -1
- package/src/agent/report.ts +15 -2
- package/src/agent/schema.ts +5 -0
- package/vendor/.gitattributes +1 -0
- package/vendor/UPSTREAM.json +94 -5
- package/vendor/laya-pilot/lib/browser-provider.mjs +18 -6
- package/vendor/laya-pilot/lib/discovery.mjs +182 -31
- package/vendor/laya-pilot/lib/dom.mjs +65 -2
- package/vendor/laya-pilot/lib/form.mjs +3 -3
- package/vendor/laya-pilot/lib/page-capabilities.mjs +356 -0
- package/vendor/laya-pilot/lib/page-exploration.mjs +372 -0
- package/vendor/laya-pilot/lib/page-session.mjs +69 -0
- package/vendor/laya-pilot/lib/related-records.mjs +328 -0
- package/vendor/laya-pilot/lib/run-state.mjs +15 -1
- package/vendor/laya-pilot/lib/test-data.mjs +15 -2
- package/vendor/laya-pilot/lib/workflow-policy.mjs +8 -1
- package/vendor/laya-pilot/lib/workflow.mjs +536 -121
- package/vendor/laya-pilot/lib/workflow_excel.py +33 -2
- package/vendor/laya-pilot/tests/retries.test.mjs +14 -1
- package/vendor/laya-pilot/tests/selected-pr1.test.mjs +21 -3
- package/vendor/patches/0001-native-field-recipes.patch +2966 -14
|
@@ -5,12 +5,22 @@ import path from 'node:path';
|
|
|
5
5
|
import { randomBytes } from 'node:crypto';
|
|
6
6
|
import { spawn } from 'node:child_process';
|
|
7
7
|
import { Laya, beginModelWarmup, waitModelWarmup } from './model.mjs';
|
|
8
|
-
import { openBrowser } from './browser-provider.mjs';
|
|
8
|
+
import { openBrowser, launchBrowser } from './browser-provider.mjs';
|
|
9
9
|
import { matchReplayTarget } from './replay-model.mjs';
|
|
10
|
+
import { executeRelatedRecords, validateRelatedStep } from './related-records.mjs';
|
|
10
11
|
import { observe, discoverRowLabels, settle } from './dom.mjs';
|
|
11
12
|
import { ensureAuthentication, saveAuthState } from './auth-state.mjs';
|
|
12
13
|
import { RunJournal, watchInterruption, resultExitCode, writePrivateJson } from './run-state.mjs';
|
|
13
14
|
import { workflowPolicy, enforceReplayPolicy } from './workflow-policy.mjs';
|
|
15
|
+
import {
|
|
16
|
+
openOwnedRecord,
|
|
17
|
+
assertRecordDetail,
|
|
18
|
+
assertSearchResult,
|
|
19
|
+
assertTabPanel,
|
|
20
|
+
inspectDisclosure,
|
|
21
|
+
observeCoverage,
|
|
22
|
+
exploreDetailTabs,
|
|
23
|
+
} from './page-exploration.mjs';
|
|
14
24
|
import {
|
|
15
25
|
accountField,
|
|
16
26
|
expiryField,
|
|
@@ -25,6 +35,26 @@ import {
|
|
|
25
35
|
observeFormEvidence,
|
|
26
36
|
} from './discovery.mjs';
|
|
27
37
|
import { waitForReady } from './readiness.mjs';
|
|
38
|
+
import {
|
|
39
|
+
pageIdentity,
|
|
40
|
+
assertPageIdentity,
|
|
41
|
+
captureVerificationAuth,
|
|
42
|
+
activity,
|
|
43
|
+
waitForVisibleStep,
|
|
44
|
+
} from './page-session.mjs';
|
|
45
|
+
import {
|
|
46
|
+
activateEditor,
|
|
47
|
+
formRoot,
|
|
48
|
+
COLLECTION,
|
|
49
|
+
recordRows,
|
|
50
|
+
sameRegion,
|
|
51
|
+
expandCollection,
|
|
52
|
+
expandTree,
|
|
53
|
+
validateTreeTarget,
|
|
54
|
+
revealTreeActions,
|
|
55
|
+
captureTreePath,
|
|
56
|
+
verifyInput,
|
|
57
|
+
} from './page-capabilities.mjs';
|
|
28
58
|
import {
|
|
29
59
|
BrowserDiagnostics,
|
|
30
60
|
diagnoseFailure,
|
|
@@ -70,9 +100,41 @@ const safeKey = (s) =>
|
|
|
70
100
|
.replace(/-+/g, '-')
|
|
71
101
|
.slice(0, 85);
|
|
72
102
|
const ownName = () => `LayaAuto_${Date.now().toString(36)}_${randomBytes(3).toString('hex')}`;
|
|
73
|
-
const controlInfo = (c) => ({
|
|
103
|
+
const controlInfo = (c) => ({
|
|
104
|
+
name: c.name,
|
|
105
|
+
role: c.role,
|
|
106
|
+
scope: c.scope || 'page',
|
|
107
|
+
...(c.region ? { region: c.region } : {}),
|
|
108
|
+
...(c.treePath ? { treePath: c.treePath } : {}),
|
|
109
|
+
});
|
|
74
110
|
const message = (e) => safeText(e?.message || String(e), 1200);
|
|
75
111
|
|
|
112
|
+
function validatePersistenceQuery(query) {
|
|
113
|
+
const [fill, search] = Array.isArray(query) ? query : [];
|
|
114
|
+
if (
|
|
115
|
+
!Array.isArray(query) ||
|
|
116
|
+
query.length < 1 ||
|
|
117
|
+
query.length > 2 ||
|
|
118
|
+
fill?.kind !== 'fill' ||
|
|
119
|
+
!['textbox', 'spinbutton'].includes(fill.target?.role) ||
|
|
120
|
+
typeof fill.target.name !== 'string' ||
|
|
121
|
+
!fill.target.name ||
|
|
122
|
+
fill.target.name.length > 150 ||
|
|
123
|
+
fill.target.scope !== 'page' ||
|
|
124
|
+
typeof fill.value !== 'string' ||
|
|
125
|
+
fill.value.length > 200 ||
|
|
126
|
+
(search &&
|
|
127
|
+
(search.kind !== 'click' ||
|
|
128
|
+
search.purpose !== 'search' ||
|
|
129
|
+
!['button', 'link'].includes(search.target?.role) ||
|
|
130
|
+
search.target.scope !== 'page' ||
|
|
131
|
+
typeof search.target.name !== 'string' ||
|
|
132
|
+
search.target.name.length > 150 ||
|
|
133
|
+
!actions.search.test(search.target.name)))
|
|
134
|
+
)
|
|
135
|
+
throw Error('持久化断言缺少受限的语义查询步骤,请重新生成 Excel');
|
|
136
|
+
}
|
|
137
|
+
|
|
76
138
|
export function validateWorkflow(file) {
|
|
77
139
|
if (file?.schemaVersion !== 1 || !Array.isArray(file.cases) || !file.cases.length)
|
|
78
140
|
throw Error('用例文件没有可执行的已验证用例');
|
|
@@ -89,6 +151,8 @@ export function validateWorkflow(file) {
|
|
|
89
151
|
'assert-input-invalid',
|
|
90
152
|
'assert-row',
|
|
91
153
|
'assert-absent',
|
|
154
|
+
'assert-persisted-row',
|
|
155
|
+
'assert-persisted-absent',
|
|
92
156
|
'assert-text',
|
|
93
157
|
'assert-control',
|
|
94
158
|
'assert-selected',
|
|
@@ -96,6 +160,13 @@ export function validateWorkflow(file) {
|
|
|
96
160
|
'assert-disabled',
|
|
97
161
|
'reload',
|
|
98
162
|
'assert-discovery',
|
|
163
|
+
'expand-tree',
|
|
164
|
+
'open-owned-record',
|
|
165
|
+
'assert-record-detail',
|
|
166
|
+
'assert-tab-panel',
|
|
167
|
+
'assert-query-result',
|
|
168
|
+
'assert-disclosure',
|
|
169
|
+
'assert-related-records',
|
|
99
170
|
]);
|
|
100
171
|
for (const c of file.cases) {
|
|
101
172
|
if (
|
|
@@ -109,6 +180,7 @@ export function validateWorkflow(file) {
|
|
|
109
180
|
'create',
|
|
110
181
|
'search',
|
|
111
182
|
'view',
|
|
183
|
+
'related-records',
|
|
112
184
|
'edit',
|
|
113
185
|
'delete',
|
|
114
186
|
'discover',
|
|
@@ -118,13 +190,63 @@ export function validateWorkflow(file) {
|
|
|
118
190
|
)
|
|
119
191
|
throw Error('用例包含不支持的操作:' + c.id);
|
|
120
192
|
for (const step of c.steps) {
|
|
121
|
-
if (
|
|
193
|
+
if (
|
|
194
|
+
c.operation === 'discover' ||
|
|
195
|
+
(c.operation === 'filters' && step.kind === 'assert-discovery')
|
|
196
|
+
) {
|
|
122
197
|
if (step.kind !== 'assert-discovery') throw Error('补充测试只允许受限的验证步骤');
|
|
123
|
-
validateDiscovery(step);
|
|
198
|
+
validateDiscovery(step, { readOnly: c.operation === 'filters' });
|
|
124
199
|
continue;
|
|
125
200
|
}
|
|
126
201
|
if (step.kind === 'assert-discovery') throw Error('补充测试步骤必须属于 discover');
|
|
127
202
|
if (!allowed.has(step.kind)) throw Error('用例包含不支持的步骤:' + step.kind);
|
|
203
|
+
if (step.kind === 'assert-related-records') {
|
|
204
|
+
if (c.operation !== 'related-records')
|
|
205
|
+
throw Error('关联步骤必须属于 related-records 写操作');
|
|
206
|
+
validateRelatedStep(step);
|
|
207
|
+
validatePersistenceQuery(step.query);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (c.operation === 'related-records') throw Error('关联用例仅允许受限的关联事务');
|
|
211
|
+
if (
|
|
212
|
+
['open-owned-record', 'assert-record-detail'].includes(step.kind) &&
|
|
213
|
+
(c.operation !== 'view' ||
|
|
214
|
+
!['${recordName}', '${updatedName}'].includes(step.value))
|
|
215
|
+
)
|
|
216
|
+
throw Error('详情步骤必须引用本轮创建的记录');
|
|
217
|
+
if (
|
|
218
|
+
step.kind === 'assert-query-result' &&
|
|
219
|
+
(c.operation !== 'search' || step.value !== '${recordName}')
|
|
220
|
+
)
|
|
221
|
+
throw Error('查询断言必须引用本轮记录');
|
|
222
|
+
if (
|
|
223
|
+
step.kind === 'assert-disclosure' &&
|
|
224
|
+
(c.operation !== 'view' ||
|
|
225
|
+
step.target?.role !== 'button' ||
|
|
226
|
+
[step.target?.name, step.target?.tab].some(
|
|
227
|
+
(value) => typeof value !== 'string' || !value || value.length > 150,
|
|
228
|
+
))
|
|
229
|
+
)
|
|
230
|
+
throw Error('展开检查必须指定详情页签内的唯一语义按钮');
|
|
231
|
+
if (
|
|
232
|
+
step.kind === 'assert-tab-panel' &&
|
|
233
|
+
(c.operation !== 'view' ||
|
|
234
|
+
step.target?.role !== 'tab' ||
|
|
235
|
+
typeof step.target.name !== 'string' ||
|
|
236
|
+
!step.target.name ||
|
|
237
|
+
step.target.name.length > 150)
|
|
238
|
+
)
|
|
239
|
+
throw Error('详情页签断言缺少明确入口');
|
|
240
|
+
if (
|
|
241
|
+
['assert-persisted-row', 'assert-persisted-absent'].includes(step.kind) &&
|
|
242
|
+
(typeof step.value !== 'string' || !step.value || step.value.length > 200)
|
|
243
|
+
)
|
|
244
|
+
throw Error('持久化断言缺少明确的记录值');
|
|
245
|
+
if (['assert-persisted-row', 'assert-persisted-absent'].includes(step.kind))
|
|
246
|
+
validatePersistenceQuery(step.query);
|
|
247
|
+
if (step.kind === 'expand-tree') validateTreeTarget(step.target);
|
|
248
|
+
if (step.target?.treePath)
|
|
249
|
+
validateTreeTarget(step.target.treePath, { allowRoot: true });
|
|
128
250
|
if (step.kind === 'assert-disabled' && (!step.target?.name || !step.target?.role))
|
|
129
251
|
throw Error('禁用态断言缺少控件名称和角色');
|
|
130
252
|
if (['click', 'fill'].includes(step.kind) && (!step.target?.name || !step.target?.role))
|
|
@@ -260,7 +382,24 @@ export class Workflow {
|
|
|
260
382
|
'replayStep',
|
|
261
383
|
]) {
|
|
262
384
|
const operation = this[name].bind(this);
|
|
263
|
-
this[name] = (...args) =>
|
|
385
|
+
this[name] = (...args) =>
|
|
386
|
+
this.withAttempts(name, async () => {
|
|
387
|
+
const result = await operation(...args);
|
|
388
|
+
if (
|
|
389
|
+
[
|
|
390
|
+
'click',
|
|
391
|
+
'clickCreate',
|
|
392
|
+
'fill',
|
|
393
|
+
'formFill',
|
|
394
|
+
'formFillRequired',
|
|
395
|
+
'formSelect',
|
|
396
|
+
'formDate',
|
|
397
|
+
'clickTab',
|
|
398
|
+
].includes(name)
|
|
399
|
+
)
|
|
400
|
+
await waitForVisibleStep(this);
|
|
401
|
+
return result;
|
|
402
|
+
});
|
|
264
403
|
}
|
|
265
404
|
}
|
|
266
405
|
checkInterrupted() {
|
|
@@ -283,9 +422,7 @@ export class Workflow {
|
|
|
283
422
|
this.journal?.completeCase(c, this.runtime());
|
|
284
423
|
}
|
|
285
424
|
ownedRows(name) {
|
|
286
|
-
return this.page
|
|
287
|
-
.locator('table tbody tr:visible,[role="rowgroup"] [role="row"]:visible')
|
|
288
|
-
.filter({ has: this.page.getByText(name, { exact: true }) });
|
|
425
|
+
return recordRows(this.page, name);
|
|
289
426
|
}
|
|
290
427
|
async ownedActionRows(name) {
|
|
291
428
|
const row = this.ownedRows(name);
|
|
@@ -330,8 +467,14 @@ export class Workflow {
|
|
|
330
467
|
.waitFor({ state: 'visible', timeout })
|
|
331
468
|
.catch(() => {});
|
|
332
469
|
}
|
|
470
|
+
async editorPresent() {
|
|
471
|
+
return (await formRoot(this.page).count()) > 0;
|
|
472
|
+
}
|
|
473
|
+
async waitForEditor() {
|
|
474
|
+
await activateEditor(this.page, this.config.assertTimeout || 4000);
|
|
475
|
+
}
|
|
333
476
|
async waitModalClosed(timeout = 8000) {
|
|
334
|
-
await this.page
|
|
477
|
+
await formRoot(this.page).waitFor({ state: 'hidden', timeout });
|
|
335
478
|
}
|
|
336
479
|
async safeClick(locator) {
|
|
337
480
|
await locator.click({ timeout: 4000 });
|
|
@@ -341,7 +484,7 @@ export class Workflow {
|
|
|
341
484
|
if (
|
|
342
485
|
step.purpose === 'save' &&
|
|
343
486
|
/^(确定|确认|confirm|ok)$/i.test(step.target.name) &&
|
|
344
|
-
!(await this.
|
|
487
|
+
!(await this.editorPresent())
|
|
345
488
|
)
|
|
346
489
|
throw Error('表单确认提交前必须有当前可见表单');
|
|
347
490
|
// Trial checks actionability without dispatching a click. Once dispatched,
|
|
@@ -368,7 +511,7 @@ export class Workflow {
|
|
|
368
511
|
const errors = await formErrors(this.page);
|
|
369
512
|
return errors.open && errors.labels.length > 0;
|
|
370
513
|
}
|
|
371
|
-
if (await this.
|
|
514
|
+
if (await this.editorPresent()) return false;
|
|
372
515
|
const deleting = ['delete', 'confirm'].includes(step.purpose) && op === 'delete';
|
|
373
516
|
const name =
|
|
374
517
|
op === 'create'
|
|
@@ -432,6 +575,10 @@ export class Workflow {
|
|
|
432
575
|
this.case.attempts ??= [];
|
|
433
576
|
this.case.attempts.push(entry);
|
|
434
577
|
}
|
|
578
|
+
// A failed restoration/compound transaction has already
|
|
579
|
+
// established an unsafe next state. Do not replace its
|
|
580
|
+
// business failure with generic click retry verification.
|
|
581
|
+
if (this.restorationFailure) throw error;
|
|
435
582
|
if (attempt === 3)
|
|
436
583
|
throw Error(`${label} 尝试3次未成功:${entry.reason}`, { cause: error });
|
|
437
584
|
await settle(this.page, 250).catch(() => {});
|
|
@@ -442,26 +589,36 @@ export class Workflow {
|
|
|
442
589
|
}
|
|
443
590
|
}
|
|
444
591
|
async clickCreate() {
|
|
445
|
-
// withAttempts owns the three-attempt budget; retain
|
|
592
|
+
// withAttempts owns the three-attempt budget; retain semantic targets, not live refs.
|
|
446
593
|
const tried = this.attemptState ? (this.attemptState.createTried ??= new Set()) : new Set();
|
|
447
|
-
if (await this.
|
|
594
|
+
if (await this.editorPresent()) {
|
|
448
595
|
if (this.attemptState?.createClicked) return;
|
|
449
596
|
if (!(await this.dismissModal())) throw Error('旧弹窗未关闭,不能选择新的创建入口');
|
|
450
597
|
}
|
|
451
598
|
let snap = await this.snapshot();
|
|
452
599
|
let candidates = snap.controls.filter((c) => isAction(c) && actions.create.test(c.name));
|
|
600
|
+
if (!candidates.length) {
|
|
601
|
+
await expandCollection(this);
|
|
602
|
+
await revealTreeActions(this.page);
|
|
603
|
+
snap = await this.snapshot();
|
|
604
|
+
candidates = snap.controls.filter((c) => isAction(c) && actions.create.test(c.name));
|
|
605
|
+
}
|
|
453
606
|
if (!candidates.length) {
|
|
454
607
|
await this.click('area');
|
|
455
608
|
snap = await this.snapshot();
|
|
456
609
|
candidates = snap.controls.filter((c) => isAction(c) && actions.create.test(c.name));
|
|
457
610
|
}
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
611
|
+
const entryKey = (c) => JSON.stringify([c.role, c.name, c.region, c.context]);
|
|
612
|
+
const untried = candidates.filter((c) => !tried.has(entryKey(c)));
|
|
613
|
+
const { control: c, locator } = await this.chooseFromSnapshot(
|
|
614
|
+
snap,
|
|
615
|
+
untried.length ? untried : candidates,
|
|
616
|
+
'创建独立记录',
|
|
617
|
+
);
|
|
618
|
+
tried.add(entryKey(c));
|
|
619
|
+
c.treePath = await captureTreePath(this.page, locator);
|
|
620
|
+
const bound = c.treePath ? await revealTreeActions(this.page, c) : locator;
|
|
621
|
+
await this.safeClick(bound, c.name);
|
|
465
622
|
if (this.attemptState) this.attemptState.createClicked = true;
|
|
466
623
|
this.record({
|
|
467
624
|
kind: 'click',
|
|
@@ -469,20 +626,17 @@ export class Workflow {
|
|
|
469
626
|
purpose: 'create',
|
|
470
627
|
});
|
|
471
628
|
await settle(this.page, 150);
|
|
472
|
-
await this.
|
|
473
|
-
if (!(await this.modalPresent())) throw Error('创建入口「' + c.name + '」未打开表单弹窗');
|
|
629
|
+
await this.waitForEditor();
|
|
474
630
|
await observeFormEvidence(this, c);
|
|
475
631
|
}
|
|
476
632
|
async dismissModal() {
|
|
477
633
|
await this.page.keyboard.press('Escape').catch(() => {});
|
|
478
|
-
if (!(await this.
|
|
479
|
-
const close = this.page
|
|
480
|
-
.locator(MODAL_SEL)
|
|
481
|
-
.last()
|
|
634
|
+
if (!(await this.editorPresent())) return true;
|
|
635
|
+
const close = formRoot(this.page)
|
|
482
636
|
.locator('button:visible')
|
|
483
637
|
.filter({ hasText: /^(取消|关闭|close|cancel)$/i });
|
|
484
638
|
if ((await close.count()) === 1) await close.click({ timeout: 1500 });
|
|
485
|
-
return !(await this.
|
|
639
|
+
return !(await this.editorPresent());
|
|
486
640
|
}
|
|
487
641
|
async chooseFromSnapshot(snap, candidates, purpose) {
|
|
488
642
|
if (!candidates.length) throw Error('页面上没有可操作的' + purpose + '控件');
|
|
@@ -536,13 +690,17 @@ export class Workflow {
|
|
|
536
690
|
throw Error('决策后页面控件已变化:' + purpose);
|
|
537
691
|
return { control, locator };
|
|
538
692
|
}
|
|
539
|
-
async action(op, { rowName, optional = false } = {}) {
|
|
540
|
-
if (op === 'save' && !(await this.
|
|
693
|
+
async action(op, { rowName, optional = false, region, frame } = {}) {
|
|
694
|
+
if (op === 'save' && !(await this.editorPresent()))
|
|
541
695
|
throw Error('保存表单前必须有当前可见表单');
|
|
542
696
|
let snap = await this.snapshot();
|
|
543
697
|
let owned;
|
|
544
698
|
if (rowName) {
|
|
545
699
|
owned = await this.ownedActionRows(rowName);
|
|
700
|
+
if ((await this.ownedRows(rowName).getAttribute('role')) === 'treeitem') {
|
|
701
|
+
await owned.locator('button,[role="button"]').first().hover();
|
|
702
|
+
snap = await this.snapshot();
|
|
703
|
+
}
|
|
546
704
|
const key = await this.ownedRows(rowName).getAttribute('data-row-key');
|
|
547
705
|
if (key) snap = await discoverRowLabels(this.page, key);
|
|
548
706
|
}
|
|
@@ -552,13 +710,20 @@ export class Workflow {
|
|
|
552
710
|
(op === 'area' ? c.role === 'tab' && !c.disabled : isAction(c)) &&
|
|
553
711
|
actions[op].test(c.name) &&
|
|
554
712
|
(op !== 'confirm' || c.role === 'button') &&
|
|
713
|
+
(region === undefined || sameRegion(c, { region, frame })) &&
|
|
555
714
|
(!rowName || c.context.includes(rowName)),
|
|
556
715
|
);
|
|
557
716
|
const inOwnedRow = async (items) => {
|
|
558
717
|
if (!owned) return items;
|
|
559
718
|
const scoped = [];
|
|
560
|
-
for (const c of items)
|
|
561
|
-
|
|
719
|
+
for (const c of items) {
|
|
720
|
+
// A delayed list render can replace nodes after observation. An
|
|
721
|
+
// expired live ref is not proof that an optional action is absent.
|
|
722
|
+
const selector = `[${LIVE_REF}="${c.ref}"]`;
|
|
723
|
+
if (!(await snap.frames[c.frame].locator(selector).count()))
|
|
724
|
+
throw Error('页面观察后控件已更新,需要重新定位:' + c.name);
|
|
725
|
+
if (await owned.locator(selector).count()) scoped.push(c);
|
|
726
|
+
}
|
|
562
727
|
return scoped;
|
|
563
728
|
};
|
|
564
729
|
let candidates = await inOwnedRow(matching());
|
|
@@ -652,14 +817,27 @@ export class Workflow {
|
|
|
652
817
|
await this.dispatchClick(found.locator, found.step);
|
|
653
818
|
this.record(found.step);
|
|
654
819
|
await settle(this.page, 120);
|
|
820
|
+
if (op === 'edit' || op === 'create') await this.waitForEditor();
|
|
655
821
|
return found.step;
|
|
656
822
|
}
|
|
657
|
-
async field(purpose, { name } = {}) {
|
|
823
|
+
async field(purpose, { name, search = false } = {}) {
|
|
658
824
|
const snap = await this.snapshot();
|
|
659
825
|
const fields = snap.controls.filter(
|
|
660
|
-
(c) =>
|
|
826
|
+
(c) =>
|
|
827
|
+
['textbox', 'spinbutton'].includes(c.role) &&
|
|
828
|
+
!c.disabled &&
|
|
829
|
+
!c.readonly &&
|
|
830
|
+
(!search ||
|
|
831
|
+
(!c.regionAmbiguous && !['banner', 'navigation'].includes(c.region?.role))),
|
|
832
|
+
);
|
|
833
|
+
const matches = fields.filter((c) =>
|
|
834
|
+
name
|
|
835
|
+
? c.name === name
|
|
836
|
+
: (search
|
|
837
|
+
? /名称|姓名|用户名|登录账号|标题|name|title|搜索|查询|关键字|search|query|filter/i
|
|
838
|
+
: nameField
|
|
839
|
+
).test(c.name),
|
|
661
840
|
);
|
|
662
|
-
const matches = fields.filter((c) => (name ? c.name === name : nameField.test(c.name)));
|
|
663
841
|
return this.chooseFromSnapshot(snap, matches, purpose);
|
|
664
842
|
}
|
|
665
843
|
record(step) {
|
|
@@ -685,8 +863,7 @@ export class Workflow {
|
|
|
685
863
|
}
|
|
686
864
|
const actual = this.resolve(value);
|
|
687
865
|
await field.locator.fill(actual);
|
|
688
|
-
|
|
689
|
-
throw Error('输入值没有进入' + field.control.name);
|
|
866
|
+
await verifyInput(this, field.control, actual);
|
|
690
867
|
this.record({ kind: 'fill', target: { ...controlInfo(field.control), scope }, value });
|
|
691
868
|
await settle(this.page, 80);
|
|
692
869
|
}
|
|
@@ -922,7 +1099,7 @@ export class Workflow {
|
|
|
922
1099
|
const plan = await chooseFieldValue(
|
|
923
1100
|
this.laya,
|
|
924
1101
|
{ ...fields[0].inputs[0], label: fields[0].label },
|
|
925
|
-
{ name: value },
|
|
1102
|
+
{ name: value, identity: true },
|
|
926
1103
|
);
|
|
927
1104
|
if (plan.kind !== 'fill' || plan.value !== value)
|
|
928
1105
|
throw Error('模型未生成可追踪的唯一记录名称');
|
|
@@ -933,7 +1110,7 @@ export class Workflow {
|
|
|
933
1110
|
const plan = await chooseFieldValue(
|
|
934
1111
|
this.laya,
|
|
935
1112
|
{ label: field.control.name },
|
|
936
|
-
{ name: value },
|
|
1113
|
+
{ name: value, identity: true },
|
|
937
1114
|
);
|
|
938
1115
|
if (plan.kind !== 'fill' || plan.value !== value)
|
|
939
1116
|
throw Error('模型未生成可追踪的唯一记录名称');
|
|
@@ -1009,13 +1186,18 @@ export class Workflow {
|
|
|
1009
1186
|
return actual;
|
|
1010
1187
|
}
|
|
1011
1188
|
async row(value, present = true) {
|
|
1189
|
+
const lastClick = this.case?.steps.findLast((step) => step.kind === 'click');
|
|
1190
|
+
if (['save', 'delete', 'confirm'].includes(lastClick?.purpose))
|
|
1191
|
+
await this.waitModalClosed();
|
|
1192
|
+
await this.pendingWrites.wait(this.config.pageTimeout || 8000);
|
|
1193
|
+
await expandCollection(this);
|
|
1012
1194
|
const name = this.resolve(value),
|
|
1013
1195
|
rows = this.ownedRows(name);
|
|
1014
1196
|
if (present) await rows.first().waitFor({ timeout: this.config.assertTimeout });
|
|
1015
1197
|
else {
|
|
1016
1198
|
// A missing list or a loading page is not proof of deletion.
|
|
1017
1199
|
await this.page
|
|
1018
|
-
.locator(
|
|
1200
|
+
.locator(COLLECTION)
|
|
1019
1201
|
.first()
|
|
1020
1202
|
.waitFor({ state: 'visible', timeout: this.config.assertTimeout });
|
|
1021
1203
|
await rows.first().waitFor({ state: 'hidden', timeout: this.config.assertTimeout });
|
|
@@ -1026,18 +1208,27 @@ export class Workflow {
|
|
|
1026
1208
|
this.record({ kind: present ? 'assert-row' : 'assert-absent', value });
|
|
1027
1209
|
}
|
|
1028
1210
|
async query(value, { assert = true } = {}) {
|
|
1029
|
-
const search = await this.field('按名称查询独立记录');
|
|
1211
|
+
const search = await this.field('按名称查询独立记录', { search: true });
|
|
1030
1212
|
const byAccount = /登录账号|登录账户|account|login/i.test(search.control.name);
|
|
1031
|
-
|
|
1032
|
-
|
|
1213
|
+
const requested = byAccount && value ? '${recordAccount}' : value;
|
|
1214
|
+
if ((await search.locator.inputValue()) !== this.resolve(requested))
|
|
1215
|
+
await this.fill(search, requested, 'page');
|
|
1216
|
+
const button = await this.action('search', {
|
|
1217
|
+
optional: true,
|
|
1218
|
+
region: search.control.region || null,
|
|
1219
|
+
frame: search.control.frame,
|
|
1220
|
+
});
|
|
1033
1221
|
if (button) {
|
|
1034
1222
|
await button.locator.click();
|
|
1035
1223
|
this.record(button.step);
|
|
1036
1224
|
await settle(this.page, 180);
|
|
1225
|
+
await waitForVisibleStep(this);
|
|
1037
1226
|
}
|
|
1038
1227
|
if (assert) await this.row(value, true);
|
|
1039
1228
|
}
|
|
1040
1229
|
async reload() {
|
|
1230
|
+
if (this.identity?.host)
|
|
1231
|
+
throw Error('旧用例要求刷新主应用,请重新探索生成采用独立持久化校验的新用例');
|
|
1041
1232
|
const lastClick = this.case?.steps.findLast((step) => step.kind === 'click');
|
|
1042
1233
|
if (['save', 'delete', 'confirm'].includes(lastClick?.purpose))
|
|
1043
1234
|
await this.waitModalClosed();
|
|
@@ -1046,6 +1237,105 @@ export class Workflow {
|
|
|
1046
1237
|
await waitForReady(this.page, { timeout: this.config.pageTimeout });
|
|
1047
1238
|
this.record({ kind: 'reload' });
|
|
1048
1239
|
}
|
|
1240
|
+
async assertPersisted(
|
|
1241
|
+
value,
|
|
1242
|
+
present = true,
|
|
1243
|
+
{ record = true, query, inspect, evidenceId } = {},
|
|
1244
|
+
) {
|
|
1245
|
+
this.checkInterrupted();
|
|
1246
|
+
await assertPageIdentity(this.page, this.identity);
|
|
1247
|
+
await this.pendingWrites.wait(this.config.pageTimeout || 8000);
|
|
1248
|
+
activity(this, '正在独立后台会话校验数据持久化,当前主子应用保持不变');
|
|
1249
|
+
const config = {
|
|
1250
|
+
...this.config,
|
|
1251
|
+
url: this.startUrl,
|
|
1252
|
+
headless: true,
|
|
1253
|
+
manualLogin: false,
|
|
1254
|
+
user: '',
|
|
1255
|
+
journal: undefined,
|
|
1256
|
+
};
|
|
1257
|
+
let session, diagnostics;
|
|
1258
|
+
const evidence = `evidence/${safeKey(evidenceId || this.case.id)}-persistence.png`;
|
|
1259
|
+
const trace = `persistence-${safeKey(evidenceId || this.case.id)}.zip`;
|
|
1260
|
+
const stop = () => {
|
|
1261
|
+
void session?.close().catch(() => {});
|
|
1262
|
+
};
|
|
1263
|
+
try {
|
|
1264
|
+
if (!this.verificationAuth) throw Error('缺少探索开始前的登录态快照,不能校验持久化');
|
|
1265
|
+
session = await openBrowser(config, {
|
|
1266
|
+
authState: this.verificationAuth,
|
|
1267
|
+
browser: this.verificationBrowser,
|
|
1268
|
+
});
|
|
1269
|
+
config.signal?.addEventListener('abort', stop, { once: true });
|
|
1270
|
+
this.checkInterrupted();
|
|
1271
|
+
diagnostics = new BrowserDiagnostics(session.context);
|
|
1272
|
+
diagnostics.begin(this.case.id);
|
|
1273
|
+
await session.context.tracing.start({ screenshots: true, snapshots: true });
|
|
1274
|
+
await session.page.goto(this.startUrl, { waitUntil: 'domcontentloaded' });
|
|
1275
|
+
await waitForReady(session.page, { timeout: config.pageTimeout });
|
|
1276
|
+
await ensureAuthentication(
|
|
1277
|
+
session.page,
|
|
1278
|
+
config,
|
|
1279
|
+
async () => {
|
|
1280
|
+
throw Error('独立校验会话登录态已失效');
|
|
1281
|
+
},
|
|
1282
|
+
undefined,
|
|
1283
|
+
true,
|
|
1284
|
+
);
|
|
1285
|
+
await assertPageIdentity(session.page, this.identity, { fresh: true });
|
|
1286
|
+
const reader = new Workflow(session.page, this.laya, config, this.mode, diagnostics);
|
|
1287
|
+
reader.identity = await pageIdentity(session.page);
|
|
1288
|
+
reader.variables = { ...this.variables };
|
|
1289
|
+
await reader.assertModuleAccess();
|
|
1290
|
+
if (query) {
|
|
1291
|
+
validatePersistenceQuery(query);
|
|
1292
|
+
for (const step of query) await reader.replayStep(step);
|
|
1293
|
+
} else {
|
|
1294
|
+
if (this.mode === 'execute')
|
|
1295
|
+
throw Error('持久化断言缺少原始查询步骤,请重新生成 Excel');
|
|
1296
|
+
await reader.query(value, { assert: false });
|
|
1297
|
+
query = reader.log.map(({ step }) => step);
|
|
1298
|
+
validatePersistenceQuery(query);
|
|
1299
|
+
}
|
|
1300
|
+
await reader.row(value, present);
|
|
1301
|
+
if (inspect) {
|
|
1302
|
+
reader.created = this.created;
|
|
1303
|
+
reader.currentName = this.currentName;
|
|
1304
|
+
await inspect(reader);
|
|
1305
|
+
}
|
|
1306
|
+
const events = await diagnostics.end();
|
|
1307
|
+
const severe = severeEvent(events);
|
|
1308
|
+
if (severe) throw Error('独立持久化校验发现 ' + eventLabel(severe));
|
|
1309
|
+
await assertPageIdentity(this.page, this.identity);
|
|
1310
|
+
this.journal?.event('persistence-verified', {
|
|
1311
|
+
caseId: this.case.id,
|
|
1312
|
+
present,
|
|
1313
|
+
evidence,
|
|
1314
|
+
trace,
|
|
1315
|
+
});
|
|
1316
|
+
if (record)
|
|
1317
|
+
this.record({
|
|
1318
|
+
kind: present ? 'assert-persisted-row' : 'assert-persisted-absent',
|
|
1319
|
+
value,
|
|
1320
|
+
query,
|
|
1321
|
+
evidence,
|
|
1322
|
+
trace,
|
|
1323
|
+
});
|
|
1324
|
+
return query;
|
|
1325
|
+
} finally {
|
|
1326
|
+
config.signal?.removeEventListener('abort', stop);
|
|
1327
|
+
if (session) {
|
|
1328
|
+
await session.page
|
|
1329
|
+
.screenshot({ path: path.join(this.config.out, evidence), timeout: 5000 })
|
|
1330
|
+
.catch(() => {});
|
|
1331
|
+
await session.context.tracing
|
|
1332
|
+
.stop({ path: path.join(this.config.out, trace) })
|
|
1333
|
+
.catch(() => {});
|
|
1334
|
+
await session.close();
|
|
1335
|
+
}
|
|
1336
|
+
activity(this, '');
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1049
1339
|
async assertControl(role, name, selected = false) {
|
|
1050
1340
|
const snap = await this.snapshot(),
|
|
1051
1341
|
matches = snap.controls.filter(
|
|
@@ -1078,9 +1368,13 @@ export class Workflow {
|
|
|
1078
1368
|
);
|
|
1079
1369
|
const found = await this.chooseFromSnapshot(snap, matches, '切换到「' + name + '」Tab');
|
|
1080
1370
|
await found.locator.click();
|
|
1371
|
+
const target = { ...controlInfo(found.control), scope: 'page' };
|
|
1372
|
+
// Exact role/name is already required to be unique above. An unnamed
|
|
1373
|
+
// nested main is not a usable region constraint for the saved target.
|
|
1374
|
+
if (found.control.regionAmbiguous) delete target.region;
|
|
1081
1375
|
this.record({
|
|
1082
1376
|
kind: 'click',
|
|
1083
|
-
target
|
|
1377
|
+
target,
|
|
1084
1378
|
purpose: 'tab',
|
|
1085
1379
|
});
|
|
1086
1380
|
await settle(this.page, 180);
|
|
@@ -1100,7 +1394,7 @@ export class Workflow {
|
|
|
1100
1394
|
};
|
|
1101
1395
|
this.case = c;
|
|
1102
1396
|
this.diagnostics.begin(id);
|
|
1103
|
-
this.journal?.checkpoint({ activeCase: c, runtime: this.runtime() });
|
|
1397
|
+
this.journal?.checkpoint({ activeCase: c, runtime: this.runtime(), activity: '' });
|
|
1104
1398
|
try {
|
|
1105
1399
|
await fn();
|
|
1106
1400
|
c.status = '已验证';
|
|
@@ -1125,7 +1419,7 @@ export class Workflow {
|
|
|
1125
1419
|
c.reason = '页面断言通过,但本用例期间发现 ' + eventLabel(severe);
|
|
1126
1420
|
}
|
|
1127
1421
|
c.diagnosis = c.status === '未生成' ? diagnoseFailure(c.reason, c.browserEvents) : null;
|
|
1128
|
-
if (await this.
|
|
1422
|
+
if (await this.editorPresent().catch(() => false)) {
|
|
1129
1423
|
try {
|
|
1130
1424
|
await this.pendingWrites.wait(this.config.pageTimeout || 8000);
|
|
1131
1425
|
await this.dismissModal();
|
|
@@ -1189,79 +1483,116 @@ export class Workflow {
|
|
|
1189
1483
|
if (search) await this.assertControl(search.role, search.name);
|
|
1190
1484
|
if (reset) await this.assertControl(reset.role, reset.name);
|
|
1191
1485
|
});
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1486
|
+
const validateEmptyForm = async () => {
|
|
1487
|
+
const saveControls = (await this.snapshot()).controls.filter(
|
|
1488
|
+
(c) => actions.save.test(c.name) && c.role === 'button',
|
|
1489
|
+
);
|
|
1490
|
+
if (saveControls.length === 1 && saveControls[0].disabled)
|
|
1491
|
+
await this.replayStep({
|
|
1492
|
+
kind: 'assert-disabled',
|
|
1493
|
+
target: controlInfo(saveControls[0]),
|
|
1494
|
+
});
|
|
1495
|
+
else {
|
|
1496
|
+
await this.click('save');
|
|
1497
|
+
await this.assertFormErrors();
|
|
1498
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
let formValidated = false;
|
|
1501
|
+
if (!this.allowed.has('create'))
|
|
1502
|
+
formValidated = await add(
|
|
1503
|
+
'form-validation',
|
|
1504
|
+
'新增表单必填项为空时阻止保存',
|
|
1505
|
+
'form-validation',
|
|
1506
|
+
async () => {
|
|
1507
|
+
await this.clickCreate();
|
|
1508
|
+
await validateEmptyForm();
|
|
1509
|
+
await this.click('close');
|
|
1510
|
+
},
|
|
1511
|
+
);
|
|
1512
|
+
const validateFormat = async () =>
|
|
1513
|
+
add('form-invalid', '数值区间示例的非法括号触发校验', 'form-invalid', async () => {
|
|
1514
|
+
// Reuse only evidence from this run's successfully validated initial
|
|
1515
|
+
// form. Missing/failed observation still follows the normal live check.
|
|
1516
|
+
if (formValidated && this.formEvidence?.hasRangeFormatInput === false)
|
|
1517
|
+
throw Object.assign(Error('已观察的新增表单没有区间格式输入框,本项不适用'), {
|
|
1518
|
+
notApplicable: true,
|
|
1519
|
+
});
|
|
1520
|
+
await this.clickCreate();
|
|
1521
|
+
try {
|
|
1522
|
+
const formatTarget = (await inspectLooseRequired(this.page)).find((x) =>
|
|
1523
|
+
invalidExampleValue(x.placeholder),
|
|
1524
|
+
);
|
|
1525
|
+
if (!formatTarget) {
|
|
1526
|
+
const error = Error('页面没有区间格式输入框,本项不适用');
|
|
1527
|
+
error.notApplicable = true;
|
|
1528
|
+
throw error;
|
|
1529
|
+
}
|
|
1530
|
+
const name = await this.field('填写校验记录名称');
|
|
1531
|
+
await this.fill(name, '${recordName}_invalid');
|
|
1532
|
+
await this.populateForm('名称');
|
|
1533
|
+
const target = (await inspectLooseRequired(this.page)).find((x) =>
|
|
1534
|
+
invalidExampleValue(x.placeholder),
|
|
1535
|
+
);
|
|
1536
|
+
if (!target) throw Error('格式校验输入框在填写后发生变化');
|
|
1537
|
+
await this.formFillRequired(target, invalidExampleValue(target.placeholder));
|
|
1538
|
+
await this.click('save');
|
|
1539
|
+
await this.assertInputInvalid(target);
|
|
1540
|
+
} finally {
|
|
1541
|
+
if ((await formErrors(this.page)).open)
|
|
1542
|
+
await this.click('close').catch(() => {});
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1545
|
+
if (!this.allowed.has('create')) await validateFormat();
|
|
1546
|
+
const created = await add(
|
|
1547
|
+
'create',
|
|
1548
|
+
'新增独立测试记录并验证必填约束',
|
|
1549
|
+
'create',
|
|
1196
1550
|
async () => {
|
|
1197
|
-
const snap = await this.snapshot();
|
|
1198
|
-
if (!snap.controls.some((c) => isAction(c) && actions.create.test(c.name)))
|
|
1199
|
-
await this.click('area');
|
|
1200
1551
|
await this.clickCreate();
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
if (saveControls.length === 1 && saveControls[0].disabled) {
|
|
1205
|
-
await this.replayStep({
|
|
1206
|
-
kind: 'assert-disabled',
|
|
1207
|
-
target: controlInfo(saveControls[0]),
|
|
1208
|
-
});
|
|
1209
|
-
await this.click('close');
|
|
1210
|
-
return;
|
|
1552
|
+
if (this.allowed.has('form-validation')) {
|
|
1553
|
+
await validateEmptyForm();
|
|
1554
|
+
formValidated = true;
|
|
1211
1555
|
}
|
|
1556
|
+
const nameLabel = await this.fillRecordName('${recordName}');
|
|
1557
|
+
await this.populateForm(nameLabel);
|
|
1212
1558
|
await this.click('save');
|
|
1213
|
-
await this.
|
|
1214
|
-
await this.
|
|
1559
|
+
await this.waitModalClosed();
|
|
1560
|
+
await this.pendingWrites.wait(this.config.pageTimeout || 8000);
|
|
1561
|
+
await this.row('${recordName}');
|
|
1562
|
+
await this.assertPersisted('${recordName}');
|
|
1563
|
+
this.created = true;
|
|
1215
1564
|
},
|
|
1216
1565
|
);
|
|
1217
|
-
await add('form-invalid', '数值区间示例的非法括号触发校验', 'form-invalid', async () => {
|
|
1218
|
-
await this.clickCreate();
|
|
1219
|
-
try {
|
|
1220
|
-
const formatTarget = (await inspectLooseRequired(this.page)).find((x) =>
|
|
1221
|
-
invalidExampleValue(x.placeholder),
|
|
1222
|
-
);
|
|
1223
|
-
if (!formatTarget) {
|
|
1224
|
-
const error = Error('页面没有区间格式输入框,本项不适用');
|
|
1225
|
-
error.notApplicable = true;
|
|
1226
|
-
throw error;
|
|
1227
|
-
}
|
|
1228
|
-
const name = await this.field('填写校验记录名称');
|
|
1229
|
-
await this.fill(name, '${recordName}_invalid');
|
|
1230
|
-
await this.populateForm('名称');
|
|
1231
|
-
const target = (await inspectLooseRequired(this.page)).find((x) =>
|
|
1232
|
-
invalidExampleValue(x.placeholder),
|
|
1233
|
-
);
|
|
1234
|
-
if (!target) throw Error('格式校验输入框在填写后发生变化');
|
|
1235
|
-
await this.formFillRequired(target, invalidExampleValue(target.placeholder));
|
|
1236
|
-
await this.click('save');
|
|
1237
|
-
await this.assertInputInvalid(target);
|
|
1238
|
-
} finally {
|
|
1239
|
-
if ((await formErrors(this.page)).open) await this.click('close').catch(() => {});
|
|
1240
|
-
}
|
|
1241
|
-
});
|
|
1242
|
-
const created = await add('create', '新增独立测试记录', 'create', async () => {
|
|
1243
|
-
let snap = await this.snapshot();
|
|
1244
|
-
if (!snap.controls.some((c) => isAction(c) && actions.create.test(c.name))) {
|
|
1245
|
-
await this.click('area');
|
|
1246
|
-
snap = await this.snapshot();
|
|
1247
|
-
}
|
|
1248
|
-
await this.clickCreate();
|
|
1249
|
-
const nameLabel = await this.fillRecordName('${recordName}');
|
|
1250
|
-
await this.populateForm(nameLabel);
|
|
1251
|
-
await this.click('save');
|
|
1252
|
-
await this.reload();
|
|
1253
|
-
await this.query('${recordName}');
|
|
1254
|
-
this.created = true;
|
|
1255
|
-
});
|
|
1256
1566
|
if (created) {
|
|
1257
|
-
await add('search', '
|
|
1567
|
+
await add('search', '查询:按唯一名称检索并核对本轮记录', 'search', async () => {
|
|
1258
1568
|
await this.query('${recordName}');
|
|
1569
|
+
await assertSearchResult(this, {
|
|
1570
|
+
kind: 'assert-query-result',
|
|
1571
|
+
value: '${recordName}',
|
|
1572
|
+
});
|
|
1573
|
+
await this.query('', { assert: false });
|
|
1574
|
+
await this.row('${recordName}');
|
|
1259
1575
|
});
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1576
|
+
let inlineDetail = false;
|
|
1577
|
+
const viewed = await add('view', '查询:打开本轮记录并核对详情', 'view', async () => {
|
|
1578
|
+
if (!(await this.click('view', { rowName: this.currentName, optional: true }))) {
|
|
1579
|
+
const row = this.ownedRows(this.currentName);
|
|
1580
|
+
if ((await row.getAttribute('aria-selected')) === null)
|
|
1581
|
+
throw Object.assign(Error('列表没有查看入口或可选中记录的语义'), {
|
|
1582
|
+
notApplicable: !this.config.operations,
|
|
1583
|
+
});
|
|
1584
|
+
await openOwnedRecord(this, {
|
|
1585
|
+
kind: 'open-owned-record',
|
|
1586
|
+
value: '${recordName}',
|
|
1587
|
+
});
|
|
1588
|
+
await assertRecordDetail(this, {
|
|
1589
|
+
kind: 'assert-record-detail',
|
|
1590
|
+
value: '${recordName}',
|
|
1264
1591
|
});
|
|
1592
|
+
await observeCoverage(this, '详情');
|
|
1593
|
+
inlineDetail = true;
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1265
1596
|
await this.page
|
|
1266
1597
|
.locator(MODAL_SEL)
|
|
1267
1598
|
.last()
|
|
@@ -1271,25 +1602,32 @@ export class Workflow {
|
|
|
1271
1602
|
this.record({ kind: 'assert-text', value: '${recordName}', scope: 'form' });
|
|
1272
1603
|
await this.click('close');
|
|
1273
1604
|
});
|
|
1605
|
+
if (viewed && inlineDetail) await exploreDetailTabs(this);
|
|
1274
1606
|
const edited = await add('edit', '修改独立测试记录名称', 'edit', async () => {
|
|
1275
|
-
|
|
1607
|
+
// Remove our own filter before editing, so the renamed record can
|
|
1608
|
+
// appear without a query that would conceal a stale UI update.
|
|
1609
|
+
await this.query('', { assert: false });
|
|
1276
1610
|
await this.click('edit', { rowName: this.currentName });
|
|
1277
1611
|
await this.fillRecordName('${updatedName}');
|
|
1278
1612
|
await this.click('save');
|
|
1279
|
-
await this.
|
|
1280
|
-
await this.
|
|
1613
|
+
await this.waitModalClosed();
|
|
1614
|
+
await this.pendingWrites.wait(this.config.pageTimeout || 8000);
|
|
1615
|
+
await this.row('${updatedName}');
|
|
1616
|
+
await this.row('${recordName}', false);
|
|
1617
|
+
await this.assertPersisted('${updatedName}');
|
|
1281
1618
|
this.currentName = this.variables.updatedName;
|
|
1282
1619
|
});
|
|
1283
1620
|
if (edited || !this.allowed.has('edit'))
|
|
1284
1621
|
await add('delete', '删除独立测试记录', 'delete', async () => {
|
|
1285
1622
|
const value = edited ? '${updatedName}' : '${recordName}';
|
|
1286
|
-
await this.
|
|
1623
|
+
await this.row(value);
|
|
1287
1624
|
await this.click('delete', { rowName: this.currentName });
|
|
1288
1625
|
const dialog = this.page.locator(MODAL_SEL + ',.ant-popover:visible');
|
|
1289
1626
|
if (await dialog.count()) await this.click('confirm');
|
|
1290
|
-
await this.
|
|
1291
|
-
await this.
|
|
1627
|
+
await this.waitModalClosed();
|
|
1628
|
+
await this.pendingWrites.wait(this.config.pageTimeout || 8000);
|
|
1292
1629
|
await this.row(value, false);
|
|
1630
|
+
await this.assertPersisted(value, false);
|
|
1293
1631
|
this.created = false;
|
|
1294
1632
|
});
|
|
1295
1633
|
else if (this.allowed.has('delete'))
|
|
@@ -1318,14 +1656,37 @@ export class Workflow {
|
|
|
1318
1656
|
attempts: [],
|
|
1319
1657
|
evidence: '',
|
|
1320
1658
|
});
|
|
1659
|
+
if (this.allowed.has('create') && this.formEvidence?.hasRangeFormatInput)
|
|
1660
|
+
await validateFormat();
|
|
1321
1661
|
if (this.allowed.has('discover')) await discoverTests(this);
|
|
1662
|
+
else if (this.allowed.has('filters')) {
|
|
1663
|
+
activity(this, '正在只读探索:展开记录树、验证筛选并恢复查询条件');
|
|
1664
|
+
try {
|
|
1665
|
+
await discoverTests(this, { readOnly: true });
|
|
1666
|
+
} finally {
|
|
1667
|
+
activity(this, '');
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1322
1670
|
if (!results.length)
|
|
1323
1671
|
throw Error(
|
|
1324
|
-
|
|
1672
|
+
this.config.readOnly
|
|
1673
|
+
? '只读探索未找到可验证的页签、列表或筛选用例。请确认当前业务页面已加载且控件具有可访问名称;如需探索新增、修改、删除,请勾选“允许创建、修改和删除本轮测试数据”。'
|
|
1674
|
+
: '当前页面未发现所选范围的可验证用例;请检查页面是否为目标模块及 --operations 配置',
|
|
1325
1675
|
);
|
|
1326
1676
|
return results;
|
|
1327
1677
|
}
|
|
1328
1678
|
async replayStep(step) {
|
|
1679
|
+
if (step.kind === 'assert-related-records') return executeRelatedRecords(this, step);
|
|
1680
|
+
if (step.kind === 'open-owned-record') return openOwnedRecord(this, step);
|
|
1681
|
+
if (step.kind === 'assert-record-detail') return assertRecordDetail(this, step);
|
|
1682
|
+
if (step.kind === 'assert-tab-panel') return assertTabPanel(this, step);
|
|
1683
|
+
if (step.kind === 'assert-query-result') return assertSearchResult(this, step);
|
|
1684
|
+
if (step.kind === 'assert-disclosure') return inspectDisclosure(this, step);
|
|
1685
|
+
if (step.kind === 'assert-persisted-row' || step.kind === 'assert-persisted-absent')
|
|
1686
|
+
return this.assertPersisted(step.value, step.kind === 'assert-persisted-row', {
|
|
1687
|
+
query: step.query,
|
|
1688
|
+
});
|
|
1689
|
+
if (step.kind === 'expand-tree') return expandTree(this, step.target);
|
|
1329
1690
|
if (step.kind === 'assert-discovery') return executeDiscovery(this, step);
|
|
1330
1691
|
if (step.kind === 'assert-control' || step.kind === 'assert-selected')
|
|
1331
1692
|
return this.assertControl(
|
|
@@ -1372,6 +1733,10 @@ export class Workflow {
|
|
|
1372
1733
|
return;
|
|
1373
1734
|
}
|
|
1374
1735
|
const target = step.target;
|
|
1736
|
+
const treeCreate =
|
|
1737
|
+
step.kind === 'click' && step.purpose === 'create'
|
|
1738
|
+
? await revealTreeActions(this.page, target)
|
|
1739
|
+
: null;
|
|
1375
1740
|
const rowMenu =
|
|
1376
1741
|
target.scope === 'owned-row' &&
|
|
1377
1742
|
target.role === 'menuitem' &&
|
|
@@ -1384,6 +1749,15 @@ export class Workflow {
|
|
|
1384
1749
|
}
|
|
1385
1750
|
let snap = await this.snapshot();
|
|
1386
1751
|
if (target.scope === 'owned-row' && !rowMenu) {
|
|
1752
|
+
if ((await this.ownedRows(this.currentName).getAttribute('role')) === 'treeitem') {
|
|
1753
|
+
await (
|
|
1754
|
+
await this.ownedActionRows(this.currentName)
|
|
1755
|
+
)
|
|
1756
|
+
.locator('button,[role="button"]')
|
|
1757
|
+
.first()
|
|
1758
|
+
.hover();
|
|
1759
|
+
snap = await this.snapshot();
|
|
1760
|
+
}
|
|
1387
1761
|
const key = await this.ownedRows(this.currentName).getAttribute('data-row-key');
|
|
1388
1762
|
if (key) snap = await discoverRowLabels(this.page, key);
|
|
1389
1763
|
}
|
|
@@ -1393,10 +1767,13 @@ export class Workflow {
|
|
|
1393
1767
|
c.role === target.role &&
|
|
1394
1768
|
!c.disabled &&
|
|
1395
1769
|
!c.readonly &&
|
|
1770
|
+
(!target.region || sameRegion(c, target)) &&
|
|
1396
1771
|
(target.scope !== 'owned-row' || rowMenu || c.context.includes(this.currentName)),
|
|
1397
1772
|
);
|
|
1398
1773
|
const scoped = [];
|
|
1774
|
+
const treeCreateRef = treeCreate ? await treeCreate.getAttribute(LIVE_REF) : null;
|
|
1399
1775
|
for (const c of matches) {
|
|
1776
|
+
if (treeCreate && c.ref !== treeCreateRef) continue;
|
|
1400
1777
|
if (
|
|
1401
1778
|
target.scope !== 'owned-row' ||
|
|
1402
1779
|
rowMenu ||
|
|
@@ -1423,17 +1800,25 @@ export class Workflow {
|
|
|
1423
1800
|
if (step.kind === 'fill') {
|
|
1424
1801
|
const value = this.resolve(step.value);
|
|
1425
1802
|
await found.locator.fill(value);
|
|
1426
|
-
|
|
1803
|
+
await verifyInput(this, found.control, value);
|
|
1427
1804
|
} else await this.dispatchClick(found.locator, step);
|
|
1428
1805
|
this.record(step);
|
|
1429
1806
|
await settle(this.page, 120);
|
|
1807
|
+
if (step.kind === 'click' && ['create', 'edit'].includes(step.purpose))
|
|
1808
|
+
await this.waitForEditor();
|
|
1809
|
+
await waitForVisibleStep(this);
|
|
1430
1810
|
}
|
|
1431
1811
|
async replay(file) {
|
|
1432
1812
|
await this.assertModuleAccess();
|
|
1813
|
+
this.coverage = file.exploration || null;
|
|
1814
|
+
if (this.identity?.host && file.cases.some((c) => c.steps.some((s) => s.kind === 'reload')))
|
|
1815
|
+
throw Error('旧 Excel 含整页刷新步骤;主子应用请重新探索生成新用例,未执行任何用例');
|
|
1433
1816
|
const results = this.results;
|
|
1434
1817
|
let editFailed = false;
|
|
1818
|
+
let viewFailed = false;
|
|
1435
1819
|
for (const saved of file.cases) {
|
|
1436
1820
|
this.checkInterrupted();
|
|
1821
|
+
if (this.restorationFailure) throw Error(this.restorationFailure);
|
|
1437
1822
|
const started = performance.now();
|
|
1438
1823
|
const c = {
|
|
1439
1824
|
id: saved.id,
|
|
@@ -1450,12 +1835,15 @@ export class Workflow {
|
|
|
1450
1835
|
this.diagnostics.begin(c.id);
|
|
1451
1836
|
this.journal?.checkpoint({ activeCase: c, runtime: this.runtime() });
|
|
1452
1837
|
if (
|
|
1453
|
-
['search', 'view', 'edit', 'delete'].includes(saved.operation) &&
|
|
1838
|
+
['search', 'view', 'related-records', 'edit', 'delete'].includes(saved.operation) &&
|
|
1454
1839
|
(!this.created ||
|
|
1840
|
+
(viewFailed &&
|
|
1841
|
+
['view', 'related-records'].includes(saved.operation) &&
|
|
1842
|
+
saved.id !== 'view') ||
|
|
1455
1843
|
(editFailed && JSON.stringify(saved.steps).includes('${updatedName}')))
|
|
1456
1844
|
) {
|
|
1457
1845
|
c.status = '未执行(依赖阻断)';
|
|
1458
|
-
c.reason = '
|
|
1846
|
+
c.reason = '前置新增、详情打开或修改未通过,本条所需的页面状态未确认';
|
|
1459
1847
|
} else
|
|
1460
1848
|
try {
|
|
1461
1849
|
for (const [index, step] of saved.steps.entries()) {
|
|
@@ -1503,9 +1891,10 @@ export class Workflow {
|
|
|
1503
1891
|
: null;
|
|
1504
1892
|
if (c.status === '通过' && saved.operation === 'create') this.created = true;
|
|
1505
1893
|
if (saved.operation === 'edit') editFailed = c.status !== '通过';
|
|
1894
|
+
if (saved.id === 'view') viewFailed = c.status !== '通过';
|
|
1506
1895
|
if (c.status === '通过' && saved.operation === 'edit')
|
|
1507
1896
|
this.currentName = this.variables.updatedName;
|
|
1508
|
-
if (await this.
|
|
1897
|
+
if (await this.editorPresent().catch(() => false)) {
|
|
1509
1898
|
try {
|
|
1510
1899
|
await this.pendingWrites.wait(this.config.pageTimeout || 8000);
|
|
1511
1900
|
await this.dismissModal();
|
|
@@ -1559,6 +1948,7 @@ export async function runWorkflow(config, mode, readSecret, root) {
|
|
|
1559
1948
|
const journal = new RunJournal(config.out, { mode, moduleUrl, provider: config.provider });
|
|
1560
1949
|
try {
|
|
1561
1950
|
let browser,
|
|
1951
|
+
verificationBrowser,
|
|
1562
1952
|
context,
|
|
1563
1953
|
page,
|
|
1564
1954
|
diagnostics,
|
|
@@ -1574,7 +1964,7 @@ export async function runWorkflow(config, mode, readSecret, root) {
|
|
|
1574
1964
|
await Promise.race([
|
|
1575
1965
|
context.tracing.stop({ path: path.join(config.out, 'trace.zip') }),
|
|
1576
1966
|
new Promise((_, reject) => {
|
|
1577
|
-
timer = setTimeout(() => reject(Error('保存 trace 超时')),
|
|
1967
|
+
timer = setTimeout(() => reject(Error('保存 trace 超时')), 30000);
|
|
1578
1968
|
}),
|
|
1579
1969
|
]);
|
|
1580
1970
|
} catch (error) {
|
|
@@ -1602,6 +1992,7 @@ export async function runWorkflow(config, mode, readSecret, root) {
|
|
|
1602
1992
|
clearTimeout(timer);
|
|
1603
1993
|
}
|
|
1604
1994
|
await browser?.close().catch(() => {});
|
|
1995
|
+
await verificationBrowser?.close().catch(() => {});
|
|
1605
1996
|
});
|
|
1606
1997
|
config = { ...config, url: url.href, journal, signal: interruption.signal };
|
|
1607
1998
|
let savedCaseFile = null,
|
|
@@ -1631,8 +2022,18 @@ export async function runWorkflow(config, mode, readSecret, root) {
|
|
|
1631
2022
|
`模式:${mode};模型:${config.provider};浏览器:${config.headless ? '无头' : '可见'}`,
|
|
1632
2023
|
);
|
|
1633
2024
|
const modelWarmup = beginModelWarmup(laya, config);
|
|
2025
|
+
journal.checkpoint({ activity: '正在打开测试页面并校验登录状态' });
|
|
1634
2026
|
config.signal.throwIfAborted();
|
|
1635
2027
|
let authRestored;
|
|
2028
|
+
// Start the headless verifier BEFORE showing the test window. Creating
|
|
2029
|
+
// Chrome processes during a visible run can steal focus on Windows.
|
|
2030
|
+
// Each verification still gets a fresh context with pre-write auth.
|
|
2031
|
+
if (!config.readOnly)
|
|
2032
|
+
verificationBrowser = await launchBrowser({ ...config, headless: true });
|
|
2033
|
+
if (verificationBrowser)
|
|
2034
|
+
journal.event('verification-browser-ready', {
|
|
2035
|
+
lifecycle: 'one-per-run-before-visible-browser',
|
|
2036
|
+
});
|
|
1636
2037
|
({ browser, context, page, authRestored } = await openBrowser(config));
|
|
1637
2038
|
config.signal.throwIfAborted();
|
|
1638
2039
|
diagnostics = new BrowserDiagnostics(context);
|
|
@@ -1653,11 +2054,22 @@ export async function runWorkflow(config, mode, readSecret, root) {
|
|
|
1653
2054
|
authRestored,
|
|
1654
2055
|
);
|
|
1655
2056
|
await saveAuthState(context, page, config);
|
|
2057
|
+
journal.checkpoint({
|
|
2058
|
+
activity: '页面已就绪,正在等待本地 Laya 模型加载;首次加载可能需要约一分钟',
|
|
2059
|
+
});
|
|
1656
2060
|
await waitModelWarmup(modelWarmup);
|
|
1657
2061
|
writePrivateJson(path.join(config.out, '启动浏览器事件.json'), await diagnostics.end());
|
|
1658
2062
|
config.signal.throwIfAborted();
|
|
1659
2063
|
workflow = new Workflow(page, laya, config, mode, diagnostics);
|
|
1660
|
-
|
|
2064
|
+
workflow.verificationBrowser = verificationBrowser;
|
|
2065
|
+
workflow.identity = await pageIdentity(page);
|
|
2066
|
+
workflow.verificationAuth = await captureVerificationAuth(page, config);
|
|
2067
|
+
journal.checkpoint({
|
|
2068
|
+
runtime: workflow.runtime(),
|
|
2069
|
+
authStatus,
|
|
2070
|
+
activity: '',
|
|
2071
|
+
explorationMode: config.readOnly ? 'read-only' : 'read-write',
|
|
2072
|
+
});
|
|
1661
2073
|
// Authentication is complete before screenshots/traces/progress are recorded.
|
|
1662
2074
|
await context.tracing.start({ screenshots: true, snapshots: true, sources: false });
|
|
1663
2075
|
traceStarted = true;
|
|
@@ -1670,6 +2082,7 @@ export async function runWorkflow(config, mode, readSecret, root) {
|
|
|
1670
2082
|
schemaVersion: 1,
|
|
1671
2083
|
generatedAt: new Date().toISOString(),
|
|
1672
2084
|
moduleUrl,
|
|
2085
|
+
exploration: workflow.coverage || null,
|
|
1673
2086
|
cases: results
|
|
1674
2087
|
.filter((r) => r.status === '已验证')
|
|
1675
2088
|
.map(({ status, reason, evidence, attempts, ...c }) => c),
|
|
@@ -1728,6 +2141,7 @@ export async function runWorkflow(config, mode, readSecret, root) {
|
|
|
1728
2141
|
await stopTrace();
|
|
1729
2142
|
await interruption.dispose();
|
|
1730
2143
|
laya?.close();
|
|
2144
|
+
await verificationBrowser?.close().catch(() => {});
|
|
1731
2145
|
if (!(config.keepOpen && !config.headless && !failure))
|
|
1732
2146
|
await browser?.close().catch(() => {});
|
|
1733
2147
|
}
|
|
@@ -1779,6 +2193,7 @@ export async function runWorkflow(config, mode, readSecret, root) {
|
|
|
1779
2193
|
retainedRecord: workflow?.created ? workflow.currentName : null,
|
|
1780
2194
|
modelStartup: laya?.startup || null,
|
|
1781
2195
|
discovery: workflow?.discovery || null,
|
|
2196
|
+
coverage: workflow?.coverage || null,
|
|
1782
2197
|
metrics: {
|
|
1783
2198
|
modelCalls: actualCalls.length + (laya?.errors?.length || 0),
|
|
1784
2199
|
modelErrors: laya?.errors?.length || 0,
|