@putdotio/rokit 1.3.0 → 1.5.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/README.md +20 -2
- package/dist/index.d.mts +16 -1
- package/dist/index.mjs +2 -2
- package/dist/rokit.mjs +174 -53
- package/dist/{roku-7hiM97p0.mjs → roku-CNLr4tbj.mjs} +39 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,16 +42,19 @@ pnpm exec rokit press --delay-ms 250 Right Select
|
|
|
42
42
|
pnpm exec rokit query /query/active-app
|
|
43
43
|
pnpm exec rokit wait-node videoPlayerScreen visible
|
|
44
44
|
pnpm exec rokit screenshot artifacts/live/player.png
|
|
45
|
+
pnpm exec rokit --json active-app
|
|
45
46
|
```
|
|
46
47
|
|
|
47
48
|
App-specific scenario scripts can also import the generic helpers:
|
|
48
49
|
|
|
49
50
|
```ts
|
|
50
51
|
import {
|
|
52
|
+
assertNamedNodeState,
|
|
53
|
+
assertNamedNodeTranslation,
|
|
51
54
|
assertSceneGraphNode,
|
|
52
55
|
pressKey,
|
|
53
56
|
querySceneGraph,
|
|
54
|
-
|
|
57
|
+
waitForSceneGraphAssertion,
|
|
55
58
|
type RokuContext,
|
|
56
59
|
} from "@putdotio/rokit";
|
|
57
60
|
|
|
@@ -70,7 +73,10 @@ const context: RokuContext = {
|
|
|
70
73
|
await pressKey(context, "Info");
|
|
71
74
|
const xml = await querySceneGraph(context, { attempts: 3 });
|
|
72
75
|
await assertSceneGraphNode(context, "videoPlayerScreen", { state: "visible" });
|
|
73
|
-
|
|
76
|
+
assertNamedNodeTranslation(xml, "videoPlayerScreen", 0, 0);
|
|
77
|
+
await waitForSceneGraphAssertion(context, "expected player", (xml) => {
|
|
78
|
+
assertNamedNodeState(xml, "videoPlayerScreen", "visible");
|
|
79
|
+
});
|
|
74
80
|
```
|
|
75
81
|
|
|
76
82
|
## Commands
|
|
@@ -91,6 +97,16 @@ rokit install <zip-path>
|
|
|
91
97
|
rokit --version
|
|
92
98
|
```
|
|
93
99
|
|
|
100
|
+
Global options:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
rokit --json <command>
|
|
104
|
+
rokit --output json <command>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
JSON mode wraps command output as `{ "status": "ok", "command": "...", ... }`
|
|
108
|
+
and reports failures as `{ "status": "failed", "error": { "message": "..." } }`.
|
|
109
|
+
|
|
94
110
|
- `check` confirms the Roku ECP endpoint responds and the developer installer
|
|
95
111
|
is reachable.
|
|
96
112
|
- `device-info` prints enhanced Roku device metadata as JSON.
|
|
@@ -138,6 +154,8 @@ tokens, and app-specific media identifiers do not belong in git.
|
|
|
138
154
|
- raw ECP queries
|
|
139
155
|
- SceneGraph state queries and named-node assertions
|
|
140
156
|
- SceneGraph attribute, numeric geometry, bounds, and translation readers
|
|
157
|
+
- SceneGraph geometry assertions, status/failure readers, and custom assertion
|
|
158
|
+
wait loops
|
|
141
159
|
- screenshots
|
|
142
160
|
|
|
143
161
|
App repositories should keep their own scenario commands for product behavior,
|
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,10 @@ import * as rokuDeploy from "roku-deploy";
|
|
|
4
4
|
type NodeState = "absent" | "hidden" | "visible";
|
|
5
5
|
type SceneGraphBounds = readonly [x: number, y: number, width: number, height: number];
|
|
6
6
|
type SceneGraphPoint = readonly [x: number, y: number];
|
|
7
|
+
type SceneGraphStatus = {
|
|
8
|
+
readonly error?: string;
|
|
9
|
+
readonly status?: string;
|
|
10
|
+
};
|
|
7
11
|
type NodeExpectation = {
|
|
8
12
|
readonly state: NodeState;
|
|
9
13
|
readonly text?: string;
|
|
@@ -16,7 +20,12 @@ declare const readNamedNodeAttribute: (xml: string, nodeName: string, attributeN
|
|
|
16
20
|
declare const readNamedNodeNumber: (xml: string, nodeName: string, attributeName: string) => number | undefined;
|
|
17
21
|
declare const readNamedNodeBounds: (xml: string, nodeName: string) => SceneGraphBounds | undefined;
|
|
18
22
|
declare const readNamedNodeTranslation: (xml: string, nodeName: string) => SceneGraphPoint | undefined;
|
|
23
|
+
declare const readSceneGraphStatus: (xml: string) => SceneGraphStatus;
|
|
24
|
+
declare const readSceneGraphFailure: (xml: string) => string | undefined;
|
|
19
25
|
declare const isNamedNodeVisible: (xml: string, nodeName: string) => boolean;
|
|
26
|
+
declare const assertSceneGraphNumberNear: (actual: number | undefined, expected: number, label: string, tolerance?: number) => void;
|
|
27
|
+
declare const assertNamedNodeTranslation: (xml: string, nodeName: string, expectedX: number, expectedY: number, tolerance?: number) => void;
|
|
28
|
+
declare const assertNamedNodeSize: (xml: string, nodeName: string, expectedWidth: number, expectedHeight: number, tolerance?: number) => void;
|
|
20
29
|
declare const assertNamedNode: (xml: string, nodeName: string, expectation: NodeExpectation) => void;
|
|
21
30
|
declare const assertNamedNodeState: (xml: string, nodeName: string, state: NodeState) => void;
|
|
22
31
|
declare const assertNamedNodeText: (xml: string, nodeName: string, expectedText: string) => void;
|
|
@@ -52,6 +61,11 @@ type RetryOptions = {
|
|
|
52
61
|
readonly attempts?: number;
|
|
53
62
|
readonly retryDelayMs?: number;
|
|
54
63
|
};
|
|
64
|
+
type SceneGraphAssertion = (xml: string) => void;
|
|
65
|
+
type WaitForSceneGraphAssertionOptions = {
|
|
66
|
+
readonly pollIntervalMs?: number;
|
|
67
|
+
readonly timeoutMs?: number;
|
|
68
|
+
};
|
|
55
69
|
declare const checkDevice: (context: RokuContext) => Promise<DeviceSummary>;
|
|
56
70
|
declare const getDeviceInfo: (context: RokuContext) => Promise<rokuDeploy.DeviceInfo>;
|
|
57
71
|
declare const queryActiveApp: (context: RokuContext) => Promise<ActiveApp>;
|
|
@@ -62,6 +76,7 @@ declare const queryEcp: (context: RokuContext, path: string) => Promise<string>;
|
|
|
62
76
|
declare const querySceneGraph: (context: RokuContext, options?: RetryOptions) => Promise<string>;
|
|
63
77
|
declare const assertSceneGraphNode: (context: RokuContext, nodeName: string, expectation: NodeExpectation) => Promise<void>;
|
|
64
78
|
declare const waitForSceneGraphNode: (context: RokuContext, nodeName: string, expectation: NodeExpectation, timeoutMs?: number) => Promise<void>;
|
|
79
|
+
declare const waitForSceneGraphAssertion: (context: RokuContext, description: string, assertXml: SceneGraphAssertion, options?: WaitForSceneGraphAssertionOptions) => Promise<string>;
|
|
65
80
|
declare const installPackage: (context: RokuContext & {
|
|
66
81
|
readonly password: string;
|
|
67
82
|
}, zipPath: string) => Promise<string>;
|
|
@@ -70,4 +85,4 @@ declare const takeScreenshot: (context: RokuContext & {
|
|
|
70
85
|
}, outputPath: string) => Promise<string>;
|
|
71
86
|
declare const validateRemoteKey: (key: string) => void;
|
|
72
87
|
//#endregion
|
|
73
|
-
export { type ActiveApp, type DeviceSummary, type NodeExpectation, type NodeState, type RemoteKey, type RetryOptions, type RokuContext, type SceneGraphBounds, type SceneGraphPoint, assertNamedNode, assertNamedNodeState, assertNamedNodeText, assertSceneGraphNode, checkDevice, getDeviceInfo, installPackage, isNamedNodeVisible, launchApp, parseSceneGraphNumberList, pressKey, queryActiveApp, queryEcp, querySceneGraph, readActiveApp, readNamedNodeAttribute, readNamedNodeAttributes, readNamedNodeBounds, readNamedNodeNumber, readNamedNodeTranslation, readXmlAttribute, readXmlTag, takeScreenshot, validateRemoteKey, waitForActiveApp, waitForSceneGraphNode };
|
|
88
|
+
export { type ActiveApp, type DeviceSummary, type NodeExpectation, type NodeState, type RemoteKey, type RetryOptions, type RokuContext, type SceneGraphAssertion, type SceneGraphBounds, type SceneGraphPoint, type SceneGraphStatus, type WaitForSceneGraphAssertionOptions, assertNamedNode, assertNamedNodeSize, assertNamedNodeState, assertNamedNodeText, assertNamedNodeTranslation, assertSceneGraphNode, assertSceneGraphNumberNear, checkDevice, getDeviceInfo, installPackage, isNamedNodeVisible, launchApp, parseSceneGraphNumberList, pressKey, queryActiveApp, queryEcp, querySceneGraph, readActiveApp, readNamedNodeAttribute, readNamedNodeAttributes, readNamedNodeBounds, readNamedNodeNumber, readNamedNodeTranslation, readSceneGraphFailure, readSceneGraphStatus, readXmlAttribute, readXmlTag, takeScreenshot, validateRemoteKey, waitForActiveApp, waitForSceneGraphAssertion, waitForSceneGraphNode };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as readNamedNodeTranslation, E as readXmlTag, S as
|
|
2
|
-
export { assertNamedNode, assertNamedNodeState, assertNamedNodeText, assertSceneGraphNode, checkDevice, getDeviceInfo, installPackage, isNamedNodeVisible, launchApp, parseSceneGraphNumberList, pressKey, queryActiveApp, queryEcp, querySceneGraph, readActiveApp, readNamedNodeAttribute, readNamedNodeAttributes, readNamedNodeBounds, readNamedNodeNumber, readNamedNodeTranslation, readXmlAttribute, readXmlTag, takeScreenshot, validateRemoteKey, waitForActiveApp, waitForSceneGraphNode };
|
|
1
|
+
import { A as readActiveApp, C as readNamedNodeAttribute, D as readNamedNodeTranslation, E as readNamedNodeNumber, M as readXmlTag, O as readSceneGraphFailure, S as parseSceneGraphNumberList, T as readNamedNodeBounds, _ as assertNamedNodeState, a as launchApp, b as assertSceneGraphNumberNear, c as queryEcp, d as validateRemoteKey, f as waitForActiveApp, g as assertNamedNodeSize, h as assertNamedNode, i as installPackage, j as readXmlAttribute, k as readSceneGraphStatus, l as querySceneGraph, m as waitForSceneGraphNode, n as checkDevice, o as pressKey, p as waitForSceneGraphAssertion, r as getDeviceInfo, s as queryActiveApp, t as assertSceneGraphNode, u as takeScreenshot, v as assertNamedNodeText, w as readNamedNodeAttributes, x as isNamedNodeVisible, y as assertNamedNodeTranslation } from "./roku-CNLr4tbj.mjs";
|
|
2
|
+
export { assertNamedNode, assertNamedNodeSize, assertNamedNodeState, assertNamedNodeText, assertNamedNodeTranslation, assertSceneGraphNode, assertSceneGraphNumberNear, checkDevice, getDeviceInfo, installPackage, isNamedNodeVisible, launchApp, parseSceneGraphNumberList, pressKey, queryActiveApp, queryEcp, querySceneGraph, readActiveApp, readNamedNodeAttribute, readNamedNodeAttributes, readNamedNodeBounds, readNamedNodeNumber, readNamedNodeTranslation, readSceneGraphFailure, readSceneGraphStatus, readXmlAttribute, readXmlTag, takeScreenshot, validateRemoteKey, waitForActiveApp, waitForSceneGraphAssertion, waitForSceneGraphNode };
|
package/dist/rokit.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as launchApp, c as queryEcp, f as waitForActiveApp, i as installPackage, l as querySceneGraph,
|
|
2
|
+
import { a as launchApp, c as queryEcp, f as waitForActiveApp, i as installPackage, l as querySceneGraph, m as waitForSceneGraphNode, n as checkDevice, o as pressKey, r as getDeviceInfo, s as queryActiveApp, t as assertSceneGraphNode, u as takeScreenshot } from "./roku-CNLr4tbj.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { existsSync, mkdirSync } from "node:fs";
|
|
@@ -23,9 +23,9 @@ const requirePassword = (env) => {
|
|
|
23
23
|
if (!password) return fail("ROKIT_PASSWORD is not set");
|
|
24
24
|
return password;
|
|
25
25
|
};
|
|
26
|
+
var RokitCliError = class extends Error {};
|
|
26
27
|
const fail = (message) => {
|
|
27
|
-
|
|
28
|
-
process.exit(1);
|
|
28
|
+
throw new RokitCliError(message);
|
|
29
29
|
};
|
|
30
30
|
const formatErrorMessage = (error) => {
|
|
31
31
|
if (error instanceof Error) return error.message;
|
|
@@ -42,100 +42,212 @@ const parseTimeout = (value) => {
|
|
|
42
42
|
//#region src/cli.ts
|
|
43
43
|
const packageJson = createRequire(import.meta.url)("../package.json");
|
|
44
44
|
const main = async (argv = process.argv.slice(2)) => {
|
|
45
|
-
|
|
46
|
-
if (!firstArg || firstArg === "--help" || firstArg === "-h") {
|
|
47
|
-
printHelp();
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (firstArg === "--version" || firstArg === "-v") {
|
|
51
|
-
console.log(packageJson.version);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
loadLocalEnv();
|
|
55
|
-
const env = loadEnv();
|
|
56
|
-
const target = requireTarget(env);
|
|
57
|
-
const context = {
|
|
58
|
-
password: env.password,
|
|
59
|
-
target,
|
|
60
|
-
timeoutMs: env.timeoutMs,
|
|
61
|
-
username: env.username
|
|
62
|
-
};
|
|
63
|
-
const command = parseCommand(argv);
|
|
45
|
+
let outputMode = inferOutputMode(argv);
|
|
64
46
|
try {
|
|
65
|
-
|
|
47
|
+
const options = parseGlobalOptions(argv);
|
|
48
|
+
outputMode = options.outputMode;
|
|
49
|
+
const firstArg = options.args[0];
|
|
50
|
+
if (!firstArg || firstArg === "--help" || firstArg === "-h") {
|
|
51
|
+
printHelp();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (firstArg === "--version" || firstArg === "-v") {
|
|
55
|
+
console.log(packageJson.version);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
loadLocalEnv();
|
|
59
|
+
const env = loadEnv();
|
|
60
|
+
const target = requireTarget(env);
|
|
61
|
+
const result = await runCommand({
|
|
62
|
+
password: env.password,
|
|
63
|
+
target,
|
|
64
|
+
timeoutMs: env.timeoutMs,
|
|
65
|
+
username: env.username
|
|
66
|
+
}, parseCommand(options.args));
|
|
67
|
+
printResult(options.outputMode, result);
|
|
66
68
|
} catch (error) {
|
|
67
|
-
|
|
69
|
+
printError(outputMode, formatErrorMessage(error));
|
|
70
|
+
process.exitCode = 1;
|
|
68
71
|
}
|
|
69
72
|
};
|
|
70
73
|
const runCommand = async (context, command) => {
|
|
71
74
|
if (command.name === "check") {
|
|
72
75
|
const summary = await checkDevice(context);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
return {
|
|
77
|
+
command: command.name,
|
|
78
|
+
data: summary,
|
|
79
|
+
message: [
|
|
80
|
+
`device: ${summary.name} (${summary.model})`,
|
|
81
|
+
`ecp: ${summary.ecp}`,
|
|
82
|
+
`developer installer HTTP status: ${summary.installerStatus}`
|
|
83
|
+
].join("\n"),
|
|
84
|
+
status: "ok"
|
|
85
|
+
};
|
|
81
86
|
}
|
|
87
|
+
if (command.name === "device-info") return {
|
|
88
|
+
command: command.name,
|
|
89
|
+
data: await getDeviceInfo(context),
|
|
90
|
+
status: "ok"
|
|
91
|
+
};
|
|
82
92
|
if (command.name === "active-app") {
|
|
83
93
|
const app = await queryActiveApp(context);
|
|
84
|
-
|
|
85
|
-
|
|
94
|
+
return {
|
|
95
|
+
command: command.name,
|
|
96
|
+
data: app,
|
|
97
|
+
message: `active app: ${app.id} ${app.name} ${app.version}`.trim(),
|
|
98
|
+
status: "ok"
|
|
99
|
+
};
|
|
86
100
|
}
|
|
87
101
|
if (command.name === "wait-active") {
|
|
88
102
|
const app = await waitForActiveApp(context, command.appId, command.timeoutMs);
|
|
89
|
-
|
|
90
|
-
|
|
103
|
+
return {
|
|
104
|
+
command: command.name,
|
|
105
|
+
data: app,
|
|
106
|
+
message: `active app: ${app.id} ${app.name} ${app.version}`.trim(),
|
|
107
|
+
status: "ok"
|
|
108
|
+
};
|
|
91
109
|
}
|
|
92
110
|
if (command.name === "launch") {
|
|
93
111
|
const app = await launchApp(context, command.args.appId, command.args.params);
|
|
94
|
-
|
|
95
|
-
|
|
112
|
+
return {
|
|
113
|
+
command: command.name,
|
|
114
|
+
data: app,
|
|
115
|
+
message: `launched: ${app.id} ${app.name} ${app.version}`.trim(),
|
|
116
|
+
status: "ok"
|
|
117
|
+
};
|
|
96
118
|
}
|
|
97
119
|
if (command.name === "press") {
|
|
120
|
+
const pressed = [];
|
|
98
121
|
for (const [index, key] of command.args.keys.entries()) {
|
|
99
122
|
if (index > 0 && command.args.delayMs > 0) await sleep(command.args.delayMs);
|
|
100
123
|
await pressKey(context, key);
|
|
101
|
-
|
|
124
|
+
pressed.push(key);
|
|
102
125
|
}
|
|
103
|
-
return
|
|
126
|
+
return {
|
|
127
|
+
command: command.name,
|
|
128
|
+
data: {
|
|
129
|
+
delayMs: command.args.delayMs,
|
|
130
|
+
keys: pressed
|
|
131
|
+
},
|
|
132
|
+
message: pressed.map((key) => `pressed: ${key}`).join("\n"),
|
|
133
|
+
status: "ok"
|
|
134
|
+
};
|
|
104
135
|
}
|
|
105
136
|
if (command.name === "query") {
|
|
106
|
-
|
|
107
|
-
return
|
|
137
|
+
const body = await queryEcp(context, command.path);
|
|
138
|
+
return {
|
|
139
|
+
command: command.name,
|
|
140
|
+
data: {
|
|
141
|
+
body,
|
|
142
|
+
path: command.path
|
|
143
|
+
},
|
|
144
|
+
message: body,
|
|
145
|
+
status: "ok"
|
|
146
|
+
};
|
|
108
147
|
}
|
|
109
148
|
if (command.name === "sgnodes") {
|
|
110
|
-
|
|
111
|
-
return
|
|
149
|
+
const body = await querySceneGraph(context);
|
|
150
|
+
return {
|
|
151
|
+
command: command.name,
|
|
152
|
+
data: { body },
|
|
153
|
+
message: body,
|
|
154
|
+
status: "ok"
|
|
155
|
+
};
|
|
112
156
|
}
|
|
113
157
|
if (command.name === "assert-node") {
|
|
114
158
|
await assertSceneGraphNode(context, command.args.nodeName, command.args.expectation);
|
|
115
|
-
|
|
116
|
-
|
|
159
|
+
return {
|
|
160
|
+
command: command.name,
|
|
161
|
+
data: formatNodeData(command.args),
|
|
162
|
+
message: `asserted node: ${formatNodeCondition(command.args)}`,
|
|
163
|
+
status: "ok"
|
|
164
|
+
};
|
|
117
165
|
}
|
|
118
166
|
if (command.name === "wait-node") {
|
|
119
167
|
await waitForSceneGraphNode(context, command.args.nodeName, command.args.expectation, command.args.timeoutMs);
|
|
120
|
-
|
|
121
|
-
|
|
168
|
+
return {
|
|
169
|
+
command: command.name,
|
|
170
|
+
data: formatNodeData(command.args),
|
|
171
|
+
message: `matched node: ${formatNodeCondition(command.args)}`,
|
|
172
|
+
status: "ok"
|
|
173
|
+
};
|
|
122
174
|
}
|
|
123
175
|
if (command.name === "screenshot") {
|
|
124
176
|
const password = requirePassword(context);
|
|
125
177
|
mkdirSync(dirname(command.outputPath), { recursive: true });
|
|
126
|
-
|
|
178
|
+
const path = await takeScreenshot({
|
|
127
179
|
...context,
|
|
128
180
|
password
|
|
129
|
-
}, command.outputPath)
|
|
130
|
-
return
|
|
181
|
+
}, command.outputPath);
|
|
182
|
+
return {
|
|
183
|
+
command: command.name,
|
|
184
|
+
data: { path },
|
|
185
|
+
message: `screenshot: ${path}`,
|
|
186
|
+
status: "ok"
|
|
187
|
+
};
|
|
131
188
|
}
|
|
132
189
|
if (command.name === "install") {
|
|
133
190
|
const password = requirePassword(context);
|
|
134
|
-
|
|
191
|
+
const message = await installPackage({
|
|
135
192
|
...context,
|
|
136
193
|
password
|
|
137
|
-
}, command.zipPath)
|
|
194
|
+
}, command.zipPath);
|
|
195
|
+
return {
|
|
196
|
+
command: command.name,
|
|
197
|
+
data: { message },
|
|
198
|
+
message,
|
|
199
|
+
status: "ok"
|
|
200
|
+
};
|
|
138
201
|
}
|
|
202
|
+
throw new Error(`unsupported command: ${command.name}`);
|
|
203
|
+
};
|
|
204
|
+
const parseGlobalOptions = (argv) => {
|
|
205
|
+
const args = [];
|
|
206
|
+
let outputMode = "text";
|
|
207
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
208
|
+
const arg = argv[index];
|
|
209
|
+
if (arg === "--json") {
|
|
210
|
+
outputMode = "json";
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (arg === "--output") {
|
|
214
|
+
const value = argv[index + 1];
|
|
215
|
+
if (value !== "json" && value !== "text") fail("usage: rokit [--json|--output json|--output text] <command>");
|
|
216
|
+
outputMode = value === "json" ? "json" : "text";
|
|
217
|
+
index += 1;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
args.push(arg);
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
args,
|
|
224
|
+
outputMode
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
const inferOutputMode = (argv) => {
|
|
228
|
+
if (argv.includes("--json")) return "json";
|
|
229
|
+
return argv[argv.indexOf("--output") + 1] === "json" ? "json" : "text";
|
|
230
|
+
};
|
|
231
|
+
const printResult = (outputMode, result) => {
|
|
232
|
+
if (outputMode === "json") {
|
|
233
|
+
console.log(JSON.stringify(result, null, 2));
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (result.message !== void 0) {
|
|
237
|
+
console.log(result.message);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
console.log(JSON.stringify(result.data, null, 2));
|
|
241
|
+
};
|
|
242
|
+
const printError = (outputMode, message) => {
|
|
243
|
+
if (outputMode === "json") {
|
|
244
|
+
console.error(JSON.stringify({
|
|
245
|
+
error: { message },
|
|
246
|
+
status: "failed"
|
|
247
|
+
}, null, 2));
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
console.error(message);
|
|
139
251
|
};
|
|
140
252
|
const parseCommand = (argv) => {
|
|
141
253
|
const [name, ...args] = argv;
|
|
@@ -265,6 +377,11 @@ const formatNodeCondition = ({ expectation, nodeName }) => {
|
|
|
265
377
|
const suffix = expectation.text === void 0 ? "" : ` text=${expectation.text}`;
|
|
266
378
|
return `${nodeName} ${expectation.state}${suffix}`;
|
|
267
379
|
};
|
|
380
|
+
const formatNodeData = ({ expectation, nodeName, timeoutMs }) => ({
|
|
381
|
+
expectation,
|
|
382
|
+
nodeName,
|
|
383
|
+
timeoutMs
|
|
384
|
+
});
|
|
268
385
|
const sleep = (ms) => new Promise((resolve) => {
|
|
269
386
|
setTimeout(resolve, ms);
|
|
270
387
|
});
|
|
@@ -305,6 +422,10 @@ usage:
|
|
|
305
422
|
rokit install <zip-path>
|
|
306
423
|
rokit --version
|
|
307
424
|
|
|
425
|
+
global options:
|
|
426
|
+
--json
|
|
427
|
+
--output json | text
|
|
428
|
+
|
|
308
429
|
environment:
|
|
309
430
|
ROKIT_TARGET=<roku-ip>
|
|
310
431
|
ROKIT_PASSWORD=<developer-mode-password>
|
|
@@ -58,10 +58,30 @@ const readNamedNodeTranslation = (xml, nodeName) => {
|
|
|
58
58
|
if (parts.length < 2) return;
|
|
59
59
|
return [parts[0], parts[1]];
|
|
60
60
|
};
|
|
61
|
+
const readSceneGraphStatus = (xml) => ({
|
|
62
|
+
error: readXmlTag(xml, "error"),
|
|
63
|
+
status: readXmlTag(xml, "status")
|
|
64
|
+
});
|
|
65
|
+
const readSceneGraphFailure = (xml) => {
|
|
66
|
+
const { error, status } = readSceneGraphStatus(xml);
|
|
67
|
+
return status === "FAILED" ? error ?? "unknown" : void 0;
|
|
68
|
+
};
|
|
61
69
|
const isNamedNodeVisible = (xml, nodeName) => {
|
|
62
70
|
const attributes = readNamedNodeAttributes(xml, nodeName);
|
|
63
71
|
return attributes !== void 0 && !attributes.includes("visible=\"false\"");
|
|
64
72
|
};
|
|
73
|
+
const assertSceneGraphNumberNear = (actual, expected, label, tolerance = 1) => {
|
|
74
|
+
if (actual === void 0 || Math.abs(actual - expected) > tolerance) throw new Error(`expected ${label} ${expected}, got ${actual ?? "missing"}`);
|
|
75
|
+
};
|
|
76
|
+
const assertNamedNodeTranslation = (xml, nodeName, expectedX, expectedY, tolerance = 1) => {
|
|
77
|
+
const translation = readNamedNodeTranslation(xml, nodeName);
|
|
78
|
+
assertSceneGraphNumberNear(translation?.[0], expectedX, `${nodeName} x`, tolerance);
|
|
79
|
+
assertSceneGraphNumberNear(translation?.[1], expectedY, `${nodeName} y`, tolerance);
|
|
80
|
+
};
|
|
81
|
+
const assertNamedNodeSize = (xml, nodeName, expectedWidth, expectedHeight, tolerance = 1) => {
|
|
82
|
+
assertSceneGraphNumberNear(readNamedNodeNumber(xml, nodeName, "width"), expectedWidth, `${nodeName} width`, tolerance);
|
|
83
|
+
assertSceneGraphNumberNear(readNamedNodeNumber(xml, nodeName, "height"), expectedHeight, `${nodeName} height`, tolerance);
|
|
84
|
+
};
|
|
65
85
|
const assertNamedNode = (xml, nodeName, expectation) => {
|
|
66
86
|
if ("attribute" in expectation) {
|
|
67
87
|
assertNamedNodeAttribute(xml, nodeName, expectation.attribute, expectation.value);
|
|
@@ -199,6 +219,24 @@ const waitForSceneGraphNode = async (context, nodeName, expectation, timeoutMs =
|
|
|
199
219
|
const suffix = lastError ? `; last observation: ${lastError}` : "";
|
|
200
220
|
throw new Error(`expected SceneGraph node "${nodeName}" to match condition${suffix}`);
|
|
201
221
|
};
|
|
222
|
+
const waitForSceneGraphAssertion = async (context, description, assertXml, options = {}) => {
|
|
223
|
+
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
224
|
+
const pollIntervalMs = options.pollIntervalMs ?? 500;
|
|
225
|
+
const start = Date.now();
|
|
226
|
+
let lastError;
|
|
227
|
+
while (Date.now() - start < timeoutMs) {
|
|
228
|
+
try {
|
|
229
|
+
const xml = await querySceneGraph(context);
|
|
230
|
+
assertXml(xml);
|
|
231
|
+
return xml;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
lastError = formatErrorMessage(error);
|
|
234
|
+
}
|
|
235
|
+
await sleep(pollIntervalMs);
|
|
236
|
+
}
|
|
237
|
+
const suffix = lastError ? `; last observation: ${lastError}` : "";
|
|
238
|
+
throw new Error(`${description}${suffix}`);
|
|
239
|
+
};
|
|
202
240
|
const installPackage = async (context, zipPath) => {
|
|
203
241
|
const resolvedZip = resolve(zipPath);
|
|
204
242
|
const extension = extname(resolvedZip);
|
|
@@ -258,4 +296,4 @@ const sleep = (ms) => new Promise((resolve) => {
|
|
|
258
296
|
});
|
|
259
297
|
const formatErrorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
260
298
|
//#endregion
|
|
261
|
-
export {
|
|
299
|
+
export { readActiveApp as A, readNamedNodeAttribute as C, readNamedNodeTranslation as D, readNamedNodeNumber as E, readXmlTag as M, readSceneGraphFailure as O, parseSceneGraphNumberList as S, readNamedNodeBounds as T, assertNamedNodeState as _, launchApp as a, assertSceneGraphNumberNear as b, queryEcp as c, validateRemoteKey as d, waitForActiveApp as f, assertNamedNodeSize as g, assertNamedNode as h, installPackage as i, readXmlAttribute as j, readSceneGraphStatus as k, querySceneGraph as l, waitForSceneGraphNode as m, checkDevice as n, pressKey as o, waitForSceneGraphAssertion as p, getDeviceInfo as r, queryActiveApp as s, assertSceneGraphNode as t, takeScreenshot as u, assertNamedNodeText as v, readNamedNodeAttributes as w, isNamedNodeVisible as x, assertNamedNodeTranslation as y };
|