@mobilewright/core 0.0.70 → 0.0.72
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/dist/expect.d.ts +4 -1
- package/dist/expect.d.ts.map +1 -1
- package/dist/expect.js +26 -16
- package/dist/expect.js.map +1 -1
- package/dist/expect.test.js +47 -0
- package/dist/expect.test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/locator.d.ts +13 -3
- package/dist/locator.d.ts.map +1 -1
- package/dist/locator.js +18 -2
- package/dist/locator.js.map +1 -1
- package/dist/locator.test.js +22 -0
- package/dist/locator.test.js.map +1 -1
- package/dist/page.d.ts +4 -1
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +11 -0
- package/dist/page.js.map +1 -1
- package/dist/playwright-engine.d.ts +25 -0
- package/dist/playwright-engine.d.ts.map +1 -1
- package/dist/playwright-engine.js +107 -14
- package/dist/playwright-engine.js.map +1 -1
- package/dist/stackTrace.d.ts +1 -0
- package/dist/stackTrace.d.ts.map +1 -1
- package/dist/stackTrace.js +5 -0
- package/dist/stackTrace.js.map +1 -1
- package/dist/web-expect-matcher.d.ts.map +1 -1
- package/dist/web-expect-matcher.js +14 -7
- package/dist/web-expect-matcher.js.map +1 -1
- package/dist/web-frame-locator.test.d.ts +2 -0
- package/dist/web-frame-locator.test.d.ts.map +1 -0
- package/dist/web-frame-locator.test.js +221 -0
- package/dist/web-frame-locator.test.js.map +1 -0
- package/dist/web-locator-native-input.test.d.ts +2 -0
- package/dist/web-locator-native-input.test.d.ts.map +1 -0
- package/dist/web-locator-native-input.test.js +177 -0
- package/dist/web-locator-native-input.test.js.map +1 -0
- package/dist/web-locator.d.ts +53 -5
- package/dist/web-locator.d.ts.map +1 -1
- package/dist/web-locator.js +182 -16
- package/dist/web-locator.js.map +1 -1
- package/dist/web-locator.test.js +17 -0
- package/dist/web-locator.test.js.map +1 -1
- package/dist/webview-locator.d.ts.map +1 -1
- package/dist/webview-locator.js +6 -0
- package/dist/webview-locator.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { test, expect as playwrightExpect } from '@playwright/test';
|
|
2
|
+
import { Page } from './page.js';
|
|
3
|
+
import { WebLocator, SCREEN_POINT_BODY } from './web-locator.js';
|
|
4
|
+
import { WebViewLocator } from './webview-locator.js';
|
|
5
|
+
import { fakeWebViewSession } from './fake-webview-session.js';
|
|
6
|
+
function fakeField(opts = {}) {
|
|
7
|
+
const events = [];
|
|
8
|
+
let taps = 0;
|
|
9
|
+
const { session, evaluateCalls } = fakeWebViewSession();
|
|
10
|
+
session.evaluate = async (expr) => {
|
|
11
|
+
evaluateCalls.push(expr);
|
|
12
|
+
if (expr.includes('getBoundingClientRect')) {
|
|
13
|
+
return { x: 10, y: 20, viewportWidth: opts.viewportWidth ?? 400 };
|
|
14
|
+
}
|
|
15
|
+
if (expr.includes('ownerDocument.activeElement')) {
|
|
16
|
+
return (taps >= (opts.focusAfterTaps ?? 1));
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
const page = new Page(session);
|
|
21
|
+
page._nativeInput = {
|
|
22
|
+
bounds: async () => ({ x: 0, y: 100, width: 800, height: 1600 }),
|
|
23
|
+
tap: async (x, y) => { taps++; events.push(`tap ${x},${y}`); },
|
|
24
|
+
typeText: async (text) => { events.push(`type ${text}`); },
|
|
25
|
+
};
|
|
26
|
+
return { page, events, evaluateCalls };
|
|
27
|
+
}
|
|
28
|
+
const taps = (events) => events.filter((e) => e.startsWith('tap ')).length;
|
|
29
|
+
const typedKeys = (events) => events.filter((e) => e.startsWith('type ')).map((e) => e.slice('type '.length));
|
|
30
|
+
// ─── tap() ────────────────────────────────────────────────────
|
|
31
|
+
test.describe('MobileWebViewLocator.tap()', () => {
|
|
32
|
+
test('taps natively at the element center, mapped onto the webview bounds', async () => {
|
|
33
|
+
const { page, events } = fakeField();
|
|
34
|
+
await page.locator('button').tap();
|
|
35
|
+
// scale = 800 native / 400 CSS px wide = 2 → (10 * 2, 100 + 20 * 2)
|
|
36
|
+
playwrightExpect(events).toEqual(['tap 20,140']);
|
|
37
|
+
});
|
|
38
|
+
test('fails clearly instead of tapping a bogus point when the webview has no width', async () => {
|
|
39
|
+
const { page, events } = fakeField({ viewportWidth: 0 });
|
|
40
|
+
await playwrightExpect(page.locator('button').tap()).rejects.toThrow(/no valid on-screen size/);
|
|
41
|
+
playwrightExpect(events).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
test('waits until the element is visible, enabled and stable', async () => {
|
|
44
|
+
const { page, evaluateCalls } = fakeField();
|
|
45
|
+
await page.locator('button').tap();
|
|
46
|
+
playwrightExpect(evaluateCalls[0]).toContain('checkElementStates(el, ["visible","enabled","stable"])');
|
|
47
|
+
});
|
|
48
|
+
test('without device input it fails clearly instead of faking a click', async () => {
|
|
49
|
+
const { session } = fakeWebViewSession({ evaluateAlways: true });
|
|
50
|
+
await playwrightExpect(new WebLocator(session, 'button').tap()).rejects.toThrow(/locator\.tap\(\): needs the page from screen\.getByWebView\(\)\.page\(\)/);
|
|
51
|
+
});
|
|
52
|
+
test('device input carries over into iframe locators', async () => {
|
|
53
|
+
const { page, events } = fakeField();
|
|
54
|
+
await page.frameLocator('#app').getByRole('button').tap();
|
|
55
|
+
playwrightExpect(taps(events)).toBe(1);
|
|
56
|
+
});
|
|
57
|
+
test('device input carries over to chained and derived locators', async () => {
|
|
58
|
+
const { page, events } = fakeField();
|
|
59
|
+
await page.locator('form').getByRole('button').first().tap();
|
|
60
|
+
playwrightExpect(taps(events)).toBe(1);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
// Run the screen-point script for `el` with `top` as the top window.
|
|
64
|
+
function screenPoint(el, top) {
|
|
65
|
+
return new Function('window', 'el', SCREEN_POINT_BODY)(top, el);
|
|
66
|
+
}
|
|
67
|
+
function element(rect, win) {
|
|
68
|
+
const el = {
|
|
69
|
+
scrolled: false,
|
|
70
|
+
scrollIntoView: () => { el.scrolled = true; },
|
|
71
|
+
getBoundingClientRect: () => rect,
|
|
72
|
+
ownerDocument: { defaultView: win },
|
|
73
|
+
};
|
|
74
|
+
return el;
|
|
75
|
+
}
|
|
76
|
+
// An <iframe> element at `rect` with a `border` px border, inside `parent`.
|
|
77
|
+
function iframeIn(parent, rect, border) {
|
|
78
|
+
const frameElement = { getBoundingClientRect: () => rect, clientLeft: border, clientTop: border };
|
|
79
|
+
return { frameElement, parent };
|
|
80
|
+
}
|
|
81
|
+
test.describe('tap() screen point', () => {
|
|
82
|
+
test('is the element center in CSS pixels, after scrolling it into view', () => {
|
|
83
|
+
const top = { innerWidth: 390 };
|
|
84
|
+
const el = element({ left: 100, top: 200, width: 50, height: 20 }, top);
|
|
85
|
+
playwrightExpect(screenPoint(el, top)).toEqual({ x: 125, y: 210, viewportWidth: 390 });
|
|
86
|
+
playwrightExpect(el.scrolled).toBe(true);
|
|
87
|
+
});
|
|
88
|
+
test('adds the offset and border of every iframe the element sits in', () => {
|
|
89
|
+
const top = { innerWidth: 390 };
|
|
90
|
+
const outer = iframeIn(top, { left: 30, top: 120, width: 300, height: 400 }, 7);
|
|
91
|
+
const inner = iframeIn(outer, { left: 5, top: 10, width: 200, height: 200 }, 1);
|
|
92
|
+
const el = element({ left: 100, top: 200, width: 50, height: 20 }, inner);
|
|
93
|
+
// x: 125 + (5 + 1) + (30 + 7) = 168; y: 210 + (10 + 1) + (120 + 7) = 348
|
|
94
|
+
playwrightExpect(screenPoint(el, top)).toEqual({ x: 168, y: 348, viewportWidth: 390 });
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
// ─── fill() ───────────────────────────────────────────────────
|
|
98
|
+
test.describe('MobileWebViewLocator.fill()', () => {
|
|
99
|
+
test('sets the value in-page without tapping or typing, even with device input', async () => {
|
|
100
|
+
const { page, events, evaluateCalls } = fakeField();
|
|
101
|
+
await page.locator('input').fill('a@b.c');
|
|
102
|
+
playwrightExpect(events).toEqual([]);
|
|
103
|
+
playwrightExpect(evaluateCalls.some((c) => c.includes('const next = "a@b.c";'))).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
test('clear() empties the field in-page, like fill(\'\')', async () => {
|
|
106
|
+
const { page, events, evaluateCalls } = fakeField();
|
|
107
|
+
await page.locator('input').clear();
|
|
108
|
+
playwrightExpect(events).toEqual([]);
|
|
109
|
+
playwrightExpect(evaluateCalls.some((c) => c.includes('const next = "";'))).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
test('without device input sets the value in-page', async () => {
|
|
112
|
+
const { session, evaluateCalls } = fakeWebViewSession({ evaluateAlways: true });
|
|
113
|
+
await new WebLocator(session, 'input').fill('x1');
|
|
114
|
+
playwrightExpect(evaluateCalls.some((c) => c.includes('const next = "x1";'))).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
// ─── pressSequentially() ──────────────────────────────────────
|
|
118
|
+
test.describe('MobileWebViewLocator.pressSequentially()', () => {
|
|
119
|
+
test('taps the field, then sends the keys one by one through the device keyboard', async () => {
|
|
120
|
+
const { page, events, evaluateCalls } = fakeField();
|
|
121
|
+
await page.locator('input').pressSequentially('a@b');
|
|
122
|
+
playwrightExpect(events).toEqual(['tap 20,140', 'type a', 'type @', 'type b']);
|
|
123
|
+
playwrightExpect(evaluateCalls.some((c) => c.includes('a@b'))).toBe(false);
|
|
124
|
+
});
|
|
125
|
+
test('sends a character outside the basic plane as a single key', async () => {
|
|
126
|
+
const { page, events } = fakeField();
|
|
127
|
+
await page.locator('input').pressSequentially('a😀');
|
|
128
|
+
playwrightExpect(typedKeys(events)).toEqual(['a', '😀']);
|
|
129
|
+
});
|
|
130
|
+
test('taps again when the first tap did not give the field keyboard focus', async () => {
|
|
131
|
+
const { page, events } = fakeField({ focusAfterTaps: 2 });
|
|
132
|
+
await page.locator('input').pressSequentially('ab');
|
|
133
|
+
playwrightExpect(events.map((e) => e.split(' ')[0])).toEqual(['tap', 'tap', 'type', 'type']);
|
|
134
|
+
});
|
|
135
|
+
test('fails without typing when the field never takes keyboard focus', async () => {
|
|
136
|
+
const { page, events } = fakeField({ focusAfterTaps: 99 });
|
|
137
|
+
await playwrightExpect(page.locator('input').pressSequentially('ab')).rejects.toThrow(/did not take keyboard focus/);
|
|
138
|
+
playwrightExpect(typedKeys(events)).toEqual([]);
|
|
139
|
+
});
|
|
140
|
+
test('without device input it fails clearly instead of faking key events', async () => {
|
|
141
|
+
const { session } = fakeWebViewSession({ evaluateAlways: true });
|
|
142
|
+
await playwrightExpect(new WebLocator(session, 'input').pressSequentially('ab')).rejects.toThrow(/needs the page from screen\.getByWebView\(\)\.page\(\)/);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
// ─── Wiring from screen.getByWebView().page() ─────────────────
|
|
146
|
+
test.describe('getByWebView().page() device input', () => {
|
|
147
|
+
test('taps through the driver at the webview\'s live on-screen bounds', async () => {
|
|
148
|
+
const webview = {
|
|
149
|
+
type: 'android.webkit.WebView',
|
|
150
|
+
isVisible: true,
|
|
151
|
+
isEnabled: true,
|
|
152
|
+
bounds: { x: 0, y: 100, width: 800, height: 1600 },
|
|
153
|
+
children: [],
|
|
154
|
+
};
|
|
155
|
+
const driverTaps = [];
|
|
156
|
+
const typed = [];
|
|
157
|
+
let session;
|
|
158
|
+
const driver = {
|
|
159
|
+
getViewHierarchy: async () => [webview],
|
|
160
|
+
tap: async (x, y) => { driverTaps.push([x, y]); },
|
|
161
|
+
typeText: async (text) => { typed.push(text); },
|
|
162
|
+
webViewBridge: {
|
|
163
|
+
listWebViews: async () => [{ id: 'w1', url: 'https://example.com', title: 'Example' }],
|
|
164
|
+
attachWebView: async () => {
|
|
165
|
+
session = fakeWebViewSession({ evaluateAlways: { x: 10, y: 20, viewportWidth: 400 } }).session;
|
|
166
|
+
return session;
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
const page = await new WebViewLocator(driver, { kind: 'webview' }).page();
|
|
171
|
+
await page.locator('button').tap();
|
|
172
|
+
await page._nativeInput.typeText('hi');
|
|
173
|
+
playwrightExpect(driverTaps).toEqual([[20, 140]]);
|
|
174
|
+
playwrightExpect(typed).toEqual(['hi']);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
//# sourceMappingURL=web-locator-native-input.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-locator-native-input.test.js","sourceRoot":"","sources":["../src/web-locator-native-input.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAe/D,SAAS,SAAS,CAAC,OAAyB,EAAE;IAC5C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,kBAAkB,EAAE,CAAC;IACxD,OAAO,CAAC,QAAQ,GAAG,KAAK,EAAK,IAAY,EAAc,EAAE;QACvD,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC,EAAE,CAAC;YAC3C,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,IAAI,GAAG,EAAO,CAAC;QACzE,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,6BAA6B,CAAC,EAAE,CAAC;YACjD,OAAO,CAAC,IAAI,IAAI,CAAC,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AE,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACvD,aAAa,EAAE;gBACb,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,qBAAqB,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;gBACtF,aAAa,EAAE,KAAK,IAAI,EAAE;oBACxB,OAAO,GAAG,kBAAkB,CAAC,EAAE,cAAc,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC;oBAC/F,OAAO,OAAO,CAAC;gBACjB,CAAC;aACF;SAC+B,CAAC;QAEnC,MAAM,IAAI,GAAG,MAAM,IAAI,cAAc,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1E,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC;QACnC,MAAM,IAAI,CAAC,YAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAExC,gBAAgB,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QAClD,gBAAgB,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/web-locator.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import type { Locator } from '@playwright/test';
|
|
1
|
+
import type { Locator, FrameLocator } from '@playwright/test';
|
|
2
2
|
import type { Bounds, WebViewSession } from '@mobilewright/protocol';
|
|
3
|
-
import type { StepFn } from './locator.js';
|
|
3
|
+
import type { FillOptions, StepFn } from './locator.js';
|
|
4
4
|
import { type FrameExpectParams, type ExpectResult, type ExpectedTextValue } from './web-expect-matcher.js';
|
|
5
|
+
export interface WebViewNativeInput {
|
|
6
|
+
bounds(): Promise<Bounds>;
|
|
7
|
+
tap(x: number, y: number): Promise<void>;
|
|
8
|
+
typeText(text: string): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare const SCREEN_POINT_BODY = "if (!el) { return null; }\n el.scrollIntoView({ block: 'center', inline: 'center' });\n const r = el.getBoundingClientRect();\n let x = r.left + r.width / 2;\n let y = r.top + r.height / 2;\n let win = el.ownerDocument.defaultView;\n while (win && win !== window && win.frameElement) {\n const frame = win.frameElement;\n const f = frame.getBoundingClientRect();\n x += f.left + frame.clientLeft;\n y += f.top + frame.clientTop;\n win = win.parent;\n }\n return { x, y, viewportWidth: window.innerWidth };";
|
|
5
11
|
interface PlaywrightExpectOptions {
|
|
6
12
|
isNot?: boolean;
|
|
7
13
|
timeout?: number;
|
|
@@ -20,10 +26,12 @@ export declare class MobileWebViewLocator {
|
|
|
20
26
|
protected readonly selector: string;
|
|
21
27
|
_apiName: string;
|
|
22
28
|
_stepFn: StepFn | null;
|
|
29
|
+
_nativeInput: WebViewNativeInput | null;
|
|
23
30
|
constructor(session: WebViewSession, selector: string);
|
|
24
31
|
private derive;
|
|
25
32
|
private child;
|
|
26
33
|
private _step;
|
|
34
|
+
private scoped;
|
|
27
35
|
private firstEl;
|
|
28
36
|
private firstElExpr;
|
|
29
37
|
private evalEngine;
|
|
@@ -50,6 +58,8 @@ export declare class MobileWebViewLocator {
|
|
|
50
58
|
getByTestId(testId: string): MobileWebViewLocator;
|
|
51
59
|
getByAltText(text: string | RegExp): MobileWebViewLocator;
|
|
52
60
|
getByTitle(text: string | RegExp): MobileWebViewLocator;
|
|
61
|
+
contentFrame(): MobileWebViewFrameLocator;
|
|
62
|
+
frameLocator(selector: string): MobileWebViewFrameLocator;
|
|
53
63
|
first(): MobileWebViewLocator;
|
|
54
64
|
last(): MobileWebViewLocator;
|
|
55
65
|
nth(index: number): MobileWebViewLocator;
|
|
@@ -98,17 +108,26 @@ export declare class MobileWebViewLocator {
|
|
|
98
108
|
state?: 'visible' | 'hidden' | 'attached' | 'detached';
|
|
99
109
|
timeout?: number;
|
|
100
110
|
}): Promise<void>;
|
|
101
|
-
|
|
111
|
+
tap(opts?: {
|
|
102
112
|
timeout?: number;
|
|
103
113
|
}): Promise<void>;
|
|
104
|
-
|
|
114
|
+
click(opts?: {
|
|
105
115
|
timeout?: number;
|
|
106
116
|
}): Promise<void>;
|
|
107
|
-
|
|
117
|
+
fill(text: string, opts?: FillOptions): Promise<void>;
|
|
118
|
+
clear(opts?: FillOptions): Promise<void>;
|
|
119
|
+
pressSequentially(text: string, opts?: FillOptions & {
|
|
120
|
+
delay?: number;
|
|
121
|
+
}): Promise<void>;
|
|
122
|
+
type(text: string, opts?: FillOptions): Promise<void>;
|
|
108
123
|
press(key: string): Promise<void>;
|
|
109
124
|
focus(): Promise<void>;
|
|
110
125
|
hover(): Promise<void>;
|
|
111
126
|
scrollIntoViewIfNeeded(): Promise<void>;
|
|
127
|
+
private requireNativeInput;
|
|
128
|
+
private nativeTap;
|
|
129
|
+
private hasFocus;
|
|
130
|
+
private tapUntilFocused;
|
|
112
131
|
private pollActionable;
|
|
113
132
|
private pollUntilVisible;
|
|
114
133
|
_runInjectedExpect(params: FrameExpectParams): Promise<ExpectResult>;
|
|
@@ -118,4 +137,33 @@ export declare class MobileWebViewLocator {
|
|
|
118
137
|
export interface MobileWebViewLocator extends Locator {
|
|
119
138
|
}
|
|
120
139
|
export { MobileWebViewLocator as WebLocator };
|
|
140
|
+
export declare class MobileWebViewFrameLocator {
|
|
141
|
+
private readonly frameElement;
|
|
142
|
+
private readonly content;
|
|
143
|
+
constructor(frameElement: MobileWebViewLocator, content: MobileWebViewLocator);
|
|
144
|
+
owner(): MobileWebViewLocator;
|
|
145
|
+
locator(selector: string): MobileWebViewLocator;
|
|
146
|
+
getByRole(role: string, opts?: {
|
|
147
|
+
name?: string | RegExp;
|
|
148
|
+
exact?: boolean;
|
|
149
|
+
}): MobileWebViewLocator;
|
|
150
|
+
getByText(text: string | RegExp, opts?: {
|
|
151
|
+
exact?: boolean;
|
|
152
|
+
}): MobileWebViewLocator;
|
|
153
|
+
getByLabel(label: string | RegExp, opts?: {
|
|
154
|
+
exact?: boolean;
|
|
155
|
+
}): MobileWebViewLocator;
|
|
156
|
+
getByPlaceholder(text: string | RegExp, opts?: {
|
|
157
|
+
exact?: boolean;
|
|
158
|
+
}): MobileWebViewLocator;
|
|
159
|
+
getByTestId(testId: string): MobileWebViewLocator;
|
|
160
|
+
getByAltText(text: string | RegExp): MobileWebViewLocator;
|
|
161
|
+
getByTitle(text: string | RegExp): MobileWebViewLocator;
|
|
162
|
+
frameLocator(selector: string): MobileWebViewFrameLocator;
|
|
163
|
+
first(): MobileWebViewFrameLocator;
|
|
164
|
+
last(): MobileWebViewFrameLocator;
|
|
165
|
+
nth(index: number): MobileWebViewFrameLocator;
|
|
166
|
+
}
|
|
167
|
+
export interface MobileWebViewFrameLocator extends FrameLocator {
|
|
168
|
+
}
|
|
121
169
|
//# sourceMappingURL=web-locator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-locator.d.ts","sourceRoot":"","sources":["../src/web-locator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"web-locator.d.ts","sourceRoot":"","sources":["../src/web-locator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAgBxD,OAAO,EAA8C,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAi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AAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,oBAAoB;IAKvD,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,yBAAyB;IAIzD,KAAK,IAAI,yBAAyB;IAIlC,IAAI,IAAI,yBAAyB;IAIjC,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,yBAAyB;CAG9C;AAID,MAAM,WAAW,yBAA0B,SAAQ,YAAY;CAAG"}
|
package/dist/web-locator.js
CHANGED
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import createDebug from 'debug';
|
|
2
2
|
import { retryUntil } from './poll.js';
|
|
3
3
|
import { sleep } from './sleep.js';
|
|
4
|
-
import { runStep } from './stackTrace.js';
|
|
5
|
-
import { getByRoleSelector, getByTextSelector, getByLabelSelector, getByPlaceholderSelector, getByAltTextSelector, getByTitleSelector, getByTestIdSelector, TEST_ID_ATTR, evaluateWithEngine, } from './playwright-engine.js';
|
|
4
|
+
import { runStep, typedTextInTitle } from './stackTrace.js';
|
|
5
|
+
import { getByRoleSelector, getByTextSelector, getByLabelSelector, getByPlaceholderSelector, getByAltTextSelector, getByTitleSelector, getByTestIdSelector, TEST_ID_ATTR, evaluateWithEngine, scopedEngineExpr, } from './playwright-engine.js';
|
|
6
6
|
import { buildExpectEvaluate, missingElementVerdict } from './web-expect-matcher.js';
|
|
7
7
|
const DEFAULT_TIMEOUT = 5_000;
|
|
8
8
|
const EXPECT_POLL_INTERVAL = 100;
|
|
9
|
+
// How long pressSequentially() waits for a tapped field to take keyboard focus, and how often it looks.
|
|
10
|
+
const FOCUS_TIMEOUT = 1_500;
|
|
11
|
+
const FOCUS_POLL_INTERVAL = 150;
|
|
12
|
+
// In-page body (with `el` bound to the element) that scrolls the element into
|
|
13
|
+
// view and returns its center in the top window's CSS pixels — adding the
|
|
14
|
+
// offsets of any iframes it sits in — plus the top window's CSS width, which
|
|
15
|
+
// maps CSS pixels onto the webview's native bounds.
|
|
16
|
+
export const SCREEN_POINT_BODY = `if (!el) { return null; }
|
|
17
|
+
el.scrollIntoView({ block: 'center', inline: 'center' });
|
|
18
|
+
const r = el.getBoundingClientRect();
|
|
19
|
+
let x = r.left + r.width / 2;
|
|
20
|
+
let y = r.top + r.height / 2;
|
|
21
|
+
let win = el.ownerDocument.defaultView;
|
|
22
|
+
while (win && win !== window && win.frameElement) {
|
|
23
|
+
const frame = win.frameElement;
|
|
24
|
+
const f = frame.getBoundingClientRect();
|
|
25
|
+
x += f.left + frame.clientLeft;
|
|
26
|
+
y += f.top + frame.clientTop;
|
|
27
|
+
win = win.parent;
|
|
28
|
+
}
|
|
29
|
+
return { x, y, viewportWidth: window.innerWidth };`;
|
|
9
30
|
const debug = createDebug('mw:web-locator');
|
|
10
31
|
// Playwright's injected engine throws this when a strict selector matches >1
|
|
11
32
|
// element. Detected by message text because it crosses the in-page boundary as
|
|
@@ -39,11 +60,13 @@ export class MobileWebViewLocator {
|
|
|
39
60
|
// accepts a MobileWebViewLocator.
|
|
40
61
|
this._apiName = 'Locator';
|
|
41
62
|
this._stepFn = null;
|
|
63
|
+
this._nativeInput = null;
|
|
42
64
|
}
|
|
43
65
|
// Build a MobileWebViewLocator from a selector, carrying step instrumentation forward.
|
|
44
66
|
derive(selector) {
|
|
45
67
|
const loc = new MobileWebViewLocator(this.session, selector);
|
|
46
68
|
loc._stepFn = this._stepFn;
|
|
69
|
+
loc._nativeInput = this._nativeInput;
|
|
47
70
|
return loc;
|
|
48
71
|
}
|
|
49
72
|
// Compose a child selector within this locator's scope, Playwright-style.
|
|
@@ -53,12 +76,18 @@ export class MobileWebViewLocator {
|
|
|
53
76
|
async _step(title, fn) {
|
|
54
77
|
return runStep(this._stepFn, title, fn);
|
|
55
78
|
}
|
|
79
|
+
// In-page expression built by `build` from the engine and document that own
|
|
80
|
+
// this locator's selector — the page's own, or an iframe's when the locator
|
|
81
|
+
// came through frameLocator()/contentFrame(). Evaluates to `frameMissing` when
|
|
82
|
+
// an iframe on the path is absent.
|
|
83
|
+
scoped(build, frameMissing) {
|
|
84
|
+
return scopedEngineExpr(this.selector, build, frameMissing);
|
|
85
|
+
}
|
|
56
86
|
// JS expression resolving to the first match via the imported Playwright
|
|
57
87
|
// engine. strict=true: a selector matching >1 element throws a strict-mode
|
|
58
88
|
// violation in-page, matching Playwright's strict locators.
|
|
59
89
|
firstEl() {
|
|
60
|
-
|
|
61
|
-
return `window.__mwInjected.querySelector(window.__mwInjected.parseSelector(${sel}), document, true)`;
|
|
90
|
+
return this.scoped((is, doc, sel) => `${is}.querySelector(${is}.parseSelector(${sel}), ${doc}, true)`, 'null');
|
|
62
91
|
}
|
|
63
92
|
firstElExpr(body) {
|
|
64
93
|
return `(() => { const el = ${this.firstEl()}; ${body} })()`;
|
|
@@ -114,9 +143,8 @@ export class MobileWebViewLocator {
|
|
|
114
143
|
// state. Throws "<what>: element not found" when no element resolves —
|
|
115
144
|
// matching Playwright's isEnabled/isChecked, which require an attached element.
|
|
116
145
|
async readElementState(state, timeout, what) {
|
|
117
|
-
const sel = JSON.stringify(this.selector);
|
|
118
146
|
const stateArg = JSON.stringify(state);
|
|
119
|
-
const js = `(() => { const is =
|
|
147
|
+
const js = this.scoped((is, doc, sel) => `(() => { const is = ${is}; const el = is.querySelector(is.parseSelector(${sel}), ${doc}, true); if (!el) { return null; } return is.elementState(el, ${stateArg}).matches; })()`, 'null');
|
|
120
148
|
let result = false;
|
|
121
149
|
await retryUntil(async () => {
|
|
122
150
|
const matches = await this.evalEngine(js);
|
|
@@ -161,6 +189,14 @@ export class MobileWebViewLocator {
|
|
|
161
189
|
getByTitle(text) {
|
|
162
190
|
return this.child(getByTitleSelector(text));
|
|
163
191
|
}
|
|
192
|
+
// ─── Frames ──────────────────────────────────────────────────
|
|
193
|
+
// This locator points at an <iframe>; locate elements inside its document.
|
|
194
|
+
contentFrame() {
|
|
195
|
+
return new MobileWebViewFrameLocator(this, this.derive(`${this.selector} >> internal:control=enter-frame`));
|
|
196
|
+
}
|
|
197
|
+
frameLocator(selector) {
|
|
198
|
+
return this.locator(selector).contentFrame();
|
|
199
|
+
}
|
|
164
200
|
// ─── Collection ──────────────────────────────────────────────
|
|
165
201
|
first() {
|
|
166
202
|
return this.nth(0);
|
|
@@ -172,8 +208,7 @@ export class MobileWebViewLocator {
|
|
|
172
208
|
return this.derive(`${this.selector} >> nth=${index}`);
|
|
173
209
|
}
|
|
174
210
|
async count() {
|
|
175
|
-
|
|
176
|
-
return this.evalEngine(`window.__mwInjected.querySelectorAll(window.__mwInjected.parseSelector(${sel}), document).length`);
|
|
211
|
+
return this.evalEngine(this.scoped((is, doc, sel) => `${is}.querySelectorAll(${is}.parseSelector(${sel}), ${doc}).length`, '0'));
|
|
177
212
|
}
|
|
178
213
|
// Aliases matching native Locator's API so LocatorAssertions works with MobileWebViewLocator
|
|
179
214
|
async getText(opts) {
|
|
@@ -188,8 +223,7 @@ export class MobileWebViewLocator {
|
|
|
188
223
|
}
|
|
189
224
|
// ─── State queries ───────────────────────────────────────────
|
|
190
225
|
async isVisible(opts) {
|
|
191
|
-
const sel =
|
|
192
|
-
const js = `(() => { const is = window.__mwInjected; const el = is.querySelector(is.parseSelector(${sel}), document, true); if (!el) { return false; } return is.elementState(el, 'visible').matches; })()`;
|
|
226
|
+
const js = this.scoped((is, doc, sel) => `(() => { const is = ${is}; const el = is.querySelector(is.parseSelector(${sel}), ${doc}, true); if (!el) { return false; } return is.elementState(el, 'visible').matches; })()`, 'false');
|
|
193
227
|
return this.pollBoolean(js, opts?.timeout ?? DEFAULT_TIMEOUT, 'visible');
|
|
194
228
|
}
|
|
195
229
|
async isHidden(opts) {
|
|
@@ -242,21 +276,47 @@ export class MobileWebViewLocator {
|
|
|
242
276
|
}, (result) => result, timeout, `MobileWebViewLocator: timed out waiting for state "${state}"`);
|
|
243
277
|
}
|
|
244
278
|
// ─── Actions ─────────────────────────────────────────────────
|
|
279
|
+
// A real touch: a native tap at the element's on-screen center, so the page
|
|
280
|
+
// gets trusted touch, pointer and click events. Needs a page from
|
|
281
|
+
// screen.getByWebView().page(); click() stays a synthetic el.click().
|
|
282
|
+
async tap(opts) {
|
|
283
|
+
return this._step('locator.tap()', () => this.nativeTap(opts?.timeout ?? DEFAULT_TIMEOUT));
|
|
284
|
+
}
|
|
245
285
|
async click(opts) {
|
|
246
286
|
return this._step('locator.click()', async () => {
|
|
247
287
|
await this.pollActionable(['visible', 'enabled'], opts?.timeout ?? DEFAULT_TIMEOUT);
|
|
248
288
|
await this.actOnFirst('el.click();', 'locator.click()');
|
|
249
289
|
});
|
|
250
290
|
}
|
|
291
|
+
// Sets the value in-page, like Playwright's fill(): no tap, no keyboard. For
|
|
292
|
+
// real key events, use pressSequentially().
|
|
251
293
|
async fill(text, opts) {
|
|
252
|
-
return this._step(`locator.fill(${
|
|
294
|
+
return this._step(`locator.fill(${typedTextInTitle(text, opts?.mask)})`, async () => {
|
|
253
295
|
await this.pollUntilVisible(opts?.timeout ?? DEFAULT_TIMEOUT);
|
|
254
296
|
await this.actOnFirst(`el.focus(); ${assignValueScript(JSON.stringify(text))} el.dispatchEvent(new Event('input', { bubbles: true })); el.dispatchEvent(new Event('change', { bubbles: true }));`, 'locator.fill()');
|
|
255
297
|
});
|
|
256
298
|
}
|
|
257
|
-
async
|
|
258
|
-
return this.
|
|
259
|
-
|
|
299
|
+
async clear(opts) {
|
|
300
|
+
return this.fill('', opts);
|
|
301
|
+
}
|
|
302
|
+
// Real typing: tap the field natively, wait for keyboard focus (tapping once
|
|
303
|
+
// more if it does not come), then send the keys one by one through the device
|
|
304
|
+
// keyboard. Like Playwright, it appends: call clear() first to replace.
|
|
305
|
+
async pressSequentially(text, opts) {
|
|
306
|
+
return this._step(`locator.pressSequentially(${typedTextInTitle(text, opts?.mask)})`, async () => {
|
|
307
|
+
const native = this.requireNativeInput('locator.pressSequentially()');
|
|
308
|
+
await this.tapUntilFocused(opts?.timeout ?? DEFAULT_TIMEOUT);
|
|
309
|
+
for (const key of Array.from(text)) {
|
|
310
|
+
await native.typeText(key);
|
|
311
|
+
if (opts?.delay) {
|
|
312
|
+
await sleep(opts.delay);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
async type(text, opts) {
|
|
318
|
+
return this._step(`locator.type(${typedTextInTitle(text, opts?.mask)})`, async () => {
|
|
319
|
+
await this.pollUntilVisible(opts?.timeout ?? DEFAULT_TIMEOUT);
|
|
260
320
|
await this.actOnFirst(`el.focus(); ${assignValueScript(`(el.value || '') + ${JSON.stringify(text)}`)} el.dispatchEvent(new Event('input', { bubbles: true }));`, 'locator.type()');
|
|
261
321
|
});
|
|
262
322
|
}
|
|
@@ -282,13 +342,64 @@ export class MobileWebViewLocator {
|
|
|
282
342
|
});
|
|
283
343
|
}
|
|
284
344
|
// ─── Private helpers ─────────────────────────────────────────
|
|
345
|
+
// The page's device input, or a clear error naming `what` when there is none
|
|
346
|
+
// (a page built directly on a WebViewSession has no device to tap or type on).
|
|
347
|
+
requireNativeInput(what) {
|
|
348
|
+
if (!this._nativeInput) {
|
|
349
|
+
throw new Error(`${what}: needs the page from screen.getByWebView().page() for a real touch or keyboard; use click() or fill() for in-page input`);
|
|
350
|
+
}
|
|
351
|
+
return this._nativeInput;
|
|
352
|
+
}
|
|
353
|
+
// Tap the element's on-screen center natively, once it is visible, enabled
|
|
354
|
+
// and not moving. The CSS point is scaled by the webview's native width over
|
|
355
|
+
// its CSS viewport width.
|
|
356
|
+
async nativeTap(timeout) {
|
|
357
|
+
const native = this.requireNativeInput('locator.tap()');
|
|
358
|
+
await this.pollActionable(['visible', 'enabled', 'stable'], timeout);
|
|
359
|
+
const point = await this.evalOnFirst(SCREEN_POINT_BODY);
|
|
360
|
+
if (!point) {
|
|
361
|
+
throw new Error('locator.tap(): element not found');
|
|
362
|
+
}
|
|
363
|
+
const box = await native.bounds();
|
|
364
|
+
if (!(box.width > 0) || !(point.viewportWidth > 0)) {
|
|
365
|
+
throw new Error('locator.tap(): the webview has no valid on-screen size to map the tap onto');
|
|
366
|
+
}
|
|
367
|
+
const scale = box.width / point.viewportWidth;
|
|
368
|
+
await native.tap(Math.round(box.x + point.x * scale), Math.round(box.y + point.y * scale));
|
|
369
|
+
}
|
|
370
|
+
// Whether the element has keyboard focus, polling for up to FOCUS_TIMEOUT:
|
|
371
|
+
// a tapped field can take a moment to focus on a slow device.
|
|
372
|
+
async hasFocus() {
|
|
373
|
+
const deadline = Date.now() + FOCUS_TIMEOUT;
|
|
374
|
+
while (true) {
|
|
375
|
+
const focused = await this.evalOnFirst('return !!el && el.ownerDocument.activeElement === el;').catch(() => false);
|
|
376
|
+
if (focused || Date.now() >= deadline) {
|
|
377
|
+
return focused;
|
|
378
|
+
}
|
|
379
|
+
await sleep(FOCUS_POLL_INTERVAL);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
// Tap the element natively until it has keyboard focus: a slow device can
|
|
383
|
+
// drop the first tap, and keys typed before focus would go elsewhere.
|
|
384
|
+
async tapUntilFocused(timeout) {
|
|
385
|
+
await this.nativeTap(timeout);
|
|
386
|
+
const focused = await this.hasFocus();
|
|
387
|
+
if (focused) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
await this.nativeTap(timeout);
|
|
391
|
+
const focusedOnRetry = await this.hasFocus();
|
|
392
|
+
if (!focusedOnRetry) {
|
|
393
|
+
throw new Error('locator.pressSequentially(): the field did not take keyboard focus after 2 taps');
|
|
394
|
+
}
|
|
395
|
+
}
|
|
285
396
|
// Poll Playwright's own checkElementStates until the element satisfies all the
|
|
286
397
|
// given states (it returns undefined when they all pass). Used by click to
|
|
287
398
|
// gate on visible+enabled before a synthetic dispatch (slice-1 behavior).
|
|
288
399
|
async pollActionable(states, timeout) {
|
|
289
|
-
const sel = JSON.stringify(this.selector);
|
|
290
400
|
const list = JSON.stringify(states);
|
|
291
|
-
|
|
401
|
+
const js = this.scoped((is, doc, sel) => `(async () => { const is = ${is}; const el = is.querySelector(is.parseSelector(${sel}), ${doc}, true); if (!el) { return false; } const missing = await is.checkElementStates(el, ${list}); return missing === undefined; })()`, 'false');
|
|
402
|
+
await retryUntil(() => this.evalEngine(js), (ready) => ready, timeout, 'MobileWebViewLocator: timed out waiting for element to be actionable');
|
|
292
403
|
}
|
|
293
404
|
async pollUntilVisible(timeout) {
|
|
294
405
|
await retryUntil(() => this.isVisible({ timeout: 0 }), (v) => v, timeout, 'MobileWebViewLocator: timed out waiting for element to be visible');
|
|
@@ -351,4 +462,59 @@ export class MobileWebViewLocator {
|
|
|
351
462
|
Object.defineProperty(MobileWebViewLocator, 'name', { value: 'Locator', configurable: true });
|
|
352
463
|
// Back-compat alias for internal callers that still import WebLocator.
|
|
353
464
|
export { MobileWebViewLocator as WebLocator };
|
|
465
|
+
// Playwright's FrameLocator for a same-origin <iframe> inside the webview, from
|
|
466
|
+
// page.frameLocator(), locator.frameLocator() or locator.contentFrame(). Its
|
|
467
|
+
// locators carry Playwright's enter-frame marker in their selector, and every
|
|
468
|
+
// engine call resolves them inside the iframe's document (see
|
|
469
|
+
// installFrameScope), so actions, queries and expect() work unchanged.
|
|
470
|
+
export class MobileWebViewFrameLocator {
|
|
471
|
+
constructor(
|
|
472
|
+
// The locator of the <iframe> element itself.
|
|
473
|
+
frameElement,
|
|
474
|
+
// frameElement's selector followed by the enter-frame marker.
|
|
475
|
+
content) {
|
|
476
|
+
this.frameElement = frameElement;
|
|
477
|
+
this.content = content;
|
|
478
|
+
}
|
|
479
|
+
owner() {
|
|
480
|
+
return this.frameElement;
|
|
481
|
+
}
|
|
482
|
+
locator(selector) {
|
|
483
|
+
return this.content.locator(selector);
|
|
484
|
+
}
|
|
485
|
+
getByRole(role, opts) {
|
|
486
|
+
return this.content.getByRole(role, opts);
|
|
487
|
+
}
|
|
488
|
+
getByText(text, opts) {
|
|
489
|
+
return this.content.getByText(text, opts);
|
|
490
|
+
}
|
|
491
|
+
getByLabel(label, opts) {
|
|
492
|
+
return this.content.getByLabel(label, opts);
|
|
493
|
+
}
|
|
494
|
+
getByPlaceholder(text, opts) {
|
|
495
|
+
return this.content.getByPlaceholder(text, opts);
|
|
496
|
+
}
|
|
497
|
+
getByTestId(testId) {
|
|
498
|
+
return this.content.getByTestId(testId);
|
|
499
|
+
}
|
|
500
|
+
getByAltText(text) {
|
|
501
|
+
return this.content.getByAltText(text);
|
|
502
|
+
}
|
|
503
|
+
getByTitle(text) {
|
|
504
|
+
return this.content.getByTitle(text);
|
|
505
|
+
}
|
|
506
|
+
// A nested iframe inside this one.
|
|
507
|
+
frameLocator(selector) {
|
|
508
|
+
return this.content.frameLocator(selector);
|
|
509
|
+
}
|
|
510
|
+
first() {
|
|
511
|
+
return this.frameElement.first().contentFrame();
|
|
512
|
+
}
|
|
513
|
+
last() {
|
|
514
|
+
return this.frameElement.last().contentFrame();
|
|
515
|
+
}
|
|
516
|
+
nth(index) {
|
|
517
|
+
return this.frameElement.nth(index).contentFrame();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
354
520
|
//# sourceMappingURL=web-locator.js.map
|