appium-android-driver 12.4.8 → 12.4.9
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/CHANGELOG.md +6 -0
- package/build/lib/commands/geolocation.d.ts +44 -36
- package/build/lib/commands/geolocation.d.ts.map +1 -1
- package/build/lib/commands/geolocation.js +38 -32
- package/build/lib/commands/geolocation.js.map +1 -1
- package/build/lib/commands/log.d.ts +44 -48
- package/build/lib/commands/log.d.ts.map +1 -1
- package/build/lib/commands/log.js +30 -54
- package/build/lib/commands/log.js.map +1 -1
- package/build/lib/commands/network.d.ts +59 -39
- package/build/lib/commands/network.d.ts.map +1 -1
- package/build/lib/commands/network.js +65 -45
- package/build/lib/commands/network.js.map +1 -1
- package/build/lib/driver.d.ts +9 -9
- package/lib/commands/{geolocation.js → geolocation.ts} +85 -54
- package/lib/commands/{log.js → log.ts} +68 -73
- package/lib/commands/{network.js → network.ts} +106 -59
- package/package.json +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import {errors} from 'appium/driver';
|
|
3
|
-
import {util} from 'appium/support';
|
|
3
|
+
import {util} from '@appium/support';
|
|
4
4
|
import B from 'bluebird';
|
|
5
|
+
import type {AndroidDriver} from '../driver';
|
|
6
|
+
import type {ServiceType, GetConnectivityResult} from './types';
|
|
5
7
|
|
|
6
8
|
const AIRPLANE_MODE_MASK = 0b001;
|
|
7
9
|
const WIFI_MASK = 0b010;
|
|
@@ -9,26 +11,33 @@ const DATA_MASK = 0b100;
|
|
|
9
11
|
const WIFI_KEY_NAME = 'wifi';
|
|
10
12
|
const DATA_KEY_NAME = 'data';
|
|
11
13
|
const AIRPLANE_MODE_KEY_NAME = 'airplaneMode';
|
|
12
|
-
const SUPPORTED_SERVICE_NAMES
|
|
14
|
+
const SUPPORTED_SERVICE_NAMES: ServiceType[] = [
|
|
13
15
|
WIFI_KEY_NAME,
|
|
14
16
|
DATA_KEY_NAME,
|
|
15
17
|
AIRPLANE_MODE_KEY_NAME,
|
|
16
|
-
]
|
|
18
|
+
];
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
+
* Gets the current network connection state.
|
|
22
|
+
*
|
|
23
|
+
* @returns Promise that resolves to a number representing the network connection state.
|
|
24
|
+
* The value is a bitmask where:
|
|
25
|
+
* - Bit 0 (0b001) = Airplane mode
|
|
26
|
+
* - Bit 1 (0b010) = Wi-Fi
|
|
27
|
+
* - Bit 2 (0b100) = Data connection
|
|
21
28
|
*/
|
|
22
|
-
export async function getNetworkConnection(
|
|
29
|
+
export async function getNetworkConnection(
|
|
30
|
+
this: AndroidDriver,
|
|
31
|
+
): Promise<number> {
|
|
23
32
|
this.log.info('Getting network connection');
|
|
24
|
-
|
|
33
|
+
const airplaneModeOn = await this.adb.isAirplaneModeOn();
|
|
25
34
|
let connection = airplaneModeOn ? AIRPLANE_MODE_MASK : 0;
|
|
26
35
|
|
|
27
36
|
// no need to check anything else if we are in airplane mode
|
|
28
37
|
if (!airplaneModeOn) {
|
|
29
|
-
|
|
38
|
+
const wifiOn = await this.isWifiOn();
|
|
30
39
|
connection |= wifiOn ? WIFI_MASK : 0;
|
|
31
|
-
|
|
40
|
+
const dataOn = await this.adb.isDataOn();
|
|
32
41
|
connection |= dataOn ? DATA_MASK : 0;
|
|
33
42
|
}
|
|
34
43
|
|
|
@@ -36,40 +45,53 @@ export async function getNetworkConnection() {
|
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
48
|
+
* Checks if Wi-Fi is enabled.
|
|
49
|
+
*
|
|
50
|
+
* @returns Promise that resolves to `true` if Wi-Fi is enabled, `false` otherwise.
|
|
41
51
|
*/
|
|
42
|
-
export async function isWifiOn(
|
|
52
|
+
export async function isWifiOn(
|
|
53
|
+
this: AndroidDriver,
|
|
54
|
+
): Promise<boolean> {
|
|
43
55
|
return await this.adb.isWifiOn();
|
|
44
56
|
}
|
|
45
57
|
|
|
46
58
|
/**
|
|
59
|
+
* Sets the connectivity state for Wi-Fi, data, and/or airplane mode.
|
|
60
|
+
*
|
|
47
61
|
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
48
|
-
* @
|
|
49
|
-
* @param {boolean} [wifi] Either to enable or disable Wi-Fi.
|
|
62
|
+
* @param wifi Either to enable or disable Wi-Fi.
|
|
50
63
|
* An unset value means to not change the state for the given service.
|
|
51
|
-
* @param
|
|
64
|
+
* @param data Either to enable or disable mobile data connection.
|
|
52
65
|
* An unset value means to not change the state for the given service.
|
|
53
|
-
* @param
|
|
66
|
+
* @param airplaneMode Either to enable to disable the Airplane Mode.
|
|
54
67
|
* An unset value means to not change the state for the given service.
|
|
55
|
-
* @returns
|
|
68
|
+
* @returns Promise that resolves when the connectivity state is set.
|
|
69
|
+
* @throws {errors.InvalidArgumentError} If none of the options are provided.
|
|
56
70
|
*/
|
|
57
|
-
export async function mobileSetConnectivity(
|
|
71
|
+
export async function mobileSetConnectivity(
|
|
72
|
+
this: AndroidDriver,
|
|
73
|
+
wifi?: boolean,
|
|
74
|
+
data?: boolean,
|
|
75
|
+
airplaneMode?: boolean,
|
|
76
|
+
): Promise<void> {
|
|
58
77
|
if (_.every([wifi, data, airplaneMode], _.isUndefined)) {
|
|
59
78
|
throw new errors.InvalidArgumentError(
|
|
60
79
|
`Either one of ${JSON.stringify(SUPPORTED_SERVICE_NAMES)} options must be provided`,
|
|
61
80
|
);
|
|
62
81
|
}
|
|
63
82
|
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
const services: ServiceType[] = [
|
|
84
|
+
[wifi, WIFI_KEY_NAME],
|
|
85
|
+
[data, DATA_KEY_NAME],
|
|
86
|
+
[airplaneMode, AIRPLANE_MODE_KEY_NAME],
|
|
87
|
+
].reduce<ServiceType[]>((acc, [value, key]: [boolean | undefined, ServiceType]) => {
|
|
88
|
+
if (!_.isUndefined(value)) {
|
|
89
|
+
acc.push(key);
|
|
90
|
+
}
|
|
91
|
+
return acc;
|
|
92
|
+
}, []);
|
|
93
|
+
const currentState = await this.mobileGetConnectivity(services);
|
|
94
|
+
const setters: Array<Promise<any> | (() => Promise<any>)> = [];
|
|
73
95
|
if (!_.isUndefined(wifi) && currentState.wifi !== Boolean(wifi)) {
|
|
74
96
|
setters.push(this.setWifiState(wifi));
|
|
75
97
|
}
|
|
@@ -90,12 +112,16 @@ export async function mobileSetConnectivity(wifi, data, airplaneMode) {
|
|
|
90
112
|
}
|
|
91
113
|
|
|
92
114
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* services to get the connectivity for.
|
|
96
|
-
* @returns
|
|
115
|
+
* Gets the connectivity state for one or more services.
|
|
116
|
+
*
|
|
117
|
+
* @param services One or more services to get the connectivity for.
|
|
118
|
+
* @returns Promise that resolves to an object containing the connectivity state for the requested services.
|
|
119
|
+
* @throws {errors.InvalidArgumentError} If any of the provided service names are not supported.
|
|
97
120
|
*/
|
|
98
|
-
export async function mobileGetConnectivity(
|
|
121
|
+
export async function mobileGetConnectivity(
|
|
122
|
+
this: AndroidDriver,
|
|
123
|
+
services: ServiceType[] | ServiceType = SUPPORTED_SERVICE_NAMES,
|
|
124
|
+
): Promise<GetConnectivityResult> {
|
|
99
125
|
const svcs = _.castArray(services);
|
|
100
126
|
const unsupportedServices = _.difference(svcs, SUPPORTED_SERVICE_NAMES);
|
|
101
127
|
if (!_.isEmpty(unsupportedServices)) {
|
|
@@ -123,17 +149,25 @@ export async function mobileGetConnectivity(services = SUPPORTED_SERVICE_NAMES)
|
|
|
123
149
|
return _.reduce(
|
|
124
150
|
statePromises,
|
|
125
151
|
(state, v, k) => _.isUndefined(v.value()) ? state : {...state, [k]: Boolean(v.value())},
|
|
126
|
-
{}
|
|
152
|
+
{} as GetConnectivityResult,
|
|
127
153
|
);
|
|
128
154
|
}
|
|
129
155
|
|
|
130
156
|
/**
|
|
157
|
+
* Sets the network connection state using a bitmask.
|
|
158
|
+
*
|
|
131
159
|
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
132
|
-
* @
|
|
133
|
-
*
|
|
134
|
-
*
|
|
160
|
+
* @param type A number representing the desired network connection state.
|
|
161
|
+
* The value is a bitmask where:
|
|
162
|
+
* - Bit 0 (0b001) = Airplane mode
|
|
163
|
+
* - Bit 1 (0b010) = Wi-Fi
|
|
164
|
+
* - Bit 2 (0b100) = Data connection
|
|
165
|
+
* @returns Promise that resolves to the current network connection state after the change.
|
|
135
166
|
*/
|
|
136
|
-
export async function setNetworkConnection(
|
|
167
|
+
export async function setNetworkConnection(
|
|
168
|
+
this: AndroidDriver,
|
|
169
|
+
type: number,
|
|
170
|
+
): Promise<number> {
|
|
137
171
|
this.log.info('Setting network connection');
|
|
138
172
|
// decode the input
|
|
139
173
|
const shouldEnableAirplaneMode = (type & AIRPLANE_MODE_MASK) !== 0;
|
|
@@ -192,61 +226,74 @@ export async function setNetworkConnection(type) {
|
|
|
192
226
|
}
|
|
193
227
|
|
|
194
228
|
/**
|
|
229
|
+
* Sets the Wi-Fi state.
|
|
230
|
+
*
|
|
195
231
|
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
196
|
-
* @
|
|
197
|
-
* @
|
|
198
|
-
* @returns {Promise<void>}
|
|
232
|
+
* @param isOn `true` to enable Wi-Fi, `false` to disable it.
|
|
233
|
+
* @returns Promise that resolves when the Wi-Fi state is set.
|
|
199
234
|
*/
|
|
200
|
-
export async function setWifiState(
|
|
235
|
+
export async function setWifiState(
|
|
236
|
+
this: AndroidDriver,
|
|
237
|
+
isOn: boolean,
|
|
238
|
+
): Promise<void> {
|
|
201
239
|
await this.settingsApp.setWifiState(isOn, this.isEmulator());
|
|
202
240
|
}
|
|
203
241
|
|
|
204
242
|
/**
|
|
243
|
+
* Sets the mobile data connection state.
|
|
244
|
+
*
|
|
205
245
|
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
206
|
-
* @
|
|
207
|
-
* @
|
|
208
|
-
* @returns {Promise<void>}
|
|
246
|
+
* @param isOn `true` to enable mobile data, `false` to disable it.
|
|
247
|
+
* @returns Promise that resolves when the data connection state is set.
|
|
209
248
|
*/
|
|
210
|
-
export async function setDataState(
|
|
249
|
+
export async function setDataState(
|
|
250
|
+
this: AndroidDriver,
|
|
251
|
+
isOn: boolean,
|
|
252
|
+
): Promise<void> {
|
|
211
253
|
await this.settingsApp.setDataState(isOn, this.isEmulator());
|
|
212
254
|
}
|
|
213
255
|
|
|
214
256
|
/**
|
|
257
|
+
* Toggles the mobile data connection state.
|
|
258
|
+
*
|
|
215
259
|
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
216
|
-
* @
|
|
217
|
-
* @returns {Promise<void>}
|
|
260
|
+
* @returns Promise that resolves when the data connection state is toggled.
|
|
218
261
|
*/
|
|
219
|
-
export async function toggleData(
|
|
262
|
+
export async function toggleData(
|
|
263
|
+
this: AndroidDriver,
|
|
264
|
+
): Promise<void> {
|
|
220
265
|
const isOn = await this.adb.isDataOn();
|
|
221
266
|
this.log.info(`Turning network data ${!isOn ? 'on' : 'off'}`);
|
|
222
267
|
await this.setDataState(!isOn);
|
|
223
268
|
}
|
|
224
269
|
|
|
225
270
|
/**
|
|
271
|
+
* Toggles the Wi-Fi state.
|
|
272
|
+
*
|
|
226
273
|
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
227
|
-
* @
|
|
228
|
-
* @returns {Promise<void>}
|
|
274
|
+
* @returns Promise that resolves when the Wi-Fi state is toggled.
|
|
229
275
|
*/
|
|
230
|
-
export async function toggleWiFi(
|
|
276
|
+
export async function toggleWiFi(
|
|
277
|
+
this: AndroidDriver,
|
|
278
|
+
): Promise<void> {
|
|
231
279
|
const isOn = await this.adb.isWifiOn();
|
|
232
280
|
this.log.info(`Turning WiFi ${!isOn ? 'on' : 'off'}`);
|
|
233
281
|
await this.setWifiState(!isOn);
|
|
234
282
|
}
|
|
235
283
|
|
|
236
284
|
/**
|
|
285
|
+
* Toggles the airplane mode state.
|
|
286
|
+
*
|
|
237
287
|
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
238
|
-
* @
|
|
239
|
-
* @returns {Promise<void>}
|
|
288
|
+
* @returns Promise that resolves when the airplane mode state is toggled.
|
|
240
289
|
*/
|
|
241
|
-
export async function toggleFlightMode(
|
|
242
|
-
|
|
290
|
+
export async function toggleFlightMode(
|
|
291
|
+
this: AndroidDriver,
|
|
292
|
+
): Promise<void> {
|
|
293
|
+
const flightMode = !(await this.adb.isAirplaneModeOn());
|
|
243
294
|
this.log.info(`Turning flight mode ${flightMode ? 'on' : 'off'}`);
|
|
244
295
|
await this.adb.setAirplaneMode(flightMode);
|
|
245
296
|
if ((await this.adb.getApiLevel()) < 30) {
|
|
246
297
|
await this.adb.broadcastAirplaneMode(flightMode);
|
|
247
298
|
}
|
|
248
299
|
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* @typedef {import('appium-adb').ADB} ADB
|
|
252
|
-
*/
|