This repository has been archived by the owner on May 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
119 lines (102 loc) · 3.46 KB
/
app.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
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
const wdio = require('webdriverio')
const assert = require('assert')
const { clickElement, getElement, tryAction } = require('./utils')
const opts = {
logLevel: 'silent',
// logLevel: 'error',
port: 4723,
capabilities: {
acceptInsecureCerts: true,
allowTestPackages: true,
// app: `${__dirname}/apk/ApiDemos-debug.apk`,
// app: `${__dirname}/apk/turkish-airlines-1-10-0.apk`,
// appActivity: 'com.cloudflare.app.presentation.main.MainActivity',
appActivity: 'ui.main.MainActivity',
// appPackage: 'io.appium.android.apis',
// appPackage: 'com.cloudflare.onedotonedotonedotone',
appPackage: 'com.turkishairlines.mobile',
automationName: 'UiAutomator2',
deviceName: 'Android Emulator',
// isHeadless: true, // gives error
platformName: 'Android',
platformVersion: '9'
}
}
// sample with webdriverio
async function main() {
try {
const client = await wdio.remote({ ...opts })
try {
await clickElement(client, [['text', 'Get started']])
await clickElement(client, [['text', 'Done']])
await clickElement(client, [['text', 'Accept']])
// const element = await client.findElement(
// 'xpath',
// '//android.widget.ImageButton[@content-desc="Guide"]'
// )
// await element.click()
// check user guide and go back
await clickElement(client, [
['resourceId', 'com.cloudflare.onedotonedotonedotone:id/guideBtn']
])
await clickElement(client, [['text', 'Done']])
// change the service to 1.1.1.1 only
await clickElement(client, [
['resourceId', 'com.cloudflare.onedotonedotonedotone:id/settingsBtn']
])
await clickElement(client, [
[
'resourceId',
'com.cloudflare.onedotonedotonedotone:id/settingsAppModeNoWarp'
]
])
// change theme to dark
await clickElement(client, [['text', 'More settings']])
await clickElement(client, [['text', 'Use dark theme']]) // should do nothing
const darkThemeSwitch = await getElement(client, [
['resourceId', 'com.cloudflare.onedotonedotonedotone:id/darkModeSwitch']
])
if ((await darkThemeSwitch.getText()) != 'ON') {
await darkThemeSwitch.click()
}
// back to main menu
await clickElement(client, [['descriptionMatches', 'Navigate up']])
await client.back()
try {
await client.acceptAlert()
} catch (error) {
console.error(error.message)
}
// turn it on
const turnSwitch = await getElement(client, [
['resourceId', 'com.cloudflare.onedotonedotonedotone:id/launchSwitch']
])
if ((await turnSwitch.getText()) == 'OFF') {
await turnSwitch.click()
// there might be an optional permission request
try {
await clickElement(client, [['text', 'Install VPN profile']])
await clickElement(client, [['text', 'OK']])
} catch (error) {
// console.error(error.message)
}
}
// turn it off
if ((await turnSwitch.getText()) == 'ON') {
await turnSwitch.click()
// may be asked for how long it should be off
try {
await clickElement(client, [['text', 'Until I turn it back on']])
} catch (error) {
console.error(error.message)
}
}
} catch (error) {
console.error(error.message)
}
await client.deleteSession()
} catch (error) {
console.error(error.message)
}
}
main()