-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathappium-driver.ts
726 lines (618 loc) · 25.3 KB
/
appium-driver.ts
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
var chai = require("chai");
import * as wd from "wd";
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
export var should = chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
import { ChildProcess } from "child_process";
import { ElementHelper } from "./element-helper";
import { SearchOptions } from "./search-options";
import { UIElement } from "./ui-element";
import { Direction } from "./direction";
import { Locator } from "./locators";
import {
Platform,
DeviceController,
IDevice,
DeviceType,
AndroidController,
IOSController
} from "mobile-devices-controller";
import {
addExt,
log,
getStorageByPlatform,
getStorageByDeviceName,
resolve,
fileExists,
getAppPath,
getReportPath,
calculateOffset,
scroll,
findFreePort,
wait,
copy
} from "./utils";
import { INsCapabilities } from "./interfaces/ns-capabilities";
import { IRectangle } from "./interfaces/rectangle";
import { Point } from "./point";
import { ImageHelper } from "./image-helper";
import { ImageOptions } from "./image-options"
import { unlinkSync, writeFileSync } from "fs";
import * as webdriverio from "webdriverio";
import { DeviceManager } from "../lib/device-manager";
import { extname, basename } from "path";
export class AppiumDriver {
private static pngFileExt = '.png';
private static partialUrl = "/wd/hub/session/";
private _defaultWaitTime: number = 5000;
private _elementHelper: ElementHelper;
private _imageHelper: ImageHelper;
private _isAlive: boolean = false;
private _locators: Locator;
private _logPath: string;
private _storageByDeviceName: string;
private _storageByPlatform: string;
private constructor(private _driver: any, private _wd, private _webio: any, private _driverConfig, private _args: INsCapabilities) {
this._elementHelper = new ElementHelper(this._args);
this._imageHelper = new ImageHelper(this._args);
this._isAlive = true;
this._locators = new Locator(this._args);
this._webio.requestHandler.sessionID = this._driver.sessionID;
}
get imageHelper() {
return this._imageHelper;
}
get defaultWaitTime(): number {
return this._defaultWaitTime;
}
set defaultWaitTime(waitTime: number) {
this._defaultWaitTime = waitTime;
}
get capabilities() {
return this._args.appiumCaps;
}
get nsCapabilities(): INsCapabilities {
return this._args;
}
get platformName() {
return this._args.appiumCaps.platformName;
}
get platformVersion() {
return this._args.appiumCaps.platformVersion;
}
get elementHelper() {
return this._elementHelper;
}
get locators() {
return this._locators;
}
get isAlive() {
return this._isAlive;
}
get isAndroid() {
return this._args.isAndroid;
}
get isIOS() {
return this._args.isIOS;
}
get driver() {
return this._driver;
}
public webio() {
return this._webio;
}
public wd() {
return this._wd;
}
public async click(args) {
return await this._webio.click(args);
}
public async navBack() {
return await this._driver.back();
}
/**
* Get the storage where test results from image comparisson is logged It will be reports/app nam/device name
*/
get reportsPath() {
return this._logPath;
}
/**
* Get the storage where images are captured by platform. It will be resources/app nam/platform name
*/
get storageByPlatform() {
return this._storageByPlatform;
}
/**
* Get the storage where images are captured. It will be resources/app nam/device name
*/
get storageByDeviceName() {
return this._storageByDeviceName;
}
public static async createAppiumDriver(port: number, args: INsCapabilities) {
let driverConfig: any = {
host: "localhost",
port: port
};
if (args.isSauceLab) {
const sauceUser = process.env.SAUCE_USER || process.env.npm_config["SAUCE_USER"];
const sauceKey = process.env.SAUCE_KEY || process.env.npm_config["SAUCE_KEY"];
if (!sauceKey || !sauceUser) {
throw new Error("Sauce Labs Username or Access Key is missing! Check environment variables for SAUCE_USER and SAUCE_KEY !!!");
}
driverConfig = "https://" + sauceUser + ":" + sauceKey + "@ondemand.saucelabs.com:443/wd/hub";
}
log("Creating driver!", args.verbose);
await AppiumDriver.applyAdditionalSettings(args);
const webio = webdriverio.remote({
baseUrl: driverConfig.host,
port: driverConfig.port,
desiredCapabilities: args.appiumCaps
});
const driver = await wd.promiseChainRemote(driverConfig);
AppiumDriver.configureLogging(driver, args.verbose);
let hasStarted = false;
let retries = 10;
while (retries > 0 && !hasStarted) {
try {
const sessionIfno = await driver.init(args.appiumCaps);
log(sessionIfno, args.verbose);
await DeviceManager.applyDeviceAdditionsSettings(driver, args, sessionIfno);
hasStarted = true;
} catch (error) {
console.log(error);
console.log("Rety launching appium driver!");
if (error && error.message && error.message.includes("WebDriverAgent")) {
const freePort = await findFreePort(100, args.wdaLocalPort);
console.log("args.appiumCaps['wdaLocalPort']", freePort);
args.appiumCaps["wdaLocalPort"] = freePort;
}
}
if (hasStarted) {
console.log("Appium driver has started successfully!");
}
retries--;
}
return new AppiumDriver(driver, wd, webio, driverConfig, args);
}
/**
*
* @param xPath
* @param waitForElement
*/
public async findElementByXPath(xPath: string, waitForElement: number = this.defaultWaitTime) {
const searchM = "waitForElementByXPath";
return await new UIElement(await this._driver.waitForElementByXPath(xPath, waitForElement), this._driver, this._wd, this._webio, this._args, searchM, xPath);
}
/**
*
* @param xPath
* @param waitForElement
*/
public async findElementsByXPath(xPath: string, waitForElement: number = this.defaultWaitTime) {
return await this.convertArrayToUIElements(await this._driver.waitForElementsByXPath(xPath, waitForElement), "waitForElementsByXPath", xPath);
}
/**
* Search for element by given text. The seacrch is case insensitive for android
* @param text
* @param match
* @param waitForElement
*/
public async findElementByText(text: string, match: SearchOptions = SearchOptions.exact, waitForElement: number = this.defaultWaitTime) {
const shouldMatch = match === SearchOptions.exact ? true : false;
return await this.findElementByXPath(this._elementHelper.getXPathByText(text, shouldMatch), waitForElement);
}
/**
* Search for elements by given text. The seacrch is case insensitive for android
* @param text
* @param match
* @param waitForElement
*/
public async findElementsByText(text: string, match: SearchOptions = SearchOptions.exact, waitForElement: number = this.defaultWaitTime) {
const shouldMatch = match === SearchOptions.exact ? true : false;
return await this.findElementsByXPath(this._elementHelper.getXPathByText(text, shouldMatch), waitForElement);
}
/**
* Searches for element by element native class name like button, textView etc which will be translated to android.widgets.Button or XCUIElementTypeButton (iOS 10 and higher) or UIElementButton (iOS 9)
* Notice this is not the same as css class
* @param className
* @param waitForElement
*/
public async findElementByClassName(className: string, waitForElement: number = this.defaultWaitTime) {
return new UIElement(await this._driver.waitForElementByClassName(className, waitForElement), this._driver, this._wd, this._webio, this._args, "waitForElementByClassName", className);
}
/**
* Searches for element by element native class name like button, textView etc which will be translated to android.widgets.Button or XCUIElementTypeButton (iOS 10 and higher) or UIElementButton (iOS 9)
* Notice this is not the same as css class
* @param className
* @param waitForElement
*/
public async findElementsByClassName(className: string, waitForElement: number = this.defaultWaitTime) {
return await this.convertArrayToUIElements(await this._driver.waitForElementsByClassName(className, waitForElement), "waitForElementsByClassName", className);
}
/**
* Find element by automationText
* @param id
* @param waitForElement
*/
public async findElementByAccessibilityId(id, waitForElement: number = this.defaultWaitTime) {
return new UIElement(await this._driver.waitForElementByAccessibilityId(id, waitForElement), this._driver, this._wd, this._webio, this._args, "waitForElementByAccessibilityId", id);
}
/**
* Find elements by automationText
* @param id
* @param waitForElement
*/
public async findElementsByAccessibilityId(id: string, waitForElement: number = this.defaultWaitTime) {
return await this.convertArrayToUIElements(await this._driver.waitForElementsByAccessibilityId(id, waitForElement), "waitForElementsByAccessibilityId", id);
}
/**
* Scrolls from point to other point with minimum inertia
* @param direction
* @param y
* @param x
* @param yOffset
* @param xOffset
*/
public async scroll(direction: Direction, y: number, x: number, yOffset: number, xOffset: number = 0) {
scroll(this._wd, this._driver, direction, this._webio.isIOS, y, x, yOffset, xOffset, this._args.verbose);
}
/**
*
* @param direction
* @param element
* @param startPoint
* @param yOffset
* @param xOffset
* @param retryCount
*/
public async scrollTo(direction: Direction, element: any, startPoint: Point, yOffset: number, xOffset: number = 0, retryCount: number = 7) {
let el = null;
while (el === null && retryCount > 0) {
try {
el = await element();
if (!(await el.isDisplayed())) {
await scroll(this._wd, this._driver, direction, this._webio.isIOS, startPoint.y, startPoint.x, yOffset, xOffset, this._args.verbose);
}
} catch (error) {
await scroll(this._wd, this._driver, direction, this._webio.isIOS, startPoint.y, startPoint.x, yOffset, xOffset, this._args.verbose);
}
if (el !== null && (await el.isDisplayed())) {
break;
} else {
el = null;
}
retryCount--;
}
return el;
}
/**
* Swipe from point with offset and inertia according to duatio
* @param y
* @param x
* @param yOffset
* @param inertia
* @param xOffset
*/
public async swipe(y: number, x: number, yOffset: number, inertia: number = 250, xOffset: number = 0) {
let direction = 1;
if (this._webio.isIOS) {
direction = -1;
}
const action = new this._wd.TouchAction(this._driver);
action
.press({ x: x, y: y })
.wait(inertia)
.moveTo({ x: xOffset, y: direction * yOffset })
.release();
await action.perform();
await this._driver.sleep(150);
}
/**
* Click a point by providing coordinates
* @param x
* @param y
*/
public async clickPoint(xCoordinate: number, yCoordinate: number) {
let action = new this._wd.TouchAction(this._driver);
action
.tap({ x: xCoordinate, y: yCoordinate });
await action.perform();
await this._driver.sleep(150);
}
public async source() {
return await this._webio.source();
}
public async sessionId() {
return await this.driver.getSessionId();
}
public async compareElement(element: UIElement, imageName: string, tolerance: number = 0.01, timeOutSeconds: number = 3, toleranceType?: ImageOptions) {
return await this.compareRectangle(await element.getActualRectangle(), imageName, timeOutSeconds, tolerance, toleranceType);
}
public async compareRectangle(rect: IRectangle, imageName: string, timeOutSeconds: number = 3, tolerance: number = 0.01, toleranceType?: ImageOptions) {
return await this.compare(imageName, timeOutSeconds, tolerance, rect, toleranceType);
}
public async compareScreen(imageName: string, timeOutSeconds: number = 3, tolerance: number = 0.01, toleranceType?: ImageOptions) {
return await this.compare(imageName, timeOutSeconds, tolerance, undefined, toleranceType);
}
/**
* @param videoName
* @param callback when to stop video recording. In order an element is found. Should return true to exit
*/
public async recordVideo(videoName, callback: () => Promise<any>): Promise<any> {
if (!this._storageByDeviceName) {
this._storageByDeviceName = getStorageByDeviceName(this._args);
}
return DeviceController.recordVideo((<IDevice>this._args.device), this._storageByDeviceName, videoName, callback);
}
private _recordVideoInfo;
/**
* @param videoName
*/
public startRecordingVideo(videoName) {
if (!this._logPath) {
this._logPath = getReportPath(this._args);
}
videoName = videoName.replace(/\s/gi, "");
console.log("DEVICE: ", this._args.device);
this._recordVideoInfo = DeviceController.startRecordingVideo(this._args.device, this._logPath, videoName);
this._recordVideoInfo['device'] = (<IDevice>this._args.device);
return this._recordVideoInfo['pathToVideo'];
}
public stopRecordingVideo(): Promise<any> {
this._recordVideoInfo['videoRecoringProcess'].kill("SIGINT");
wait(this.isIOS ? 100 : 10000);
if (this._args.device.type === DeviceType.EMULATOR || this._args.device.platform === Platform.ANDROID) {
AndroidController.pullFile(
this._recordVideoInfo['device'],
this._recordVideoInfo['devicePath'],
this._recordVideoInfo['pathToVideo'].endsWith(".mp4") ? this._recordVideoInfo['pathToVideo'] : `${this._recordVideoInfo['pathToVideo']}.mp4`);
wait(20000);
}
return Promise.resolve(this._recordVideoInfo['pathToVideo']);
}
private async compare(imageName: string, timeOutSeconds: number = 3, tolerance: number = 0.01, rect?: IRectangle, toleranceType?: ImageOptions) {
if (!this._logPath) {
this._logPath = getReportPath(this._args);
}
imageName = addExt(imageName, AppiumDriver.pngFileExt);
const pathExpectedImage = this.getExpectedImagePath(imageName);
// First time capture
if (!fileExists(pathExpectedImage)) {
const pathActualImage = resolve(this._storageByDeviceName, imageName.replace(".", "_actual."));
await this.takeScreenshot(pathActualImage);
if (rect) {
await this._imageHelper.clipRectangleImage(rect, pathActualImage);
}
const pathActualImageToReportsFolder = resolve(this._logPath, basename(pathActualImage));
copy(pathActualImage, pathActualImageToReportsFolder, false);
console.log("Remove the 'actual' suffix to continue using the image as expected one ", pathExpectedImage);
return false;
}
// Compare
let pathActualImage = await this.takeScreenshot(resolve(this._logPath, imageName.replace(".", "_actual.")));
const pathDiffImage = pathActualImage.replace("actual", "diff");
await this.prepareImageToCompare(pathActualImage, rect);
let result = await this._imageHelper.compareImages(pathActualImage, pathExpectedImage, pathDiffImage, tolerance, toleranceType);
// Iterate
if (!result) {
const eventStartTime = Date.now().valueOf();
let counter = 1;
timeOutSeconds *= 1000;
while ((Date.now().valueOf() - eventStartTime) <= timeOutSeconds && !result) {
const pathActualImageConter = resolve(this._logPath, imageName.replace(".", "_actual_" + counter + "."));
pathActualImage = await this.takeScreenshot(pathActualImageConter);
await this.prepareImageToCompare(pathActualImage, rect);
result = await this._imageHelper.compareImages(pathActualImage, pathExpectedImage, pathDiffImage, tolerance, toleranceType);
counter++;
}
} else {
if (fileExists(pathDiffImage)) {
unlinkSync(pathDiffImage);
}
if (fileExists(pathActualImage)) {
unlinkSync(pathActualImage);
}
}
this._imageHelper.imageCropRect = undefined;
return result;
}
public async prepareImageToCompare(filePath: string, rect: IRectangle) {
if (rect) {
await this._imageHelper.clipRectangleImage(rect, filePath);
const rectToCrop = { x: 0, y: 0, width: undefined, height: undefined };
this._imageHelper.imageCropRect = rectToCrop;
} else {
this._imageHelper.imageCropRect = ImageHelper.cropImageDefault(this._args);
}
}
public takeScreenshot(fileName: string) {
if (!fileName.endsWith(AppiumDriver.pngFileExt)) {
fileName = fileName.concat(AppiumDriver.pngFileExt);
}
return new Promise<string>((resolve, reject) => {
this._driver.takeScreenshot().then(
function (image, err) {
if (err) {
console.error(err);
reject(err);
}
writeFileSync(fileName, image, 'base64');
resolve(fileName);
}
)
});
}
public async logScreenshot(fileName: string) {
if (!this._logPath && !fileExists(fileName)) {
this._logPath = getReportPath(this._args);
}
if (!fileName.endsWith(AppiumDriver.pngFileExt)) {
fileName = fileName.concat(AppiumDriver.pngFileExt);
}
const imgPath = await this.takeScreenshot(resolve(this._logPath, fileName));
return imgPath;
}
public async logPageSource(fileName: string) {
if (!this._logPath && !fileExists(fileName)) {
this._logPath = getReportPath(this._args);
}
if (!fileName.endsWith(".xml")) {
fileName = fileName.concat(".xml");
}
const path = resolve(this._logPath, fileName);
const xml = await this.source();
writeFileSync(path, xml.value, 'utf8');
}
/**
* Send the currently active app to the background
* @param time
*/
public async backgroundApp(time: number) {
console.log("Sending the currently active app to the background ...");
await this._driver.backgroundApp(time);
}
public async resetApp() {
await this._driver.resetApp();
}
public async init() {
await this._driver.init(this._args.appiumCaps);
this._webio.requestHandler.sessionID = this._driver.sessionID;
this._isAlive = true;
}
public async quit() {
console.log("Killing driver");
if (this._recordVideoInfo && this._recordVideoInfo['videoRecoringProcess']) {
this._recordVideoInfo['videoRecoringProcess'].kill("SIGINT");
}
try {
await this._driver.quit();
await this._driver.quit();
await this._webio.quit();
} catch (error) {
}
this._isAlive = false;
console.log("Driver is dead");
}
private static async applyAdditionalSettings(args) {
if (args.isSauceLab) return;
args.appiumCaps['udid'] = args.appiumCaps['udid'] || args.device.token;
if (args.device.type === DeviceType.EMULATOR && args.device.token) {
args.appiumCaps['udid'] = args.device.token.startsWith("emulator") ? args.device.token : `emulator-${args.device.token}`;
}
if (!args.appiumCaps['udid']) {
delete args.appiumCaps['udid'];
}
if (args.appiumCaps.platformName.toLowerCase() === Platform.IOS) {
args.appiumCaps["useNewWDA"] = false;
args.appiumCaps["wdaStartupRetries"] = 5;
args.appiumCaps["shouldUseSingletonTestManager"] = false;
// It looks we need it for XCTest (iOS 10+ automation)
if (args.appiumCaps.platformVersion >= 10 && args.wdaLocalPort) {
console.log(`args.appiumCaps['wdaLocalPort']: ${args.wdaLocalPort}`);
args.appiumCaps["wdaLocalPort"] = args.wdaLocalPort;
}
} else {
if (process.env["SYSTEM_PORT"]) {
args.appiumCaps['systemPort'] = process.env["SYSTEM_PORT"];
}
}
}
private async convertArrayToUIElements(array, searchM, args) {
const arrayOfUIElements = new Array<UIElement>();
if (!array || array === null) {
return arrayOfUIElements;
}
for (let index = 0; index < array.length; index++) {
const element = array[index];
arrayOfUIElements.push(new UIElement(await element, this._driver, this._wd, this._webio, this._args, searchM, args, index));
}
return arrayOfUIElements;
}
private static configureLogging(driver, verbose) {
driver.on("status", function (info) {
log(info.cyan, verbose);
});
driver.on("command", function (meth, path, data) {
log(" > " + meth.yellow + path.grey + " " + (data || ""), verbose);
});
driver.on("http", function (meth, path, data) {
log(" > " + meth.magenta + path + " " + (data || "").grey, verbose);
});
};
private getExpectedImagePath(imageName: string) {
if (!this._storageByDeviceName) {
this._storageByDeviceName = getStorageByDeviceName(this._args);
}
let pathExpectedImage = resolve(this._storageByDeviceName, imageName);
if (!fileExists(pathExpectedImage)) {
if (!this._storageByPlatform) {
this._storageByPlatform = getStorageByPlatform(this._args);
}
pathExpectedImage = resolve(this._storageByPlatform, imageName);
}
if (!fileExists(pathExpectedImage)) {
pathExpectedImage = resolve(this._storageByDeviceName, imageName);
}
return pathExpectedImage;
}
/**
* Wait specific amount of time before continue execution
* @param miliseconds
*/
public async sleep(miliseconds: number) {
await this._driver.sleep(miliseconds);
}
/**
* Wait specific amount of time before continue execution
* @param miliseconds
*/
public wait(miliseconds: number) {
wait(miliseconds);
}
/**
* Search for element by given xPath but does not throw error if can not find it. Instead returns 'undefined'.
* @param xPath
* @param waitForElement
*/
public async findElementByXPathIfExists(xPath: string, waitForElement: number = this.defaultWaitTime) {
const element = await this._driver.elementByXPathIfExists(xPath, waitForElement);
if (element) {
const searchMethod = "elementByXPathIfExists";
return await new UIElement(element, this._driver, this._wd, this._webio, this._args, searchMethod, xPath);
} else {
return undefined;
}
}
/**
* Search for element by given text but does not throw error if can not find it. Instead returns 'undefined'.
* @param text
* @param match
* @param waitForElement
*/
public async findElementByTextIfExists(text: string, match: SearchOptions = SearchOptions.exact, waitForElement: number = this.defaultWaitTime) {
const shouldMatch = match === SearchOptions.exact ? true : false;
return await this.findElementByXPathIfExists(this._elementHelper.getXPathByText(text, shouldMatch), waitForElement);
}
/**
* Search for element by automationText but does not throw error if can not find it. Instead returns 'undefined'.
* @param id
* @param waitForElement
*/
public async findElementByAccessibilityIdIfExists(id: string, waitForElement: number = this.defaultWaitTime) {
const element = await this._driver.elementByAccessibilityIdIfExists(id, waitForElement);
if (element) {
const searchMethod = "elementByAccessibilityIdIfExists";
return await new UIElement(element, this._driver, this._wd, this._webio, this._args, searchMethod, id);
} else {
return undefined;
}
}
public async setDontKeepActivities(value: boolean) {
if (this._args.isAndroid) {
const output = await DeviceManager.setDontKeepActivities(this._args, this._driver, value);
} else {
// Do nothing for iOS ...
}
}
}