Skip to content

Commit d387f0d

Browse files
chore: fix some typos and imports (#186)
1 parent 1860883 commit d387f0d

17 files changed

+220
-252
lines changed

lib/appium-driver.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export declare class AppiumDriver {
7474
*/
7575
findElementsByXPath(xPath: string, waitForElement?: number): Promise<UIElement[]>;
7676
/**
77-
* Search for element by given text. The seacrch is case insensitive for android
77+
* Search for element by given text. The search is case insensitive for android
7878
* @param text
7979
* @param match
8080
* @param waitForElement
@@ -89,17 +89,17 @@ export declare class AppiumDriver {
8989
/**
9090
* Search for element by given automationText and waits until the element is displayed.
9191
* @param text
92-
* @param waitInMiliseconds till element is displayed
92+
* @param waitInMilliseconds till element is displayed
9393
*/
94-
waitForElement(automationText: string, waitInMiliseconds?: number): Promise<UIElement>;
94+
waitForElement(automationText: string, waitInMilliseconds?: number): Promise<UIElement>;
9595
/**
9696
* Search for elements by given automationText. Searches only for exact string. Returns promise with array of elements.
9797
* @param text
9898
* @param waitForElement
9999
*/
100100
findElementsByAutomationText(automationText: string, waitForElement?: number): Promise<UIElement[]>;
101101
/**
102-
* Search for elements by given text. The seacrch is case insensitive for android
102+
* Search for elements by given text. The search is case insensitive for android
103103
* @param text
104104
* @param match
105105
* @param waitForElement
@@ -207,14 +207,14 @@ export declare class AppiumDriver {
207207
private getExpectedImagePath;
208208
/**
209209
* Wait specific amount of time before continue execution
210-
* @param miliseconds
210+
* @param milliseconds
211211
*/
212-
sleep(miliseconds: number): Promise<void>;
212+
sleep(milliseconds: number): Promise<void>;
213213
/**
214214
* Wait specific amount of time before continue execution
215-
* @param miliseconds
215+
* @param milliseconds
216216
*/
217-
wait(miliseconds: number): void;
217+
wait(milliseconds: number): void;
218218
/**
219219
* Search for element by given xPath but does not throw error if can not find it. Instead returns 'undefined'.
220220
* @param xPath

lib/appium-driver.ts

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import {
2323
log,
2424
getStorageByPlatform,
2525
getStorageByDeviceName,
26-
resolve,
27-
fileExists,
26+
resolvePath,
2827
getReportPath,
2928
scroll,
3029
findFreePort,
@@ -44,7 +43,7 @@ import { IRectangle } from "./interfaces/rectangle";
4443
import { Point } from "./point";
4544
import { ImageHelper } from "./image-helper";
4645
import { ImageOptions } from "./image-options"
47-
import { unlinkSync, writeFileSync } from "fs";
46+
import { unlinkSync, writeFileSync, existsSync } from "fs";
4847
import { DeviceManager } from "../lib/device-manager";
4948
import { extname, basename } from "path";
5049
import { LogType } from "./log-types";
@@ -228,39 +227,39 @@ export class AppiumDriver {
228227
let retries = 10;
229228
while (retries > 0 && !hasStarted) {
230229
try {
231-
let sessionIfno;
230+
let sessionInfo;
232231

233232
try {
234233
if (args.sessionId || args.attachToDebug) {
235-
const sessionIfnos = JSON.parse(((await getSessions(args.port)) || "{}") + '');
234+
const sessionInfos = JSON.parse(((await getSessions(args.port)) || "{}") + '');
236235

237-
sessionIfno = sessionIfnos.value.filter(value => args.sessionId ? args.sessionId === value.id : true)[0];
238-
if (!sessionIfno || !sessionIfno.id) {
239-
logError("No info suitable session found", sessionIfno);
236+
sessionInfo = sessionInfos.value.filter(value => args.sessionId ? args.sessionId === value.id : true)[0];
237+
if (!sessionInfo || !sessionInfo.id) {
238+
logError("No suitable session info found", sessionInfo);
240239
process.exit(1);
241240
}
242241

243-
args.sessionId = sessionIfno.id;
244-
args.appiumCaps = sessionIfno.capabilities;
245-
// remove app to prevent appium installiing it again
242+
args.sessionId = sessionInfo.id;
243+
args.appiumCaps = sessionInfo.capabilities;
244+
// remove app to prevent appium from installing app again
246245
args.appiumCaps.app = "";
247246

248-
if (sessionIfno.capabilities.automationName) {
249-
(<any>args).setAutomationNameFromString(sessionIfno.capabilities.automationName);
247+
if (sessionInfo.capabilities.automationName) {
248+
(<any>args).setAutomationNameFromString(sessionInfo.capabilities.automationName);
250249
}
251250

252251
prepareApp(args);
253252
if (!args.device) {
254253
if (args.isAndroid) {
255-
args.device = DeviceManager.getDefaultDevice(args, sessionIfno.capabilities.avd, sessionIfno.capabilities.deviceUDID.replace("emulator-", ""), sessionIfno.capabilities.deviceUDID.includes("emulator") ? DeviceType.EMULATOR : DeviceType.SIMULATOR, sessionIfno.capabilities.desired.platformVersion || sessionIfno.capabilities.platformVersion);
254+
args.device = DeviceManager.getDefaultDevice(args, sessionInfo.capabilities.avd, sessionInfo.capabilities.deviceUDID.replace("emulator-", ""), sessionInfo.capabilities.deviceUDID.includes("emulator") ? DeviceType.EMULATOR : DeviceType.SIMULATOR, sessionInfo.capabilities.desired.platformVersion || sessionInfo.capabilities.platformVersion);
256255
} else {
257256
args.device = DeviceManager.getDefaultDevice(args);
258257
}
259258
}
260259

261260
await driver.attach(args.sessionId);
262261
} else {
263-
sessionIfno = await driver.init(args.appiumCaps);
262+
sessionInfo = await driver.init(args.appiumCaps);
264263
}
265264

266265
} catch (error) {
@@ -272,10 +271,10 @@ export class AppiumDriver {
272271
}
273272
if (args.verbose) {
274273
logInfo("Session info");
275-
console.info(sessionIfno);
274+
console.info(sessionInfo);
276275
}
277276

278-
await DeviceManager.applyDeviceAdditionsSettings(driver, args, sessionIfno);
277+
await DeviceManager.applyDeviceAdditionsSettings(driver, args, sessionInfo);
279278

280279
hasStarted = true;
281280
} catch (error) {
@@ -321,7 +320,7 @@ export class AppiumDriver {
321320
}
322321

323322
/**
324-
* Search for element by given text. The seacrch is case insensitive for android
323+
* Search for element by given text. The search is case insensitive for android
325324
* @param text
326325
* @param match
327326
* @param waitForElement
@@ -346,22 +345,22 @@ export class AppiumDriver {
346345
/**
347346
* Search for element by given automationText and waits until the element is displayed.
348347
* @param text
349-
* @param waitInMiliseconds till element is displayed
348+
* @param waitInMilliseconds till element is displayed
350349
*/
351-
public async waitForElement(automationText: string, waitInMiliseconds: number = this.defaultWaitTime): Promise<UIElement> {
350+
public async waitForElement(automationText: string, waitInMilliseconds: number = this.defaultWaitTime): Promise<UIElement> {
352351
let element;
353352
try {
354353
element = await this.findElementByAutomationText(automationText, 100);
355354
} catch (error) { }
356355
const startTime = Date.now();
357-
while ((!element || !(await element.isDisplayed())) && Date.now() - startTime <= waitInMiliseconds) {
356+
while ((!element || !(await element.isDisplayed())) && Date.now() - startTime <= waitInMilliseconds) {
358357
try {
359358
element = await this.findElementByAutomationText(automationText, 100);
360359
} catch (error) { }
361360
}
362361

363362
if (!element || !await element.isDisplayed()) {
364-
const msg = `Element with automationText: '${automationText}' is not dislpayed after ${waitInMiliseconds} milliseconds.`;
363+
const msg = `Element with automationText: '${automationText}' is not displayed after ${waitInMilliseconds} milliseconds.`;
365364
logInfo(msg);
366365
}
367366

@@ -381,7 +380,7 @@ export class AppiumDriver {
381380
}
382381

383382
/**
384-
* Search for elements by given text. The seacrch is case insensitive for android
383+
* Search for elements by given text. The search is case insensitive for android
385384
* @param text
386385
* @param match
387386
* @param waitForElement
@@ -583,23 +582,23 @@ export class AppiumDriver {
583582
const pathExpectedImage = this.getExpectedImagePath(imageName);
584583

585584
// First time capture
586-
if (!fileExists(pathExpectedImage)) {
587-
const pathActualImage = resolve(this._storageByDeviceName, imageName.replace(".", "_actual."));
585+
if (!existsSync(pathExpectedImage)) {
586+
const pathActualImage = resolvePath(this._storageByDeviceName, imageName.replace(".", "_actual."));
588587
await this.takeScreenshot(pathActualImage);
589588

590589
if (rect) {
591590
await this._imageHelper.clipRectangleImage(rect, pathActualImage);
592591
}
593592

594-
const pathActualImageToReportsFolder = resolve(this._logPath, basename(pathActualImage));
593+
const pathActualImageToReportsFolder = resolvePath(this._logPath, basename(pathActualImage));
595594
copy(pathActualImage, pathActualImageToReportsFolder, false);
596595

597596
console.log("Remove the 'actual' suffix to continue using the image as expected one ", pathExpectedImage);
598597
return false;
599598
}
600599

601600
// Compare
602-
let pathActualImage = await this.takeScreenshot(resolve(this._logPath, imageName.replace(".", "_actual.")));
601+
let pathActualImage = await this.takeScreenshot(resolvePath(this._logPath, imageName.replace(".", "_actual.")));
603602
const pathDiffImage = pathActualImage.replace("actual", "diff");
604603

605604
await this.prepareImageToCompare(pathActualImage, rect);
@@ -611,18 +610,18 @@ export class AppiumDriver {
611610
let counter = 1;
612611
timeOutSeconds *= 1000;
613612
while ((Date.now().valueOf() - eventStartTime) <= timeOutSeconds && !result) {
614-
const pathActualImageConter = resolve(this._logPath, imageName.replace(".", "_actual_" + counter + "."));
613+
const pathActualImageConter = resolvePath(this._logPath, imageName.replace(".", "_actual_" + counter + "."));
615614
pathActualImage = await this.takeScreenshot(pathActualImageConter);
616615

617616
await this.prepareImageToCompare(pathActualImage, rect);
618617
result = await this._imageHelper.compareImages(pathActualImage, pathExpectedImage, pathDiffImage, tolerance, toleranceType);
619618
counter++;
620619
}
621620
} else {
622-
if (fileExists(pathDiffImage)) {
621+
if (existsSync(pathDiffImage)) {
623622
unlinkSync(pathDiffImage);
624623
}
625-
if (fileExists(pathActualImage)) {
624+
if (existsSync(pathActualImage)) {
626625
unlinkSync(pathActualImage);
627626
}
628627
}
@@ -668,7 +667,7 @@ export class AppiumDriver {
668667
fileName = fileName.concat(AppiumDriver.pngFileExt);
669668
}
670669

671-
const imgPath = await this.takeScreenshot(resolve(this._logPath, fileName));
670+
const imgPath = await this.takeScreenshot(resolvePath(this._logPath, fileName));
672671
return imgPath;
673672
}
674673

@@ -685,7 +684,7 @@ export class AppiumDriver {
685684
fileName = fileName.concat(".xml");
686685
}
687686

688-
const path = resolve(this._logPath, fileName);
687+
const path = resolvePath(this._logPath, fileName);
689688
const xml = await this.source();
690689
writeFileSync(path, xml.value, 'utf8');
691690
}
@@ -719,7 +718,7 @@ export class AppiumDriver {
719718
this._logPath = getReportPath(this._args);
720719
}
721720

722-
const path = resolve(this._logPath, fileName);
721+
const path = resolvePath(this._logPath, fileName);
723722
writeFileSync(path, deviceLog, 'utf8');
724723
} else {
725724
console.log(`Log type: ${logType} is empty!`);
@@ -763,8 +762,8 @@ export class AppiumDriver {
763762

764763
public async quit() {
765764
console.log("Killing driver");
766-
if (this._recordVideoInfo && this._recordVideoInfo['videoRecoringProcess']) {
767-
this._recordVideoInfo['videoRecoringProcess'].kill("SIGINT");
765+
if (this._recordVideoInfo && this._recordVideoInfo['videoRecordingProcess']) {
766+
this._recordVideoInfo['videoRecordingProcess'].kill("SIGINT");
768767
}
769768
try {
770769
if (!this._args.attachToDebug) {
@@ -834,41 +833,40 @@ export class AppiumDriver {
834833
};
835834

836835
private getExpectedImagePath(imageName: string) {
837-
838836
if (!this._storageByDeviceName) {
839837
this._storageByDeviceName = getStorageByDeviceName(this._args);
840838
}
841839

842-
let pathExpectedImage = resolve(this._storageByDeviceName, imageName);
840+
let pathExpectedImage = resolvePath(this._storageByDeviceName, imageName);
843841

844-
if (!fileExists(pathExpectedImage)) {
842+
if (!existsSync(pathExpectedImage)) {
845843
if (!this._storageByPlatform) {
846844
this._storageByPlatform = getStorageByPlatform(this._args);
847845
}
848-
pathExpectedImage = resolve(this._storageByPlatform, imageName);
846+
pathExpectedImage = resolvePath(this._storageByPlatform, imageName);
849847
}
850848

851-
if (!fileExists(pathExpectedImage)) {
852-
pathExpectedImage = resolve(this._storageByDeviceName, imageName);
849+
if (!existsSync(pathExpectedImage)) {
850+
pathExpectedImage = resolvePath(this._storageByDeviceName, imageName);
853851
}
854852

855853
return pathExpectedImage;
856854
}
857855

858856
/**
859857
* Wait specific amount of time before continue execution
860-
* @param miliseconds
858+
* @param milliseconds
861859
*/
862-
public async sleep(miliseconds: number) {
863-
await this._driver.sleep(miliseconds);
860+
public async sleep(milliseconds: number) {
861+
await this._driver.sleep(milliseconds);
864862
}
865863

866864
/**
867865
* Wait specific amount of time before continue execution
868-
* @param miliseconds
866+
* @param milliseconds
869867
*/
870-
public wait(miliseconds: number) {
871-
wait(miliseconds);
868+
public wait(milliseconds: number) {
869+
wait(milliseconds);
872870
}
873871

874872

@@ -936,7 +934,7 @@ export class AppiumDriver {
936934
const imageName = addExt(image, AppiumDriver.pngFileExt);
937935
const pathExpectedImage = this.getExpectedImagePath(imageName);
938936

939-
if (!fileExists(pathExpectedImage)) {
937+
if (!existsSync(pathExpectedImage)) {
940938
throw new Error("The provided image does not exist!!!");
941939
}
942940
const imageAsBase64 = encodeImageToBase64(pathExpectedImage);

lib/appium-server.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as child_process from "child_process";
22
import {
33
log,
4-
resolve,
4+
resolvePath,
55
waitForOutput,
66
shutdown,
7-
fileExists,
87
isWin,
98
findFreePort,
109
logWarn,
@@ -15,6 +14,7 @@ import {
1514
import { INsCapabilities } from "./interfaces/ns-capabilities";
1615
import { IDeviceManager } from "./interfaces/device-manager";
1716
import { DeviceManager } from "./device-manager";
17+
import { existsSync } from "fs";
1818

1919
export class AppiumServer {
2020
private _server: child_process.ChildProcess;
@@ -177,13 +177,13 @@ export class AppiumServer {
177177
this._appium = appium;
178178
return;
179179
}
180-
const pluginAppiumBinary = resolve(pluginBinary, appium);
181-
const projectAppiumBinary = resolve(projectBinary, appium);
180+
const pluginAppiumBinary = resolvePath(pluginBinary, appium);
181+
const projectAppiumBinary = resolvePath(projectBinary, appium);
182182

183-
if (fileExists(pluginAppiumBinary)) {
183+
if (existsSync(pluginAppiumBinary)) {
184184
logInfo("Using plugin-local Appium binary.", this._args.verbose);
185185
appium = pluginAppiumBinary;
186-
} else if (fileExists(projectAppiumBinary)) {
186+
} else if (existsSync(projectAppiumBinary)) {
187187
logInfo("Using project-local Appium binary.", this._args.verbose);
188188
appium = projectAppiumBinary;
189189
} else {

0 commit comments

Comments
 (0)