@testmuai/playwright-bindings 0.1.52 → 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.
- package/README.md +1 -0
- package/dist/v4/helpers/dialog.d.ts +33 -17
- package/dist/v4/helpers/dialog.d.ts.map +1 -1
- package/dist/v4/helpers/dialog.js +110 -27
- package/dist/v4/helpers/dialog.js.map +1 -1
- package/dist/v4/helpers/smartui.d.ts +23 -3
- package/dist/v4/helpers/smartui.d.ts.map +1 -1
- package/dist/v4/helpers/smartui.js +21 -39
- package/dist/v4/helpers/smartui.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -70,6 +70,7 @@ files never breaks consumers.
|
|
|
70
70
|
| `LT_USERNAME`, `LT_ACCESS_KEY` | LambdaTest credentials (enables ATMS + vision) |
|
|
71
71
|
| `TESTMU_SMART` | `1` enables vision/heal (validated at run() — requires LT creds) |
|
|
72
72
|
| `TESTMU_READ_SETTLE_MS` | Re-read budget for a recorded read whose answer differs from its expected answer (ms, default 15000, max 30000) |
|
|
73
|
+
| `SMARTUI_SERVER_ADDRESS` | SmartUI server `smartuiSnapshot` captures through (default `http://localhost:49152`, the server `npx smartui exec:start` runs). With no server answering, the snapshot is skipped; a SmartUI error is logged and never fails the step (v4) |
|
|
73
74
|
|
|
74
75
|
## Build
|
|
75
76
|
|
|
@@ -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":"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ACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAU,EACV,OAA6F,EAAE;IAE/F,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC/D,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,yDAAyD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC1G,CAAC;IACD,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC;IACd,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;QACX,EAAE,EAAE,CAAC,CAAC,MAAM;QACZ,MAAM;QACN,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI;QACzB,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE;QACjD,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;KAC7B,CAAC,CAAC;IACH,OAAO,CAAC,CAAC,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
import type { Page } from 'playwright';
|
|
2
|
-
type
|
|
3
|
-
|
|
2
|
+
type SdkUtils = {
|
|
3
|
+
isSmartUIRunning(): Promise<boolean>;
|
|
4
|
+
fetchDOMSerializer(): Promise<{
|
|
5
|
+
body: {
|
|
6
|
+
data: {
|
|
7
|
+
dom: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
}>;
|
|
11
|
+
postSnapshot(snapshot: {
|
|
12
|
+
dom: unknown;
|
|
13
|
+
url: string;
|
|
14
|
+
name: string;
|
|
15
|
+
options: Record<string, unknown>;
|
|
16
|
+
}, testType: string): Promise<{
|
|
17
|
+
body?: {
|
|
18
|
+
data?: {
|
|
19
|
+
warnings?: string[];
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
24
|
+
export declare function _resolveSdkUtils(mod: unknown): SdkUtils;
|
|
4
25
|
/** Test hook: forget the cached session id. */
|
|
5
26
|
export declare function _resetSessionId(): void;
|
|
6
|
-
export declare function _isModuleNotFound(e: unknown): boolean;
|
|
7
27
|
export declare function smartuiSnapshot(page: Page, name: string, options?: Record<string, unknown>): Promise<void>;
|
|
8
28
|
export {};
|
|
9
29
|
//# sourceMappingURL=smartui.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smartui.d.ts","sourceRoot":"","sources":["../../../src/v4/helpers/smartui.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"smartui.d.ts","sourceRoot":"","sources":["../../../src/v4/helpers/smartui.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAMvC,KAAK,QAAQ,GAAG;IACd,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC,kBAAkB,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE;YAAE,IAAI,EAAE;gBAAE,GAAG,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAC,CAAC;IACnE,YAAY,CACV,QAAQ,EAAE;QAAE,GAAG,EAAE,OAAO,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,EACvF,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE;gBAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAC,CAAC;CAC3D,CAAC;AAGF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,QAAQ,CAIvD;AAoBD,+CAA+C;AAC/C,wBAAgB,eAAe,IAAI,IAAI,CAEtC;AAED,wBAAsB,eAAe,CACnC,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACpC,OAAO,CAAC,IAAI,CAAC,CAyBf"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { config } from '../../config.js';
|
|
2
1
|
import { log } from '../../log.js';
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
// The driver's testType, which the SmartUI server records for the snapshot.
|
|
3
|
+
const TEST_TYPE = 'js-playwright-driver';
|
|
4
|
+
// exported for unit testing — pure function, no module side effects
|
|
5
|
+
export function _resolveSdkUtils(mod) {
|
|
6
|
+
// CJS in Node ESM can surface as either top-level named exports or .default
|
|
6
7
|
const m = mod;
|
|
7
|
-
|
|
8
|
-
return m.smartuiSnapshot;
|
|
9
|
-
if (typeof m?.default?.smartuiSnapshot === 'function')
|
|
10
|
-
return m.default.smartuiSnapshot;
|
|
11
|
-
return null;
|
|
8
|
+
return (typeof m?.isSmartUIRunning === 'function' ? m : m.default);
|
|
12
9
|
}
|
|
13
10
|
// The grid session's id, looked up once per process.
|
|
14
11
|
let ltSessionId;
|
|
@@ -31,43 +28,28 @@ async function sessionId(page) {
|
|
|
31
28
|
export function _resetSessionId() {
|
|
32
29
|
ltSessionId = undefined;
|
|
33
30
|
}
|
|
34
|
-
export function _isModuleNotFound(e) {
|
|
35
|
-
const code = e?.code;
|
|
36
|
-
return code === 'ERR_MODULE_NOT_FOUND' || code === 'MODULE_NOT_FOUND';
|
|
37
|
-
}
|
|
38
31
|
export async function smartuiSnapshot(page, name, options = {}) {
|
|
32
|
+
const utils = _resolveSdkUtils(await import('@lambdatest/sdk-utils'));
|
|
39
33
|
log.helper(`[smartui_snapshot] name=${name}`);
|
|
40
|
-
if (
|
|
41
|
-
log.helper(`[smartui_snapshot]
|
|
34
|
+
if (!(await utils.isSmartUIRunning())) {
|
|
35
|
+
log.helper(`[smartui_snapshot] no SmartUI server — skipping name=${name}`);
|
|
42
36
|
return;
|
|
43
37
|
}
|
|
44
|
-
let mod;
|
|
45
38
|
try {
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
// The session id links the snapshot to the session in the Automation
|
|
40
|
+
// dashboard; the Selenium SDK sends driver.session_id the same way.
|
|
41
|
+
if (!options['sessionId']) {
|
|
42
|
+
const id = await sessionId(page);
|
|
43
|
+
if (id)
|
|
44
|
+
options = { ...options, sessionId: id };
|
|
52
45
|
}
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
const serializer = await utils.fetchDOMSerializer();
|
|
47
|
+
await page.evaluate(serializer.body.data.dom);
|
|
48
|
+
const dom = await page.evaluate('SmartUIDOM.serialize({})');
|
|
49
|
+
const { body } = await utils.postSnapshot({ dom, url: page.url(), name, options }, TEST_TYPE);
|
|
50
|
+
for (const warning of body?.data?.warnings ?? []) {
|
|
51
|
+
log.helper(`[smartui_snapshot] ${warning}`);
|
|
55
52
|
}
|
|
56
|
-
throw e;
|
|
57
|
-
}
|
|
58
|
-
const snapshotFn = _resolveSdkFn(mod);
|
|
59
|
-
if (!snapshotFn) {
|
|
60
|
-
throw new Error('[smartui_snapshot] SDK loaded but smartuiSnapshot export not found');
|
|
61
|
-
}
|
|
62
|
-
// The session id links the snapshot to the session in the Automation
|
|
63
|
-
// dashboard; the Selenium SDK sends driver.session_id the same way.
|
|
64
|
-
if (!options['sessionId']) {
|
|
65
|
-
const id = await sessionId(page);
|
|
66
|
-
if (id)
|
|
67
|
-
options = { ...options, sessionId: id };
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
await snapshotFn(page, name, options);
|
|
71
53
|
log.helper(`[smartui_snapshot] captured name=${name}`);
|
|
72
54
|
}
|
|
73
55
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smartui.js","sourceRoot":"","sources":["../../../src/v4/helpers/smartui.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"smartui.js","sourceRoot":"","sources":["../../../src/v4/helpers/smartui.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,4EAA4E;AAC5E,MAAM,SAAS,GAAG,sBAAsB,CAAC;AAWzC,oEAAoE;AACpE,MAAM,UAAU,gBAAgB,CAAC,GAAY;IAC3C,4EAA4E;IAC5E,MAAM,CAAC,GAAG,GAAiD,CAAC;IAC5D,OAAO,CAAC,OAAO,CAAC,EAAE,gBAAgB,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAa,CAAC;AACjF,CAAC;AAED,qDAAqD;AACrD,IAAI,WAAsC,CAAC;AAE3C,oFAAoF;AACpF,KAAK,UAAU,SAAS,CAAC,IAAU;IACjC,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,iDAAiD,CAAC,CAAC;YACjG,MAAM,IAAI,GAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAwC,CAAC,IAAI,CAAC;YACtF,WAAW,GAAG,IAAI,EAAE,UAAU,IAAI,IAAI,CAAC;QACzC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,GAAG,CAAC,MAAM,CAAC,qDAAqD,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC7E,WAAW,GAAG,IAAI,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,+CAA+C;AAC/C,MAAM,U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B,OAAO,EAAE,CAAC,CAAC;QAC9C,CAAC;QACD,GAAG,CAAC,MAAM,CAAC,oCAAoC,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,GAAG,CAAC,MAAM,CAAC,8BAA8B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACxD,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testmuai/playwright-bindings",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.53-beta.2",
|
|
4
4
|
"description": "Testmu binding for Playwright — thin runtime for LambdaTest exports",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"playwright": ">=1.57.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
+
"@lambdatest/sdk-utils": "^1.0.8",
|
|
46
47
|
"ajv": "^8.17.1",
|
|
47
48
|
"aws4": "^1.13.2",
|
|
48
49
|
"dotenv": "^17.4.2",
|