forked from github/copilot-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwait.js
More file actions
90 lines (75 loc) · 2.23 KB
/
wait.js
File metadata and controls
90 lines (75 loc) · 2.23 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
/**
* wait command - Wait for element to appear
* @module cli/commands/wait
*/
const path = require('path');
const { success, error, info, Spinner } = require('../util/output');
const UI_MODULE = path.resolve(__dirname, '../../main/ui-automation');
let ui;
function loadUI() {
if (!ui) {
ui = require(UI_MODULE);
}
return ui;
}
/**
* Run the wait command
*
* Usage:
* liku wait "Loading..." # Wait up to 10s for element
* liku wait "Submit" 5000 # Wait up to 5s
* liku wait "Dialog" --gone # Wait for element to disappear
* liku wait "Submit" 5000 --enabled # Wait for element to exist AND be enabled
*/
async function run(args, options) {
loadUI();
if (args.length === 0) {
error('Usage: liku wait <text> [timeout] [--gone]');
return { success: false };
}
const searchText = args[0];
const timeout = args[1] ? parseInt(args[1], 10) : 10000;
const waitGone = options.gone || false;
const requireEnabled = options.enabled === true || options.isEnabled === true;
const spinner = (!options.quiet && !options.json) ? new Spinner(
waitGone
? `Waiting for "${searchText}" to disappear`
: `Waiting for "${searchText}"`
) : null;
spinner?.start();
const criteria = { text: searchText };
if (options.type) {
criteria.controlType = options.type;
}
if (requireEnabled) {
criteria.isEnabled = true;
}
const result = waitGone
? await ui.waitForElementGone(criteria, timeout)
: await ui.waitForElement(criteria, { timeout });
spinner?.stop();
if (result.success) {
if (!options.quiet && !options.json) {
success(
waitGone
? `"${searchText}" disappeared after ${result.elapsed}ms`
: `Found "${searchText}" after ${result.elapsed}ms`
);
}
return {
success: true,
elapsed: result.elapsed,
element: result.element,
};
} else {
if (!options.quiet && !options.json) {
error(
waitGone
? `"${searchText}" did not disappear within ${timeout}ms`
: `"${searchText}" not found within ${timeout}ms`
);
}
return { success: false, elapsed: result.elapsed, timeout };
}
}
module.exports = { run };