playwright-touch 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +612 -2
- package/dist/android.d.ts +26 -0
- package/dist/android.js +113 -0
- package/dist/chromium/clock.d.ts +12 -0
- package/dist/chromium/clock.js +45 -0
- package/dist/chromium/gestures.d.ts +56 -0
- package/dist/chromium/gestures.js +500 -0
- package/dist/chromium/steady.d.ts +16 -0
- package/dist/chromium/steady.js +38 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +459 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.js +149 -0
- package/dist/ios/bplist.d.ts +8 -0
- package/dist/ios/bplist.js +150 -0
- package/dist/ios/device.d.ts +30 -0
- package/dist/ios/device.js +48 -0
- package/dist/ios/inspector.d.ts +61 -0
- package/dist/ios/inspector.js +342 -0
- package/dist/ios/iphone.d.ts +27 -0
- package/dist/ios/iphone.js +141 -0
- package/dist/ios/page.d.ts +90 -0
- package/dist/ios/page.js +338 -0
- package/dist/ios/paths.d.ts +17 -0
- package/dist/ios/paths.js +77 -0
- package/dist/ios/simulator.d.ts +24 -0
- package/dist/ios/simulator.js +69 -0
- package/dist/ios/tab.d.ts +41 -0
- package/dist/ios/tab.js +171 -0
- package/dist/ios/tools.d.ts +4 -0
- package/dist/ios/tools.js +17 -0
- package/dist/ios/touch.d.ts +31 -0
- package/dist/ios/touch.js +178 -0
- package/dist/ios/usbmux.d.ts +34 -0
- package/dist/ios/usbmux.js +346 -0
- package/dist/layout.d.ts +35 -0
- package/dist/layout.js +164 -0
- package/dist/measure.d.ts +86 -0
- package/dist/measure.js +173 -0
- package/dist/own-tabs.d.ts +8 -0
- package/dist/own-tabs.js +242 -0
- package/dist/playwright-test.d.ts +66 -0
- package/dist/playwright-test.js +64 -0
- package/dist/polyline.d.ts +10 -0
- package/dist/polyline.js +38 -0
- package/dist/recipes.d.ts +57 -0
- package/dist/recipes.js +135 -0
- package/dist/report.d.ts +46 -0
- package/dist/report.js +118 -0
- package/dist/session.d.ts +35 -0
- package/dist/session.js +23 -0
- package/dist/show.d.ts +13 -0
- package/dist/show.js +51 -0
- package/dist/synthetic.d.ts +17 -0
- package/dist/synthetic.js +117 -0
- package/dist/types.d.ts +58 -0
- package/dist/types.js +2 -0
- package/package.json +83 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import * as chrome from './chromium/gestures.js';
|
|
2
|
+
import * as measuring from './measure.js';
|
|
3
|
+
import * as showing from './show.js';
|
|
4
|
+
export { steadyScrollArgs } from './chromium/steady.js';
|
|
5
|
+
export { isSynthetic } from './synthetic.js';
|
|
6
|
+
export { edgeSwipe, pullToRefresh, swipeUntilVisible, twoFingerSwipe } from './recipes.js';
|
|
7
|
+
// Safari on iOS has no Playwright page. Its page and locators are told apart here, so the same
|
|
8
|
+
// calls work on both.
|
|
9
|
+
const isSafari = (target) => !!target && target.ios === true && typeof target.goto === 'function';
|
|
10
|
+
const isSafariLocator = (target) => !!target && target.ios === true && typeof target.selector === 'string';
|
|
11
|
+
const safariTarget = (target) => isSafariLocator(target) ? target.selector : target;
|
|
12
|
+
/** A stroke across a Safari element is a stroke across the page with the element named in it. */
|
|
13
|
+
const across = (locator, options) => 'from' in options ? options : { ...options, on: locator.selector };
|
|
14
|
+
/**
|
|
15
|
+
* A hard flick: the finger is still moving at full speed when it lifts, so the content keeps
|
|
16
|
+
* scrolling on its own momentum, as it does under a thumb.
|
|
17
|
+
*/
|
|
18
|
+
export async function fling(target, options) {
|
|
19
|
+
if (isSafari(target))
|
|
20
|
+
return target.fling(options);
|
|
21
|
+
if (isSafariLocator(target))
|
|
22
|
+
return target.page.fling(across(target, options));
|
|
23
|
+
return chrome.fling(target, options);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A controlled swipe: the finger slows to a stop before it lifts, so the content moves by the
|
|
27
|
+
* length of the stroke and no further.
|
|
28
|
+
*/
|
|
29
|
+
export async function swipe(target, options) {
|
|
30
|
+
if (isSafari(target))
|
|
31
|
+
return target.swipe(options);
|
|
32
|
+
if (isSafariLocator(target))
|
|
33
|
+
return target.page.swipe(across(target, options));
|
|
34
|
+
return chrome.swipe(target, options);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A quick touch that the browser turns into a click. Playwright's own `tap` needs a context created
|
|
38
|
+
* with `hasTouch`, which the browser on a real phone is not; this one works in both.
|
|
39
|
+
*/
|
|
40
|
+
export async function tap(target, options = {}) {
|
|
41
|
+
if (isSafariLocator(target))
|
|
42
|
+
return target.page.tap(target.selector);
|
|
43
|
+
if (isSafari(options.page))
|
|
44
|
+
return options.page.tap(target);
|
|
45
|
+
return chrome.tap(target, { page: options.page });
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Two quick taps on the same place, which browsers report as a `dblclick` and some pages answer by
|
|
49
|
+
* zooming in.
|
|
50
|
+
*/
|
|
51
|
+
export async function doubleTap(target, options = {}) {
|
|
52
|
+
if (isSafariLocator(target))
|
|
53
|
+
return target.page.doubleTap(target.selector);
|
|
54
|
+
if (isSafari(options.page))
|
|
55
|
+
return options.page.doubleTap(target);
|
|
56
|
+
return chrome.doubleTap(target, { page: options.page });
|
|
57
|
+
}
|
|
58
|
+
/** Rests one finger on the target without moving, long enough for a long-press menu or a pick-up. */
|
|
59
|
+
export async function longPress(target, options = {}) {
|
|
60
|
+
if (isSafariLocator(target))
|
|
61
|
+
return target.page.longPress(target.selector, options);
|
|
62
|
+
if (isSafari(options.page))
|
|
63
|
+
return options.page.longPress(target, options);
|
|
64
|
+
return chrome.longPress(target, { duration: options.duration, page: options.page });
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Carries the source to the destination under one finger and lets go at a standstill. With `hold`,
|
|
68
|
+
* the finger rests first, for lists that pick an item up on a long press.
|
|
69
|
+
*/
|
|
70
|
+
export async function drag(source, destination, options = {}) {
|
|
71
|
+
const safari = isSafariLocator(source)
|
|
72
|
+
? source.page
|
|
73
|
+
: isSafariLocator(destination)
|
|
74
|
+
? destination.page
|
|
75
|
+
: isSafari(options.page)
|
|
76
|
+
? options.page
|
|
77
|
+
: null;
|
|
78
|
+
if (safari) {
|
|
79
|
+
return safari.drag(safariTarget(source), safariTarget(destination), options);
|
|
80
|
+
}
|
|
81
|
+
return chrome.drag(source, destination, { ...options, page: options.page });
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Two fingers spreading (scale above 1) or closing (below 1).
|
|
85
|
+
*
|
|
86
|
+
* On a page, the browser zooms by `scale`, where the page allows zooming. On an element, two
|
|
87
|
+
* fingers travel around its centre, for maps and canvases that read the touches themselves.
|
|
88
|
+
*/
|
|
89
|
+
export async function pinch(target, options) {
|
|
90
|
+
if (isSafari(target))
|
|
91
|
+
return target.pinch(null, options);
|
|
92
|
+
if (isSafariLocator(target))
|
|
93
|
+
return target.page.pinch(target.selector, options);
|
|
94
|
+
return chrome.pinch(target, options);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Two fingers turning around the middle of an element, for maps and pictures that follow the
|
|
98
|
+
* angle between the touches. Positive degrees turn clockwise.
|
|
99
|
+
*/
|
|
100
|
+
export async function rotate(target, options) {
|
|
101
|
+
if (isSafariLocator(target))
|
|
102
|
+
return target.page.rotate(target.selector, options);
|
|
103
|
+
return chrome.rotate(target, options);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Any gesture, finger by finger: each finger lands on its first point, passes through the others
|
|
107
|
+
* at an even pace and lifts on the last. For what the named gestures do not cover, a signature or
|
|
108
|
+
* a drawing.
|
|
109
|
+
*/
|
|
110
|
+
export async function gesture(page, options) {
|
|
111
|
+
if (isSafari(page))
|
|
112
|
+
return page.gesture(options);
|
|
113
|
+
return chrome.gesture(page, options);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Draws a dot under every finger from now on, also on the pages gone to later. The dots follow the
|
|
117
|
+
* touches the page really gets, so they show in a film and tell where a gesture landed.
|
|
118
|
+
*/
|
|
119
|
+
export async function showTouches(page) {
|
|
120
|
+
if (isSafari(page))
|
|
121
|
+
return page.showTouches();
|
|
122
|
+
return showing.showTouches(page);
|
|
123
|
+
}
|
|
124
|
+
export { connectAndroid } from './android.js';
|
|
125
|
+
export { longestPauseOf } from './measure.js';
|
|
126
|
+
/**
|
|
127
|
+
* Starts collecting metrics on the page. Call it before the navigation that should be measured,
|
|
128
|
+
* then read at any time. In Safari the collector can start late, so the order does not matter.
|
|
129
|
+
*/
|
|
130
|
+
export async function watchVitals(page) {
|
|
131
|
+
if (isSafari(page))
|
|
132
|
+
return { read: () => page.vitals() };
|
|
133
|
+
return measuring.watchVitals(page);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Opens the address the way a first-time visitor gets it, without the HTTP cache, and returns the
|
|
137
|
+
* metrics. Nothing is deleted, so on a real phone the owner's cache, cookies and sign-ins stay.
|
|
138
|
+
*/
|
|
139
|
+
export async function coldLoad(page, url, options = {}) {
|
|
140
|
+
return isSafari(page) ? page.coldLoad(url, options) : measuring.coldLoad(page, url, options);
|
|
141
|
+
}
|
|
142
|
+
/** Records what the screen shows while `action` runs, and for `settle` milliseconds after. */
|
|
143
|
+
export async function film(page, action, options = {}) {
|
|
144
|
+
return isSafari(page) ? page.film(action, options) : measuring.film(page, action, options);
|
|
145
|
+
}
|
|
146
|
+
export { rate, writeComparison, writeReport } from './report.js';
|
|
147
|
+
export { connectSimulator } from './ios/simulator.js';
|
|
148
|
+
export { connectIphone } from './ios/iphone.js';
|
|
149
|
+
export { findOverflow, findSmallTargets } from './layout.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A value a property list can hold. */
|
|
2
|
+
export type Plist = string | number | boolean | Buffer | null | Plist[] | {
|
|
3
|
+
[key: string]: Plist;
|
|
4
|
+
};
|
|
5
|
+
/** Writes a value as a binary property list. */
|
|
6
|
+
export declare function encode(root: Plist): Buffer;
|
|
7
|
+
/** Reads a binary property list. */
|
|
8
|
+
export declare function decode(data: Buffer): Plist;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Apple's binary property list, the format Safari's Web Inspector speaks on the wire. Only what
|
|
2
|
+
// those messages use: dictionaries, arrays, strings, data, integers, reals and booleans.
|
|
3
|
+
const isAscii = (text) => /^[\x00-\x7f]*$/.test(text);
|
|
4
|
+
/** A marker byte with a length; lengths of 15 and more follow as an integer object. */
|
|
5
|
+
function sized(type, length) {
|
|
6
|
+
if (length < 15)
|
|
7
|
+
return Buffer.from([type | length]);
|
|
8
|
+
return Buffer.concat([Buffer.from([type | 15]), integer(length)]);
|
|
9
|
+
}
|
|
10
|
+
function integer(value) {
|
|
11
|
+
if (value >= 0 && value < 0x100)
|
|
12
|
+
return Buffer.from([0x10, value]);
|
|
13
|
+
if (value >= 0 && value < 0x10000) {
|
|
14
|
+
const out = Buffer.alloc(3);
|
|
15
|
+
out[0] = 0x11;
|
|
16
|
+
out.writeUInt16BE(value, 1);
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
if (value >= 0 && value < 0x100000000) {
|
|
20
|
+
const out = Buffer.alloc(5);
|
|
21
|
+
out[0] = 0x12;
|
|
22
|
+
out.writeUInt32BE(value, 1);
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
const out = Buffer.alloc(9);
|
|
26
|
+
out[0] = 0x13;
|
|
27
|
+
out.writeBigInt64BE(BigInt(value), 1);
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
/** Writes a value as a binary property list. */
|
|
31
|
+
export function encode(root) {
|
|
32
|
+
// Every value becomes one numbered object; containers refer to their members by number.
|
|
33
|
+
const objects = [];
|
|
34
|
+
const add = (value) => {
|
|
35
|
+
const index = objects.length;
|
|
36
|
+
const entry = { value, refs: [] };
|
|
37
|
+
objects.push(entry);
|
|
38
|
+
if (Array.isArray(value))
|
|
39
|
+
entry.refs = value.map(add);
|
|
40
|
+
else if (value !== null && typeof value === 'object' && !Buffer.isBuffer(value)) {
|
|
41
|
+
const keys = Object.keys(value);
|
|
42
|
+
entry.refs = [...keys.map(add), ...keys.map((key) => add(value[key]))];
|
|
43
|
+
}
|
|
44
|
+
return index;
|
|
45
|
+
};
|
|
46
|
+
add(root);
|
|
47
|
+
const refSize = objects.length < 0x100 ? 1 : objects.length < 0x10000 ? 2 : 4;
|
|
48
|
+
const ref = (index) => {
|
|
49
|
+
const out = Buffer.alloc(refSize);
|
|
50
|
+
out.writeUIntBE(index, 0, refSize);
|
|
51
|
+
return out;
|
|
52
|
+
};
|
|
53
|
+
const body = objects.map(({ value, refs }) => {
|
|
54
|
+
if (value === null)
|
|
55
|
+
return Buffer.from([0x00]);
|
|
56
|
+
if (typeof value === 'boolean')
|
|
57
|
+
return Buffer.from([value ? 0x09 : 0x08]);
|
|
58
|
+
if (typeof value === 'number') {
|
|
59
|
+
if (Number.isInteger(value))
|
|
60
|
+
return integer(value);
|
|
61
|
+
const out = Buffer.alloc(9);
|
|
62
|
+
out[0] = 0x23;
|
|
63
|
+
out.writeDoubleBE(value, 1);
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
if (typeof value === 'string') {
|
|
67
|
+
if (isAscii(value))
|
|
68
|
+
return Buffer.concat([sized(0x50, value.length), Buffer.from(value, 'latin1')]);
|
|
69
|
+
const utf16 = Buffer.from(value, 'utf16le').swap16();
|
|
70
|
+
return Buffer.concat([sized(0x60, value.length), utf16]);
|
|
71
|
+
}
|
|
72
|
+
if (Buffer.isBuffer(value))
|
|
73
|
+
return Buffer.concat([sized(0x40, value.length), value]);
|
|
74
|
+
if (Array.isArray(value))
|
|
75
|
+
return Buffer.concat([sized(0xa0, refs.length), ...refs.map(ref)]);
|
|
76
|
+
return Buffer.concat([sized(0xd0, refs.length / 2), ...refs.map(ref)]);
|
|
77
|
+
});
|
|
78
|
+
const offsets = [];
|
|
79
|
+
let position = 8;
|
|
80
|
+
for (const part of body) {
|
|
81
|
+
offsets.push(position);
|
|
82
|
+
position += part.length;
|
|
83
|
+
}
|
|
84
|
+
const offsetSize = position < 0x100 ? 1 : position < 0x10000 ? 2 : 4;
|
|
85
|
+
const table = Buffer.alloc(offsets.length * offsetSize);
|
|
86
|
+
offsets.forEach((offset, i) => table.writeUIntBE(offset, i * offsetSize, offsetSize));
|
|
87
|
+
const trailer = Buffer.alloc(32);
|
|
88
|
+
trailer[6] = offsetSize;
|
|
89
|
+
trailer[7] = refSize;
|
|
90
|
+
trailer.writeBigUInt64BE(BigInt(objects.length), 8);
|
|
91
|
+
trailer.writeBigUInt64BE(0n, 16);
|
|
92
|
+
trailer.writeBigUInt64BE(BigInt(position), 24);
|
|
93
|
+
return Buffer.concat([Buffer.from('bplist00'), ...body, table, trailer]);
|
|
94
|
+
}
|
|
95
|
+
/** Reads a binary property list. */
|
|
96
|
+
export function decode(data) {
|
|
97
|
+
if (data.subarray(0, 8).toString('latin1') !== 'bplist00')
|
|
98
|
+
throw new Error('playwright-touch: not a binary property list.');
|
|
99
|
+
const trailer = data.subarray(data.length - 32);
|
|
100
|
+
const offsetSize = trailer[6];
|
|
101
|
+
const refSize = trailer[7];
|
|
102
|
+
const top = Number(trailer.readBigUInt64BE(16));
|
|
103
|
+
const tableAt = Number(trailer.readBigUInt64BE(24));
|
|
104
|
+
const offsetOf = (index) => data.readUIntBE(tableAt + index * offsetSize, offsetSize);
|
|
105
|
+
const read = (index) => {
|
|
106
|
+
let at = offsetOf(index);
|
|
107
|
+
const marker = data[at++];
|
|
108
|
+
const type = marker & 0xf0;
|
|
109
|
+
let length = marker & 0x0f;
|
|
110
|
+
const number = (bytes) => {
|
|
111
|
+
const value = bytes === 8 ? Number(data.readBigInt64BE(at)) : data.readUIntBE(at, bytes);
|
|
112
|
+
at += bytes;
|
|
113
|
+
return value;
|
|
114
|
+
};
|
|
115
|
+
if (type === 0x00)
|
|
116
|
+
return marker === 0x09 ? true : marker === 0x08 ? false : null;
|
|
117
|
+
if (type === 0x10)
|
|
118
|
+
return number(1 << length);
|
|
119
|
+
if (type === 0x20)
|
|
120
|
+
return length === 2 ? data.readFloatBE(at) : data.readDoubleBE(at);
|
|
121
|
+
if (type === 0x30)
|
|
122
|
+
return data.readDoubleBE(at);
|
|
123
|
+
if (type === 0x80)
|
|
124
|
+
return number(length + 1);
|
|
125
|
+
if (length === 15) {
|
|
126
|
+
const width = 1 << (data[at++] & 0x0f);
|
|
127
|
+
length = number(width);
|
|
128
|
+
}
|
|
129
|
+
if (type === 0x40)
|
|
130
|
+
return Buffer.from(data.subarray(at, at + length));
|
|
131
|
+
if (type === 0x50)
|
|
132
|
+
return data.subarray(at, at + length).toString('latin1');
|
|
133
|
+
if (type === 0x60)
|
|
134
|
+
return Buffer.from(data.subarray(at, at + length * 2))
|
|
135
|
+
.swap16()
|
|
136
|
+
.toString('utf16le');
|
|
137
|
+
const refs = (count) => Array.from({ length: count }, (_, i) => data.readUIntBE(at + i * refSize, refSize));
|
|
138
|
+
if (type === 0xa0)
|
|
139
|
+
return refs(length).map(read);
|
|
140
|
+
if (type === 0xd0) {
|
|
141
|
+
const all = refs(length * 2);
|
|
142
|
+
const out = {};
|
|
143
|
+
for (let i = 0; i < length; i++)
|
|
144
|
+
out[String(read(all[i]))] = read(all[length + i]);
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
throw new Error(`playwright-touch: unknown property list object 0x${marker.toString(16)}.`);
|
|
148
|
+
};
|
|
149
|
+
return read(top);
|
|
150
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** A simulator Xcode has installed. */
|
|
2
|
+
export interface Simulator {
|
|
3
|
+
udid: string;
|
|
4
|
+
name: string;
|
|
5
|
+
state: string;
|
|
6
|
+
/** The iOS version it runs, as in "26.5". */
|
|
7
|
+
system: string;
|
|
8
|
+
}
|
|
9
|
+
/** The simulators that can be booted, ordered by the system they run, the newest last. */
|
|
10
|
+
export declare function simulators(): Promise<Simulator[]>;
|
|
11
|
+
/** Boots the simulator if it is not running, without opening the Simulator window, and waits until it is up. */
|
|
12
|
+
export declare function boot(device: Simulator): Promise<void>;
|
|
13
|
+
/** The device a running WebDriverAgent serves. */
|
|
14
|
+
export interface Served {
|
|
15
|
+
name?: string;
|
|
16
|
+
system: string;
|
|
17
|
+
/** The session it already has, if any. */
|
|
18
|
+
session?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Asks the WebDriverAgent at `url` which device it serves. Null when nothing answers there. */
|
|
21
|
+
export declare function servedBy(url: string): Promise<Served | null>;
|
|
22
|
+
/**
|
|
23
|
+
* One WebDriverAgent serves one device. Left running for another simulator, it would put the
|
|
24
|
+
* fingers on that one while the page is read from this one. Two simulators may share a name and
|
|
25
|
+
* differ in the system they run, so both are compared. Returns a description of the other device,
|
|
26
|
+
* or null when it is the wanted one.
|
|
27
|
+
*/
|
|
28
|
+
export declare function anotherDevice(served: Served, wanted: Pick<Simulator, 'name' | 'system'>): string | null;
|
|
29
|
+
/** How a simulator is named in messages. */
|
|
30
|
+
export declare const describe: (device: Pick<Simulator, 'name' | 'system'>) => string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Which simulators there are, and which WebDriverAgent serves which of them.
|
|
2
|
+
import { simctl } from './tools.js';
|
|
3
|
+
/** The simulators that can be booted, ordered by the system they run, the newest last. */
|
|
4
|
+
export async function simulators() {
|
|
5
|
+
const listed = JSON.parse(await simctl('list', 'devices', 'available', '-j'));
|
|
6
|
+
return Object.keys(listed.devices)
|
|
7
|
+
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }))
|
|
8
|
+
.flatMap((runtime) => {
|
|
9
|
+
// The runtime's name ends in the system version, as in "…SimRuntime.iOS-26-5".
|
|
10
|
+
const system = /iOS-([\d-]+)$/.exec(runtime)?.[1]?.replace(/-/g, '.') ?? '';
|
|
11
|
+
return listed.devices[runtime].map(({ udid, name, state }) => ({ udid, name, state, system }));
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/** Boots the simulator if it is not running, without opening the Simulator window, and waits until it is up. */
|
|
15
|
+
export async function boot(device) {
|
|
16
|
+
if (device.state !== 'Booted')
|
|
17
|
+
await simctl('boot', device.udid);
|
|
18
|
+
await simctl('bootstatus', device.udid);
|
|
19
|
+
}
|
|
20
|
+
/** Asks the WebDriverAgent at `url` which device it serves. Null when nothing answers there. */
|
|
21
|
+
export async function servedBy(url) {
|
|
22
|
+
const ask = (path, timeout) => fetch(url + path, { signal: AbortSignal.timeout(timeout) }).then((response) => response.json());
|
|
23
|
+
let status;
|
|
24
|
+
try {
|
|
25
|
+
status = (await ask('/status', 1500));
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const info = (await ask('/wda/device/info', 5000).catch(() => null));
|
|
31
|
+
return { name: info?.value?.name, system: status.value?.os?.version ?? '', session: status.sessionId ?? undefined };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* One WebDriverAgent serves one device. Left running for another simulator, it would put the
|
|
35
|
+
* fingers on that one while the page is read from this one. Two simulators may share a name and
|
|
36
|
+
* differ in the system they run, so both are compared. Returns a description of the other device,
|
|
37
|
+
* or null when it is the wanted one.
|
|
38
|
+
*/
|
|
39
|
+
export function anotherDevice(served, wanted) {
|
|
40
|
+
// A wanted device without a name is one whose name the agent is not told, as on a phone.
|
|
41
|
+
const otherName = !!served.name && !!wanted.name && served.name !== wanted.name;
|
|
42
|
+
const otherSystem = !!served.system && !!wanted.system && served.system !== wanted.system;
|
|
43
|
+
if (!otherName && !otherSystem)
|
|
44
|
+
return null;
|
|
45
|
+
return `${served.name ?? 'another device'}${served.system ? ` with iOS ${served.system}` : ''}`;
|
|
46
|
+
}
|
|
47
|
+
/** How a simulator is named in messages. */
|
|
48
|
+
export const describe = (device) => `${device.name}${device.system ? ` with iOS ${device.system}` : ''}`;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Duplex } from 'node:stream';
|
|
2
|
+
import { type Plist } from './bplist.js';
|
|
3
|
+
type Arguments = {
|
|
4
|
+
[key: string]: Plist;
|
|
5
|
+
};
|
|
6
|
+
/** A page Safari offers for inspection. */
|
|
7
|
+
export interface InspectablePage {
|
|
8
|
+
app: string;
|
|
9
|
+
/** The application the page belongs to, as in "com.apple.mobilesafari". Empty when it was not told. */
|
|
10
|
+
bundle: string;
|
|
11
|
+
id: number;
|
|
12
|
+
title: string;
|
|
13
|
+
url: string;
|
|
14
|
+
}
|
|
15
|
+
/** A connection to Safari's Web Inspector in a simulator: it knows the open pages and opens command channels to them. */
|
|
16
|
+
export declare class WebInspector {
|
|
17
|
+
#private;
|
|
18
|
+
private constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Connects to the inspector and introduces itself. A simulator offers its inspector as a socket
|
|
21
|
+
* at a path; for a real iPhone, `dial` makes the connection and `silent` says what to tell the
|
|
22
|
+
* user when the inspector does not answer, which on a phone means it is switched off.
|
|
23
|
+
*
|
|
24
|
+
* The simulator's inspector goes quiet for a while when a client that stayed only a few seconds
|
|
25
|
+
* leaves, and a connection made in that time is never answered. Such a connection is held until
|
|
26
|
+
* the quiet time has passed and then replaced, which takes about a quarter of a minute.
|
|
27
|
+
*/
|
|
28
|
+
static open(dial: string | (() => Promise<Duplex>), silent?: string): Promise<WebInspector>;
|
|
29
|
+
send(selector: string, argument: Arguments): void;
|
|
30
|
+
on(listener: (selector: string, argument: Arguments) => void): () => void;
|
|
31
|
+
/** Asks every known application for its pages again. */
|
|
32
|
+
refresh(): void;
|
|
33
|
+
/** Whether an application with this bundle identifier has announced itself to the inspector. */
|
|
34
|
+
knows(bundle: string): boolean;
|
|
35
|
+
pages(): InspectablePage[];
|
|
36
|
+
/** Waits until a page matching the test is listed. */
|
|
37
|
+
waitForPage(matches: (page: InspectablePage) => boolean, timeout?: number): Promise<InspectablePage>;
|
|
38
|
+
/** Opens a command channel to one page. */
|
|
39
|
+
attach(page: InspectablePage): Promise<InspectorSession>;
|
|
40
|
+
/**
|
|
41
|
+
* Hangs up after everything already sent has gone out. Cutting the socket with a message still
|
|
42
|
+
* on its way leaves the simulator's inspector deaf to the next connection.
|
|
43
|
+
*/
|
|
44
|
+
close(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Commands for one page. Safari wraps each page in a "target" and expects commands to be passed on
|
|
48
|
+
* to it; a navigation to another site swaps the target, and the session follows.
|
|
49
|
+
*/
|
|
50
|
+
export declare class InspectorSession {
|
|
51
|
+
#private;
|
|
52
|
+
readonly ready: Promise<void>;
|
|
53
|
+
constructor(inspector: WebInspector, page: InspectablePage);
|
|
54
|
+
/** Sends one inspector command to the page and waits for its answer. */
|
|
55
|
+
command<T = unknown>(method: string, params?: Record<string, unknown>, timeout?: number): Promise<T>;
|
|
56
|
+
onEvent(listener: (method: string, params: Record<string, unknown>) => void): () => void;
|
|
57
|
+
/** Runs an expression in the page and returns its value. A promise is waited for. */
|
|
58
|
+
evaluate<T = unknown>(expression: string): Promise<T>;
|
|
59
|
+
close(): void;
|
|
60
|
+
}
|
|
61
|
+
export {};
|