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
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
// Semantic master/detail navigation extends the upstream executor. The model
|
|
2
|
+
// chooses from observed controls; it never supplies selectors or scripts.
|
|
3
|
+
import { selectDiscovery } from './discovery.mjs';
|
|
4
|
+
import { assertPageIdentity, activity, waitForVisibleStep } from './page-session.mjs';
|
|
5
|
+
import { recordTrees } from './page-capabilities.mjs';
|
|
6
|
+
import { matchReplayTarget } from './replay-model.mjs';
|
|
7
|
+
import { exploreRelatedRecords } from './related-records.mjs';
|
|
8
|
+
|
|
9
|
+
export async function assertSearchResult(w, step) {
|
|
10
|
+
await w.row(step.value);
|
|
11
|
+
const trees = recordTrees(w.page);
|
|
12
|
+
let total;
|
|
13
|
+
if ((await trees.count()) === 1)
|
|
14
|
+
total = await trees
|
|
15
|
+
.getByRole('treeitem')
|
|
16
|
+
.filter({ visible: true })
|
|
17
|
+
.evaluateAll((items) => items.filter((e) => !e.hasAttribute('aria-expanded')).length);
|
|
18
|
+
else {
|
|
19
|
+
const collection = w
|
|
20
|
+
.ownedRows(w.resolve(step.value))
|
|
21
|
+
.locator('xpath=ancestor::*[self::table or @role="grid"][1]');
|
|
22
|
+
if ((await collection.count()) !== 1) throw Error('无法确定查询结果所属的唯一列表');
|
|
23
|
+
total = await collection
|
|
24
|
+
.locator('tbody tr,[role="row"]')
|
|
25
|
+
.filter({ visible: true })
|
|
26
|
+
.evaluateAll(
|
|
27
|
+
(rows) =>
|
|
28
|
+
rows.filter(
|
|
29
|
+
(e) =>
|
|
30
|
+
e.querySelector('td,[role="gridcell"],[role="cell"]') &&
|
|
31
|
+
!e.matches('.ant-table-placeholder') &&
|
|
32
|
+
!e.querySelector('.ant-empty,.el-table__empty-block'),
|
|
33
|
+
).length,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (total !== 1) throw Error('唯一关键词查询未收敛到本轮记录,不能只凭输入框变化认为查询通过');
|
|
37
|
+
w.record(step);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function openOwnedRecord(w, step) {
|
|
41
|
+
if (!w.created) throw Error('查看详情需要本轮已创建的独立记录');
|
|
42
|
+
const name = w.resolve(step.value);
|
|
43
|
+
if (name !== w.currentName) throw Error('详情目标不是本轮当前记录');
|
|
44
|
+
const row = w.ownedRows(name);
|
|
45
|
+
if ((await row.count()) !== 1) throw Error('详情记录不唯一');
|
|
46
|
+
const snap = await w.snapshot();
|
|
47
|
+
const candidates = [];
|
|
48
|
+
for (const c of snap.controls) {
|
|
49
|
+
if (!['button', 'link'].includes(c.role) || c.disabled || !c.name.includes(name)) continue;
|
|
50
|
+
if (await row.locator(`[data-laya-live-ref="${c.ref}"]`).count()) candidates.push(c);
|
|
51
|
+
}
|
|
52
|
+
let found;
|
|
53
|
+
if (w.mode === 'execute' && candidates.length === 1) {
|
|
54
|
+
// Upstream replay uses stable option keys (目标1, 目标2). A random record
|
|
55
|
+
// identifier is test data, not a useful classifier label for Laya.
|
|
56
|
+
const c = await matchReplayTarget(w.laya, '点击', candidates[0].name, candidates, w.config);
|
|
57
|
+
found = { locator: snap.frames[c.frame].locator(`[data-laya-live-ref="${c.ref}"]`) };
|
|
58
|
+
} else
|
|
59
|
+
found = await w.chooseFromSnapshot(snap, candidates, '打开本轮记录「' + name + '」的详情');
|
|
60
|
+
await found.locator.click();
|
|
61
|
+
await assertPageIdentity(w.page, w.identity);
|
|
62
|
+
await waitForVisibleStep(w);
|
|
63
|
+
w.record(step);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function assertRecordDetail(w, step, { record = true } = {}) {
|
|
67
|
+
const name = w.resolve(step.value);
|
|
68
|
+
// A matching list label is not evidence that detail opened. Require an
|
|
69
|
+
// independently rendered heading/definition outside every collection.
|
|
70
|
+
await w.page.waitForFunction(
|
|
71
|
+
(name) =>
|
|
72
|
+
[...document.querySelectorAll('h1,h2,h3,h4,h5,h6,[role="heading"],dd')].some((e) => {
|
|
73
|
+
const rect = e.getBoundingClientRect();
|
|
74
|
+
return (
|
|
75
|
+
rect.width > 0 &&
|
|
76
|
+
rect.height > 0 &&
|
|
77
|
+
!e.closest(
|
|
78
|
+
'[role="tree"],table,[role="grid"],nav,header,[aria-hidden="true"]',
|
|
79
|
+
) &&
|
|
80
|
+
e.textContent.includes(name)
|
|
81
|
+
);
|
|
82
|
+
}),
|
|
83
|
+
name,
|
|
84
|
+
{ timeout: w.config.assertTimeout || 4000 },
|
|
85
|
+
);
|
|
86
|
+
if (record) w.record(step);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function assertTabPanel(w, step) {
|
|
90
|
+
const tab = w.page.getByRole('tab', { name: step.target.name, exact: true });
|
|
91
|
+
if ((await tab.count()) !== 1) throw Error('页签入口不唯一:' + step.target.name);
|
|
92
|
+
await w.page.waitForFunction(
|
|
93
|
+
(name) => {
|
|
94
|
+
const visible = (e) =>
|
|
95
|
+
!!e &&
|
|
96
|
+
e.getBoundingClientRect().width > 0 &&
|
|
97
|
+
e.getBoundingClientRect().height > 0 &&
|
|
98
|
+
!e.closest('[hidden],[aria-hidden="true"]');
|
|
99
|
+
const tabs = [...document.querySelectorAll('[role="tab"]')].filter(
|
|
100
|
+
(e) =>
|
|
101
|
+
visible(e) && (e.getAttribute('aria-label') || e.textContent).trim() === name,
|
|
102
|
+
);
|
|
103
|
+
if (tabs.length !== 1 || tabs[0].getAttribute('aria-selected') !== 'true') return false;
|
|
104
|
+
const panel = document.getElementById(tabs[0].getAttribute('aria-controls'));
|
|
105
|
+
return (
|
|
106
|
+
visible(panel) &&
|
|
107
|
+
panel.getAttribute('role') === 'tabpanel' &&
|
|
108
|
+
panel.getAttribute('aria-busy') !== 'true'
|
|
109
|
+
);
|
|
110
|
+
},
|
|
111
|
+
step.target.name,
|
|
112
|
+
{ timeout: w.config.assertTimeout || 4000 },
|
|
113
|
+
);
|
|
114
|
+
w.record(step);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function inspectDisclosure(w, step) {
|
|
118
|
+
if (w.restorationFailure) throw Error(w.restorationFailure);
|
|
119
|
+
const tab = w.page.getByRole('tab', { name: step.target.tab, exact: true });
|
|
120
|
+
const panel = w.page.getByRole('tabpanel').filter({ visible: true });
|
|
121
|
+
if ((await tab.getAttribute('aria-selected')) !== 'true' || (await panel.count()) !== 1)
|
|
122
|
+
throw Error('展开检查需要唯一的当前详情面板');
|
|
123
|
+
const initial = await w.snapshot();
|
|
124
|
+
const candidates = initial.controls.filter(
|
|
125
|
+
(c) =>
|
|
126
|
+
c.role === 'button' &&
|
|
127
|
+
c.name === step.target.name &&
|
|
128
|
+
c.inPanel &&
|
|
129
|
+
!c.disabled &&
|
|
130
|
+
c.expanded === false,
|
|
131
|
+
);
|
|
132
|
+
if (candidates.length !== 1) throw Error('展开入口不唯一或不是收起状态');
|
|
133
|
+
if ((await panel.locator(`[data-laya-live-ref="${candidates[0].ref}"]`).count()) !== 1)
|
|
134
|
+
throw Error('展开按钮不属于当前详情面板');
|
|
135
|
+
const before = initial.controls.filter((c) => c.inPanel).map((c) => c.role + ':' + c.name);
|
|
136
|
+
let failure;
|
|
137
|
+
try {
|
|
138
|
+
const found = await w.chooseFromSnapshot(
|
|
139
|
+
initial,
|
|
140
|
+
candidates,
|
|
141
|
+
'点击「' + step.target.name + '」',
|
|
142
|
+
);
|
|
143
|
+
await found.locator.click();
|
|
144
|
+
await waitForVisibleStep(w);
|
|
145
|
+
const opened = panel.locator(
|
|
146
|
+
'button[aria-expanded="true"],[role="button"][aria-expanded="true"]',
|
|
147
|
+
);
|
|
148
|
+
await opened.waitFor({ state: 'visible', timeout: w.config.assertTimeout || 4000 });
|
|
149
|
+
if ((await opened.count()) !== 1) throw Error('展开后无法确定唯一恢复入口');
|
|
150
|
+
let after = [];
|
|
151
|
+
const deadline = Date.now() + (w.config.assertTimeout || 4000);
|
|
152
|
+
do {
|
|
153
|
+
w.checkInterrupted();
|
|
154
|
+
after = (await w.snapshot()).controls.filter(
|
|
155
|
+
(c) => c.inPanel && !before.includes(c.role + ':' + c.name) && c.expanded !== true,
|
|
156
|
+
);
|
|
157
|
+
if (after.length) break;
|
|
158
|
+
await w.page.waitForTimeout(80);
|
|
159
|
+
} while (Date.now() < deadline);
|
|
160
|
+
if (!after.length) throw Error('展开后没有出现新的可操作控件');
|
|
161
|
+
await observeCoverage(w, `详情 / ${step.target.tab} / ${step.target.name}`, {
|
|
162
|
+
panel: step.target.tab,
|
|
163
|
+
});
|
|
164
|
+
} catch (e) {
|
|
165
|
+
failure = e;
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
const opened = panel.locator(
|
|
169
|
+
'button[aria-expanded="true"],[role="button"][aria-expanded="true"]',
|
|
170
|
+
);
|
|
171
|
+
if ((await opened.count()) === 1) {
|
|
172
|
+
const snap = await w.snapshot();
|
|
173
|
+
const ref = await opened.getAttribute('data-laya-live-ref');
|
|
174
|
+
const candidate = snap.controls.find((c) => c.ref === ref);
|
|
175
|
+
const found = await w.chooseFromSnapshot(
|
|
176
|
+
snap,
|
|
177
|
+
[candidate].filter(Boolean),
|
|
178
|
+
'点击「' + candidate?.name + '」',
|
|
179
|
+
);
|
|
180
|
+
await found.locator.click();
|
|
181
|
+
await waitForVisibleStep(w);
|
|
182
|
+
}
|
|
183
|
+
const restored = (await w.snapshot()).controls.filter(
|
|
184
|
+
(c) =>
|
|
185
|
+
c.role === 'button' &&
|
|
186
|
+
c.name === step.target.name &&
|
|
187
|
+
c.inPanel &&
|
|
188
|
+
c.expanded === false,
|
|
189
|
+
);
|
|
190
|
+
if (restored.length !== 1) throw Error('展开区未恢复');
|
|
191
|
+
await assertPageIdentity(w.page, w.identity);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
w.restorationFailure = '详情展开区恢复失败,停止后续探索:' + e.message;
|
|
194
|
+
throw Error(w.restorationFailure);
|
|
195
|
+
}
|
|
196
|
+
if (failure) throw failure;
|
|
197
|
+
w.coverage.gaps = w.coverage.gaps.filter(
|
|
198
|
+
(g) =>
|
|
199
|
+
!(
|
|
200
|
+
g.name === step.target.name &&
|
|
201
|
+
['详情', `详情 / ${step.target.tab}`].includes(g.state)
|
|
202
|
+
),
|
|
203
|
+
);
|
|
204
|
+
w.record(step);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export async function observeCoverage(w, state, { panel } = {}) {
|
|
208
|
+
const snap = await w.snapshot();
|
|
209
|
+
w.coverage ??= { states: [], gaps: [] };
|
|
210
|
+
if (!w.coverage.states.includes(state)) w.coverage.states.push(state);
|
|
211
|
+
for (const c of snap.controls) {
|
|
212
|
+
if (!['button', 'link', 'checkbox', 'switch', 'combobox'].includes(c.role) || !c.name)
|
|
213
|
+
continue;
|
|
214
|
+
// Bind inventory to its owning panel. Re-observing an expanded state
|
|
215
|
+
// must not count the same button again, or include sibling-panel tools.
|
|
216
|
+
if (panel ? !c.inPanel : c.inPanel) continue;
|
|
217
|
+
if (c.expanded === true) continue;
|
|
218
|
+
const locator = snap.frames[c.frame].locator(`[data-laya-live-ref="${c.ref}"]`);
|
|
219
|
+
const inside = await locator.evaluate(
|
|
220
|
+
(e) =>
|
|
221
|
+
!!e.closest('main,[role="main"],[role="tabpanel"],dialog,[role="dialog"]') &&
|
|
222
|
+
!e.closest(
|
|
223
|
+
'[role="tree"],nav,header,[data-research-assistant],gz-research-assistant',
|
|
224
|
+
),
|
|
225
|
+
);
|
|
226
|
+
if (!inside || c.name.includes(w.variables.recordName)) continue;
|
|
227
|
+
const reason = c.disabled
|
|
228
|
+
? '当前数据条件下入口不可用,未执行'
|
|
229
|
+
: '已发现入口,尚无可验证并可恢复的测试步骤';
|
|
230
|
+
const owner = panel ? `详情 / ${panel}` : state;
|
|
231
|
+
const item = { state: owner, role: c.role, name: c.name, reason };
|
|
232
|
+
if (
|
|
233
|
+
!w.coverage.gaps.some(
|
|
234
|
+
(g) => g.state === owner && g.role === c.role && g.name === c.name,
|
|
235
|
+
)
|
|
236
|
+
)
|
|
237
|
+
w.coverage.gaps.push(item);
|
|
238
|
+
}
|
|
239
|
+
w.journal?.checkpoint({ coverage: w.coverage });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export async function exploreDetailTabs(w) {
|
|
243
|
+
const snap = await w.snapshot();
|
|
244
|
+
const tabs = snap.controls.filter(
|
|
245
|
+
(c) =>
|
|
246
|
+
c.role === 'tab' &&
|
|
247
|
+
c.name &&
|
|
248
|
+
!c.disabled &&
|
|
249
|
+
!['navigation', 'banner'].includes(c.region?.role),
|
|
250
|
+
);
|
|
251
|
+
const selected = tabs.filter((c) => c.selected);
|
|
252
|
+
if (
|
|
253
|
+
selected.length !== 1 ||
|
|
254
|
+
tabs.some((c) => tabs.filter((t) => t.name === c.name).length !== 1)
|
|
255
|
+
) {
|
|
256
|
+
if (tabs.length) {
|
|
257
|
+
w.coverage.gaps.push({
|
|
258
|
+
state: '详情',
|
|
259
|
+
role: 'tablist',
|
|
260
|
+
name: '详情页签',
|
|
261
|
+
reason: '无法确定唯一页签组及恢复入口',
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const original = selected[0];
|
|
267
|
+
const group = w.page
|
|
268
|
+
.getByRole('tab', { name: original.name, exact: true })
|
|
269
|
+
.locator('xpath=ancestor::*[@role="tablist"][1]');
|
|
270
|
+
if ((await group.count()) !== 1) throw Error('详情页签缺少唯一的 tablist 容器');
|
|
271
|
+
let changed = false;
|
|
272
|
+
const queue = [...tabs];
|
|
273
|
+
const seen = new Set();
|
|
274
|
+
for (let index = 0; index < queue.length && index < 12; index++) {
|
|
275
|
+
const tab = queue[index];
|
|
276
|
+
seen.add(tab.name);
|
|
277
|
+
w.checkInterrupted();
|
|
278
|
+
if ((await group.getByRole('tab', { name: tab.name, exact: true }).count()) !== 1) continue;
|
|
279
|
+
const title = `查询详情:${tab.name}页签及关联内容`;
|
|
280
|
+
const decision = await selectDiscovery(w.laya, {
|
|
281
|
+
title,
|
|
282
|
+
evidence: `role=tab;${tab.name};有明确的初始选中页签 ${original.name}`,
|
|
283
|
+
});
|
|
284
|
+
if (!decision.selected) {
|
|
285
|
+
w.coverage.gaps.push({
|
|
286
|
+
state: '详情',
|
|
287
|
+
role: 'tab',
|
|
288
|
+
name: tab.name,
|
|
289
|
+
reason: '模型判断证据不足,未执行',
|
|
290
|
+
});
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
activity(w, '正在探索' + title);
|
|
294
|
+
const result = await w.runCase(`view-tab-${index + 1}`, title, 'view', async () => {
|
|
295
|
+
if (tab.name !== original.name || changed) await w.clickTab(tab.name);
|
|
296
|
+
changed = tab.name !== original.name;
|
|
297
|
+
await assertRecordDetail(w, { kind: 'assert-record-detail', value: '${recordName}' });
|
|
298
|
+
await assertTabPanel(w, {
|
|
299
|
+
kind: 'assert-tab-panel',
|
|
300
|
+
target: { role: 'tab', name: tab.name },
|
|
301
|
+
});
|
|
302
|
+
await observeCoverage(w, `详情 / ${tab.name}`, { panel: tab.name });
|
|
303
|
+
const controls = (await w.snapshot()).controls;
|
|
304
|
+
for (const c of controls
|
|
305
|
+
.filter(
|
|
306
|
+
(c) => c.role === 'button' && c.inPanel && c.expanded === false && !c.disabled,
|
|
307
|
+
)
|
|
308
|
+
.slice(0, 4)) {
|
|
309
|
+
if (
|
|
310
|
+
controls.filter((t) => t.inPanel && t.role === 'button' && t.name === c.name)
|
|
311
|
+
.length !== 1
|
|
312
|
+
)
|
|
313
|
+
continue;
|
|
314
|
+
const decision = await selectDiscovery(w.laya, {
|
|
315
|
+
title: `展开「${c.name}」查看隐藏控件,再收起恢复`,
|
|
316
|
+
evidence: `${tab.name}面板内唯一可见可用的 button「${c.name}」,aria-expanded=false;验证目标为展开状态变为 true 并出现新控件,再恢复为 false;不提交表单或修改记录`,
|
|
317
|
+
});
|
|
318
|
+
if (decision.selected)
|
|
319
|
+
await inspectDisclosure(w, {
|
|
320
|
+
kind: 'assert-disclosure',
|
|
321
|
+
target: { role: 'button', name: c.name, tab: tab.name },
|
|
322
|
+
});
|
|
323
|
+
else {
|
|
324
|
+
const gap = w.coverage.gaps.find(
|
|
325
|
+
(g) => g.state === `详情 / ${tab.name}` && g.name === c.name,
|
|
326
|
+
);
|
|
327
|
+
if (gap) gap.reason = '模型未选择展开检查;保留为未验证,不强行点击或计入通过';
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
w.completeCase(result);
|
|
332
|
+
if (w.restorationFailure) throw Error(w.restorationFailure);
|
|
333
|
+
if (result.status !== '已验证') break;
|
|
334
|
+
await exploreRelatedRecords(w, tab, index);
|
|
335
|
+
// New page states may reveal more tabs. Re-observe after every verified
|
|
336
|
+
// transition instead of declaring coverage from the entry snapshot.
|
|
337
|
+
const next = await w.snapshot();
|
|
338
|
+
for (const c of next.controls.filter((c) => c.role === 'tab' && c.name && !c.disabled)) {
|
|
339
|
+
if (
|
|
340
|
+
!seen.has(c.name) &&
|
|
341
|
+
!queue.some((t) => t.name === c.name) &&
|
|
342
|
+
next.controls.filter((t) => t.role === 'tab' && t.name === c.name).length === 1 &&
|
|
343
|
+
(await group.getByRole('tab', { name: c.name, exact: true }).count()) === 1
|
|
344
|
+
)
|
|
345
|
+
queue.push(c);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (queue.length > 12)
|
|
349
|
+
w.coverage.gaps.push({
|
|
350
|
+
state: '详情',
|
|
351
|
+
role: 'tablist',
|
|
352
|
+
name: '其余页签',
|
|
353
|
+
reason: `达到 12 个页签预算,剩余 ${queue.length - 12} 个未探索`,
|
|
354
|
+
});
|
|
355
|
+
if (changed) {
|
|
356
|
+
const result = await w.runCase(
|
|
357
|
+
'view-return',
|
|
358
|
+
'查询详情:恢复初始页签',
|
|
359
|
+
'view',
|
|
360
|
+
async () => {
|
|
361
|
+
await w.clickTab(original.name);
|
|
362
|
+
await assertTabPanel(w, {
|
|
363
|
+
kind: 'assert-tab-panel',
|
|
364
|
+
target: { role: 'tab', name: original.name },
|
|
365
|
+
});
|
|
366
|
+
},
|
|
367
|
+
);
|
|
368
|
+
w.completeCase(result);
|
|
369
|
+
if (result.status !== '已验证') throw Error('详情页签恢复失败,停止后续写操作');
|
|
370
|
+
}
|
|
371
|
+
activity(w, '');
|
|
372
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { waitForReady } from './readiness.mjs';
|
|
2
|
+
|
|
3
|
+
// Page continuity is separate from persistence. Never reload the host merely to
|
|
4
|
+
// clear a child application's form/filter, or mistake a remount for a fresh read.
|
|
5
|
+
export async function pageIdentity(page) {
|
|
6
|
+
const apps = await page.locator('[data-laya-app]').evaluateAll((roots) =>
|
|
7
|
+
roots
|
|
8
|
+
.filter((root) => root.getAttribute('data-laya-active') === 'true')
|
|
9
|
+
.map((root) => ({
|
|
10
|
+
app: root.getAttribute('data-laya-app'),
|
|
11
|
+
instance: root.getAttribute('data-laya-instance'),
|
|
12
|
+
})),
|
|
13
|
+
);
|
|
14
|
+
if (apps.length > 1 || (apps.length === 1 && (!apps[0].app || !apps[0].instance)))
|
|
15
|
+
throw Error('无法确定唯一的当前子应用实例');
|
|
16
|
+
return {
|
|
17
|
+
url: page.url(),
|
|
18
|
+
host: (await page.locator('[data-laya-host],[data-laya-app]').count()) > 0,
|
|
19
|
+
app: apps[0]?.app ?? null,
|
|
20
|
+
instance: apps[0]?.instance ?? null,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function assertPageIdentity(page, expected, { fresh = false } = {}) {
|
|
25
|
+
const current = await pageIdentity(page);
|
|
26
|
+
if (
|
|
27
|
+
current.url !== expected.url ||
|
|
28
|
+
current.host !== expected.host ||
|
|
29
|
+
current.app !== expected.app ||
|
|
30
|
+
(!fresh && current.instance !== expected.instance)
|
|
31
|
+
)
|
|
32
|
+
throw Error('页面路由或子应用实例已变化;停止操作,不刷新主应用或切换其他标签');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function captureVerificationAuth(page, config) {
|
|
36
|
+
// Capture BEFORE any test mutation. Copying storage after a write could copy
|
|
37
|
+
// optimistic business caches and falsely make an unpersisted record pass.
|
|
38
|
+
return {
|
|
39
|
+
origin: new URL(config.url).origin,
|
|
40
|
+
storageState: await page.context().storageState({ indexedDB: true }),
|
|
41
|
+
...(config.authSessionStorage
|
|
42
|
+
? {
|
|
43
|
+
sessionStorage: await page.evaluate(() =>
|
|
44
|
+
Object.fromEntries(
|
|
45
|
+
Object.entries(sessionStorage).filter(
|
|
46
|
+
([key]) => key !== '__laya_auth_restored__',
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
),
|
|
50
|
+
}
|
|
51
|
+
: {}),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function activity(w, message) {
|
|
56
|
+
w.journal?.checkpoint({ activity: message });
|
|
57
|
+
if (message) console.log(message);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Visible runs need time to observe a completed interaction before the next
|
|
61
|
+
// action replaces it. DOM reads and headless persistence checks never wait here.
|
|
62
|
+
export async function waitForVisibleStep(w) {
|
|
63
|
+
if (w.config?.headless !== false) return;
|
|
64
|
+
w.checkInterrupted?.();
|
|
65
|
+
// Observe a stable, non-loading UI before advancing. A fixed sleep alone
|
|
66
|
+
// can expire halfway through an asynchronous panel replacement.
|
|
67
|
+
await waitForReady(w.page, { minimum: 650, timeout: w.config.pageTimeout || 8000 });
|
|
68
|
+
w.checkInterrupted?.();
|
|
69
|
+
}
|