-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathplatform-profiles.ts
More file actions
80 lines (76 loc) · 3.2 KB
/
platform-profiles.ts
File metadata and controls
80 lines (76 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import type { PerfConfig } from './config.ts';
import type { Platform } from './types.ts';
// Local-convenience defaults for ad-hoc runs; CI always overrides them (--device / --serial).
// The iOS UDID is a specific local "iPhone 17" sim; the Android default is an AVD name that
// `boot` can launch. Pass --udid/--device/--serial to target your own device.
const DEFAULT_IOS_UDID = 'D74E0B66-57EB-4EC1-92DC-DA0A30581FE7';
const DEFAULT_ANDROID_AVD = 'Pixel_9_Pro_XL_API_37';
export type ProfileSelectors = {
// A row on the Settings root that pushes a large sub-screen (big a11y tree).
deepScreen: string;
// The Settings search field (for press/focus; auto-picks a match).
searchField: string;
// A selector that uniquely targets the EDITABLE search field (for fill).
searchFieldEditable: string;
// iOS exposes an editable search field at the Settings root (fill works without focusing
// first; focusing then filling can hang). Android only reveals the editable after tapping
// the search card, so it must press the search entry before fill/type.
searchEditableAtRoot: boolean;
// A label reliably visible on the Settings root, for get/is (selector form).
anchorLabel: string;
// Plain text of the anchor, for wait text / find (not a selector).
anchorText: string;
};
export type ResolvedProfile = {
platform: Platform;
deviceName: string;
udid?: string;
serial?: string;
platformFlags: string[]; // --platform; applied to every call (only conflicts if it mismatches a locked session)
selectorFlags: string[]; // device selectors — ONLY on the session-establishing open / selectorless boot
appTarget: string; // `open` target for Settings
selectors: ProfileSelectors;
};
export function resolveProfile(cfg: PerfConfig): ResolvedProfile {
if (cfg.platform === 'ios') {
// Prefer targeting by device name (CI boots a named simulator); fall back to a UDID.
const useName = cfg.device !== undefined;
const udid = useName ? undefined : (cfg.udid ?? DEFAULT_IOS_UDID);
return {
platform: 'ios',
deviceName: cfg.device ?? 'iPhone 17',
udid,
platformFlags: ['--platform', 'ios'],
selectorFlags: useName ? ['--device', cfg.device!] : ['--udid', udid!],
appTarget: 'settings',
selectors: {
deepScreen: 'label="General"',
searchField: 'label="Search"',
searchFieldEditable: 'label="Search" editable',
searchEditableAtRoot: true,
anchorLabel: 'label="General"',
anchorText: 'General',
},
};
}
const avdName = cfg.device ?? DEFAULT_ANDROID_AVD;
const serialFlags = cfg.serial
? ['--serial', cfg.serial, '--android-device-allowlist', cfg.serial]
: [];
return {
platform: 'android',
deviceName: cfg.serial ? `android (${cfg.serial})` : avdName,
serial: cfg.serial,
platformFlags: ['--platform', 'android'],
selectorFlags: ['--device', avdName, ...serialFlags],
appTarget: 'com.android.settings',
selectors: {
deepScreen: 'text="Network & internet"',
searchField: 'text="Search Settings"',
searchFieldEditable: 'editable',
searchEditableAtRoot: false,
anchorLabel: 'label="Network & internet"',
anchorText: 'Network & internet',
},
};
}