-
Notifications
You must be signed in to change notification settings - Fork 11
/
appium-repl.js
executable file
·73 lines (54 loc) · 1.81 KB
/
appium-repl.js
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
let wd = require('wd');
let repl = require('repl');
require('colors');
let telme = require('telme-promise');
let getProfile = async function (profiles, preselected) {
if (Object.keys(profiles).length === 0) {
throw new Error('No ".appium-repl.json" file found. Consult the README for appium-repl')
}
if (preselected) {
return profiles[preselected]
}
let indexedProfiles = Object.keys(profiles)
console.log(' Profiles '.green)
console.log('=========='.green)
indexedProfiles.forEach((key, index) => {
console.log(`${index} : ${key}`)
})
let decision = await telme("Enter the number of the profile you wish to start")
console.log('\n\n\n\n')
return profiles[indexedProfiles[decision]]
}
async function run (config) {
let desiredCapabilities = await getProfile(config.profiles, config.preselected)
if (!desiredCapabilities) {
console.log("desired capabilities not found")
return
}
desiredCapabilities.newCommandTimeout = 0
console.log("Desired Capabilities: ", JSON.stringify(desiredCapabilities, null, 2));
let driver = wd.promiseRemote(config.hostname, config.port, config.username, config.password);
driver.on('status', function (info) {
console.log(info.cyan);
})
driver.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
})
let quit = function () {
driver.quit(function () {
process.exit(1);
});
};
let action = new wd.TouchAction(driver);
await driver.init(desiredCapabilities)
console.log('driver started')
global.driver = driver
global.quit = quit
global.action = action
repl.start({ prompt: '("o")', useGlobal: true })
}
module.exports = run
process.on('unhandledRejection', error => {
// Will print "unhandledRejection err is not defined"
console.error(error);
});