-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathscenario.ts
More file actions
171 lines (155 loc) · 6.68 KB
/
Copy pathscenario.ts
File metadata and controls
171 lines (155 loc) · 6.68 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import path from 'node:path';
import type { ResolvedProfile } from './platform-profiles.ts';
// A legacy-form batch step: maps through the exact documented CLI grammar.
// `flags` uses internal CliFlags field names (e.g. snapshotInteractiveOnly).
export type BatchStepSpec = {
command: string;
positionals?: string[];
flags?: Record<string, unknown>;
};
type ScenarioStepBase = {
label: string;
command: string;
// When set, the harness runs an untimed `open --relaunch` (reset to root, top of list)
// before timing this step. Used for steps whose precondition is a clean root, since
// earlier commands (find/is, search) leave the list scrolled or in a different surface.
freshRoot?: boolean;
};
// Discriminated on execMode so the invoker gets the right payload without `!`/`?? []`:
// standalone carries full CLI args; batch carries one legacy batch step.
export type ScenarioStep =
| (ScenarioStepBase & { execMode: 'standalone'; args: string[] })
| (ScenarioStepBase & { execMode: 'batch'; step: BatchStepSpec; isSnapshot?: boolean });
export type StepContext = { artifactsDir: string };
function std(label: string, command: string, args: string[]): ScenarioStep {
return { label, command, execMode: 'standalone', args };
}
function bat(
label: string,
command: string,
step: BatchStepSpec,
opts: { isSnapshot?: boolean; freshRoot?: boolean } = {},
): ScenarioStep {
return { label, command, execMode: 'batch' as const, step, ...opts };
}
// One ordered pass over Settings. The harness repeats this N (+warmup) times;
// the leading `open --relaunch` resets the app to its root each round, so every
// round starts from a known state while commands run in their natural order.
export function buildSettingsTour(p: ResolvedProfile, ctx: StepContext): ScenarioStep[] {
const s = p.selectors;
const shot = path.join(ctx.artifactsDir, 'shot.png');
const rec = path.join(ctx.artifactsDir, 'rec.mp4');
const trace = path.join(ctx.artifactsDir, 'trace.log');
// Text entry differs per platform: iOS fills the root search field directly (focusing it
// first can hang); Android must open the search screen before an editable field exists.
const textEntry: ScenarioStep[] = p.selectors.searchEditableAtRoot
? [
// iOS: editable search field exists at root; fill it directly (freshRoot resets scroll).
bat(
'fill search',
'fill',
{ command: 'fill', positionals: [s.searchFieldEditable, 'general'] },
{ freshRoot: true },
),
bat('type', 'type', { command: 'type', positionals: ['wifi'] }),
bat('get editable text', 'get', {
command: 'get',
positionals: ['text', s.searchFieldEditable],
}),
bat('keyboard return', 'keyboard', { command: 'keyboard', positionals: ['return'] }),
]
: [
// Android: tap the search entry first to reveal the editable, then type/fill it.
bat(
'press search field',
'press',
{ command: 'press', positionals: [s.searchField] },
{ freshRoot: true },
),
bat('type', 'type', { command: 'type', positionals: ['wifi'] }),
bat('fill search', 'fill', {
command: 'fill',
positionals: [s.searchFieldEditable, 'general'],
}),
bat('get editable text', 'get', {
command: 'get',
positionals: ['text', s.searchFieldEditable],
}),
];
// These iOS-only repeated gesture forms route to dedicated XCTest runner commands:
// press --count > 1 -> tapSeries; swipe --count > 1 -> dragSeries.
const iosRunnerSeries: ScenarioStep[] =
p.platform === 'ios'
? [
bat(
'press series (tapSeries)',
'press',
{ command: 'press', positionals: ['200', '95'], flags: { count: 2, intervalMs: 50 } },
{ freshRoot: true },
),
bat(
'swipe series (dragSeries)',
'swipe',
{
command: 'swipe',
positionals: ['200', '650', '200', '450', '120'],
flags: { count: 2, pauseMs: 50, pattern: 'ping-pong' },
},
{ freshRoot: true },
),
]
: [];
return [
// --- reset to root via relaunch ---
std('open (relaunch → root)', 'open', ['open', p.appTarget, '--relaunch']),
// --- reads on the root tree (snapshots first; anchor label is visible here) ---
bat(
'snapshot -i (root)',
'snapshot',
{ command: 'snapshot', flags: { snapshotInteractiveOnly: true } },
{ isSnapshot: true },
),
bat('snapshot (root)', 'snapshot', { command: 'snapshot' }, { isSnapshot: true }),
// --- navigate into a sub-screen from a fresh root (freshRoot resets scroll so the
// deep-screen row is in view), read it, then return ---
bat(
'press → deep screen',
'press',
{ command: 'press', positionals: [s.deepScreen] },
{ freshRoot: true },
),
bat('snapshot (deep)', 'snapshot', { command: 'snapshot' }, { isSnapshot: true }),
bat(
'snapshot -i (deep)',
'snapshot',
{ command: 'snapshot', flags: { snapshotInteractiveOnly: true } },
{ isSnapshot: true },
),
bat('back', 'back', { command: 'back' }),
// --- iOS runner series commands surfaced by PR #643 ---
...iosRunnerSeries,
// --- targeted reads against the visible anchor (freshRoot so the anchor is on screen) ---
bat(
'wait text',
'wait',
{ command: 'wait', positionals: ['text', s.anchorText, '3000'] },
{ freshRoot: true },
),
bat('find', 'find', { command: 'find', positionals: [s.anchorText] }),
bat('get text', 'get', { command: 'get', positionals: ['text', s.anchorLabel] }),
bat('is visible', 'is', { command: 'is', positionals: ['visible', s.anchorLabel] }),
// --- text entry (platform-specific order; see textEntry above) then scroll results ---
...textEntry,
bat('scroll down', 'scroll', { command: 'scroll', positionals: ['down'] }),
// --- artifact-producing commands; record brackets the rest so the clip has >1s of
// footage (an instant start→stop makes simctl recordVideo fail to finalize) ---
std('record start', 'record', ['record', 'start', rec, '--hide-touches']),
bat('screenshot', 'screenshot', { command: 'screenshot', positionals: [shot] }),
bat('logs mark', 'logs', { command: 'logs', positionals: ['mark', 'perf-mark'] }),
bat('logs clear', 'logs', { command: 'logs', positionals: ['clear'] }),
std('trace start', 'trace', ['trace', 'start', trace]),
std('trace stop', 'trace', ['trace', 'stop']),
bat('perf', 'perf', { command: 'perf' }),
std('record stop', 'record', ['record', 'stop']),
];
}