@testmuai/playwright-bindings 0.1.53-beta.1 → 0.1.53-beta.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.
|
@@ -1,29 +1,45 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* V4 JS-dialog handling — one-shot answers armed before the trigger.
|
|
3
3
|
*
|
|
4
|
-
* Playwright auto-dismisses a JavaScript dialog (alert / confirm / prompt
|
|
5
|
-
* unless a `
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* post-hoc order), so a Selenium-style `switch_to.alert` is impossible here:
|
|
9
|
-
* by the time the JS_DIALOG op runs the dialog is already gone.
|
|
4
|
+
* Playwright auto-dismisses a JavaScript dialog (alert / confirm / prompt /
|
|
5
|
+
* beforeunload) unless a `dialog` listener exists BEFORE the action that opens
|
|
6
|
+
* it, and while a dialog is open every page call blocks. So the answer is
|
|
7
|
+
* decided up front and given the instant the dialog opens:
|
|
10
8
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
9
|
+
* - One listener per browser context, so tabs and popups opened later are
|
|
10
|
+
* covered and Playwright's auto-dismiss is off everywhere.
|
|
11
|
+
* - `primeDialog` arms a one-shot answer in a FIFO per context and returns its
|
|
12
|
+
* id. When a dialog opens, the earliest armed entry that fits its type
|
|
13
|
+
* (`expect`; `*` fits any type but beforeunload) answers it and is removed
|
|
14
|
+
* unless `repeat`; an entry for a dialog that never opened therefore never
|
|
15
|
+
* blocks a later one of another type. No fitting entry: the type default,
|
|
16
|
+
* alert accept, confirm dismiss, prompt dismiss, beforeunload accept
|
|
17
|
+
* (Playwright's own outcome).
|
|
18
|
+
* - An answer that fails (another listener took the dialog, the page closed)
|
|
19
|
+
* was not given: its one-shot entry is re-armed.
|
|
20
|
+
*
|
|
21
|
+
* Same behaviour as the Python binding's `prime_dialog`.
|
|
14
22
|
*/
|
|
15
23
|
import type { Page } from 'playwright';
|
|
16
24
|
/**
|
|
17
|
-
* Arm
|
|
25
|
+
* Arm a one-shot answer for the next fitting JS dialog of `page`'s context;
|
|
26
|
+
* returns the entry's id.
|
|
18
27
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
28
|
+
* - `action`: `'accept'` or `'dismiss'` (case-insensitive; default dismiss).
|
|
29
|
+
* - `value`: text typed into a prompt when accepting (`''` submits an empty
|
|
30
|
+
* answer); `{{var}}` / `${var}` resolve when the dialog opens.
|
|
31
|
+
* Omitted / `null` uses the prompt's own default value.
|
|
32
|
+
* - `expect`: dialog type the answer is for (`alert`, `confirm`, `prompt`,
|
|
33
|
+
* `beforeunload`); omitted or `'*'` fits any type but beforeunload.
|
|
34
|
+
* - `repeat`: keep the entry armed after it is used.
|
|
21
35
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
36
|
+
* Entries are tried in arming order; the first that fits the dialog's type
|
|
37
|
+
* answers it. A dialog no entry fits gets the type default.
|
|
24
38
|
*/
|
|
25
39
|
export declare function primeDialog(page: Page, opts?: {
|
|
26
40
|
action?: string;
|
|
27
|
-
value?: string;
|
|
28
|
-
|
|
41
|
+
value?: string | null;
|
|
42
|
+
expect?: string | null;
|
|
43
|
+
repeat?: boolean;
|
|
44
|
+
}): Promise<number>;
|
|
29
45
|
//# sourceMappingURL=dialog.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../../../src/v4/helpers/dialog.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../../../src/v4/helpers/dialog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAA0B,IAAI,EAAE,MAAM,YAAY,CAAC;AA0G/D;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,IAAI,EACV,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAC9F,OAAO,CAAC,MAAM,CAAC,CAejB"}
|
|
@@ -1,35 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
1
|
+
import { log } from '../../log.js';
|
|
2
|
+
import { resolveVar } from '../vars.js';
|
|
3
|
+
// Answer for a dialog no armed entry fits.
|
|
4
|
+
const TYPE_DEFAULTS = {
|
|
5
|
+
alert: 'accept',
|
|
6
|
+
confirm: 'dismiss',
|
|
7
|
+
prompt: 'dismiss',
|
|
8
|
+
beforeunload: 'accept',
|
|
9
|
+
};
|
|
10
|
+
const PURE_TEMPLATE = /^(?:\{\{[^{}]+\}\}|\$\{[^{}]+\})$/;
|
|
11
|
+
// Keyed weakly by BrowserContext so a closed context evicts itself.
|
|
12
|
+
const contexts = new WeakMap();
|
|
13
|
+
function state(page) {
|
|
14
|
+
const context = page.context();
|
|
15
|
+
let s = contexts.get(context);
|
|
16
|
+
if (!s) {
|
|
17
|
+
const created = { armed: [], nextId: 0 };
|
|
18
|
+
contexts.set(context, created);
|
|
19
|
+
context.on('dialog', (dialog) => {
|
|
20
|
+
// The listener is sync; the answer is async. Never let it reject unhandled:
|
|
21
|
+
// that kills the Node process before the LT status is reported.
|
|
22
|
+
void onDialog(created, dialog).catch(() => { });
|
|
23
|
+
});
|
|
24
|
+
s = created;
|
|
25
|
+
}
|
|
26
|
+
return s;
|
|
27
|
+
}
|
|
28
|
+
function fits(entry, dialogType) {
|
|
29
|
+
// A wildcard never answers beforeunload: a dismiss would cancel the navigation.
|
|
30
|
+
if (entry.expect === '*')
|
|
31
|
+
return dialogType !== 'beforeunload';
|
|
32
|
+
return entry.expect === dialogType;
|
|
33
|
+
}
|
|
34
|
+
async function onDialog(s, dialog) {
|
|
35
|
+
const dialogType = dialog.type();
|
|
36
|
+
const entry = s.armed.find((e) => fits(e, dialogType));
|
|
37
|
+
let used;
|
|
38
|
+
if (entry && !entry.repeat) {
|
|
39
|
+
s.armed.splice(s.armed.indexOf(entry), 1);
|
|
40
|
+
used = entry;
|
|
41
|
+
}
|
|
42
|
+
const action = entry ? entry.action : (TYPE_DEFAULTS[dialogType] ?? 'dismiss');
|
|
43
|
+
log.helper(` [primeDialog] ${action}: type=${dialogType} message=${JSON.stringify(dialog.message())} `
|
|
44
|
+
+ `source=${entry ? 'armed' : 'default'}`);
|
|
45
|
+
try {
|
|
46
|
+
if (action === 'accept' && dialogType === 'prompt') {
|
|
47
|
+
const value = entry?.value == null ? dialog.defaultValue() : await resolveValue(entry.value);
|
|
48
|
+
await dialog.accept(value);
|
|
49
|
+
}
|
|
50
|
+
else if (action === 'accept') {
|
|
51
|
+
await dialog.accept();
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
await dialog.dismiss();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
log.warn(`[v4] JS dialog answer failed: ${err.message}`);
|
|
59
|
+
if (used) {
|
|
60
|
+
s.armed.push(used);
|
|
61
|
+
s.armed.sort((a, b) => a.id - b.id);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
5
65
|
/**
|
|
6
|
-
*
|
|
66
|
+
* Resolve a prompt answer's variable references as the dialog opens. A pure
|
|
67
|
+
* reference with no value is typed as written, so a missing variable shows
|
|
68
|
+
* instead of submitting an empty answer.
|
|
69
|
+
*/
|
|
70
|
+
async function resolveValue(value) {
|
|
71
|
+
if (!value.includes('{{') && !value.includes('${'))
|
|
72
|
+
return value;
|
|
73
|
+
let resolved;
|
|
74
|
+
try {
|
|
75
|
+
resolved = await resolveVar(value);
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
log.warn(`[v4] JS dialog prompt text not resolved: ${err.message}`);
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
if ((resolved == null || resolved === '') && PURE_TEMPLATE.test(value)) {
|
|
82
|
+
log.warn(`[v4] JS dialog prompt text ${value} has no value; typed as written`);
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
return String(resolved);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Arm a one-shot answer for the next fitting JS dialog of `page`'s context;
|
|
89
|
+
* returns the entry's id.
|
|
7
90
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
91
|
+
* - `action`: `'accept'` or `'dismiss'` (case-insensitive; default dismiss).
|
|
92
|
+
* - `value`: text typed into a prompt when accepting (`''` submits an empty
|
|
93
|
+
* answer); `{{var}}` / `${var}` resolve when the dialog opens.
|
|
94
|
+
* Omitted / `null` uses the prompt's own default value.
|
|
95
|
+
* - `expect`: dialog type the answer is for (`alert`, `confirm`, `prompt`,
|
|
96
|
+
* `beforeunload`); omitted or `'*'` fits any type but beforeunload.
|
|
97
|
+
* - `repeat`: keep the entry armed after it is used.
|
|
10
98
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
99
|
+
* Entries are tried in arming order; the first that fits the dialog's type
|
|
100
|
+
* answers it. A dialog no entry fits gets the type default.
|
|
13
101
|
*/
|
|
14
102
|
export async function primeDialog(page, opts = {}) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
: dialog.dismiss();
|
|
28
|
-
// The listener is sync but accept()/dismiss() are async. Swallow rejection
|
|
29
|
-
// rather than let it float: an unhandled rejection kills the Node process
|
|
30
|
-
// before the LT status is reported, surfacing as "completed" on the grid.
|
|
31
|
-
void settled.catch(() => { });
|
|
103
|
+
const action = (opts.action || 'dismiss').trim().toLowerCase();
|
|
104
|
+
if (action !== 'accept' && action !== 'dismiss') {
|
|
105
|
+
throw new Error(`primeDialog action must be 'accept' or 'dismiss', got ${JSON.stringify(opts.action)}`);
|
|
106
|
+
}
|
|
107
|
+
const s = state(page);
|
|
108
|
+
s.nextId += 1;
|
|
109
|
+
s.armed.push({
|
|
110
|
+
id: s.nextId,
|
|
111
|
+
action,
|
|
112
|
+
value: opts.value ?? null,
|
|
113
|
+
expect: (opts.expect || '*').trim().toLowerCase(),
|
|
114
|
+
repeat: Boolean(opts.repeat),
|
|
32
115
|
});
|
|
33
|
-
|
|
116
|
+
return s.nextId;
|
|
34
117
|
}
|
|
35
118
|
//# sourceMappingURL=dialog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["../../../src/v4/helpers/dialog.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["../../../src/v4/helpers/dialog.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAiBxC,2CAA2C;AAC3C,MAAM,aAAa,GAA2B;IAC5C,KAAK,EAAE,QAAQ;IACf,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,SAAS;IACjB,YAAY,EAAE,QAAQ;CACvB,CAAC;AAEF,MAAM,aAAa,GAAG,mCAAmC,CAAC;AAE1D,oEAAoE;AACpE,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAkC,CAAC;AAE/D,SAAS,KAAK,CAAC,IAAU;IACvB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC/B,IAAI,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9B,IAAI,CAAC,CAAC,EAAE,CAAC;QACP,MAAM,OAAO,GAAmB,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;QACzD,QAAQ,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