Skip to content

Commit f3bc15f

Browse files
Tsenov/animations (#112)
* feature: frame-comparer
1 parent 38ec681 commit f3bc15f

15 files changed

+79
-49
lines changed

lib/appium-driver.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ export class AppiumDriver {
419419

420420
public stopRecordingVideo(): Promise<any> {
421421
this._recordVideoInfo['videoRecoringProcess'].kill("SIGINT");
422-
423422
wait(this.isIOS ? 100 : 10000);
424423
if (this._args.device.type === DeviceType.EMULATOR || this._args.device.platform === Platform.ANDROID) {
425424
AndroidController.pullFile(
@@ -689,10 +688,10 @@ export class AppiumDriver {
689688
public async findElementByAccessibilityIdIfExists(id: string, waitForElement: number = this.defaultWaitTime) {
690689
const element = await this._driver.elementByAccessibilityIdIfExists(id, waitForElement);
691690
if (element) {
692-
const searchMethod = "elementByAccessibilityIdIfExists";
693-
return await new UIElement(element, this._driver, this._wd, this._webio, this._args, searchMethod, id);
691+
const searchMethod = "elementByAccessibilityIdIfExists";
692+
return await new UIElement(element, this._driver, this._wd, this._webio, this._args, searchMethod, id);
694693
} else {
695-
return undefined;
694+
return undefined;
696695
}
697696
}
698697

lib/appium-server.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ export declare class AppiumServer {
1818
start(port: any, deviceManager?: IDeviceManager): Promise<boolean>;
1919
private startAppiumServer(logLevel);
2020
stop(): Promise<{}>;
21+
private prepareDevice(deviceManager);
22+
private prepareApp();
2123
private resolveAppiumDependency();
2224
}

lib/appium-server.ts

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
fileExists,
88
isWin,
99
executeCommand,
10-
findFreePort
10+
findFreePort,
11+
getRegexResultsAsArray
1112
} from "./utils";
1213
import { INsCapabilities } from "./interfaces/ns-capabilities";
1314
import { IDeviceManager } from "./interfaces/device-manager";
@@ -57,40 +58,9 @@ export class AppiumServer {
5758
}
5859

5960
public async start(port, deviceManager: IDeviceManager = new DeviceManger()) {
60-
this._deviceManager = deviceManager;
61-
if (!this._args.device) {
62-
const device = await this._deviceManager.startDevice(this._args);
63-
this._args.device = device;
64-
}
65-
66-
if (this._args.devMode) {
67-
const appPackage = this._args.isAndroid ? "appPackage" : "bundleId";
68-
const appFullPath = this._args.appiumCaps.app;
69-
70-
if (appFullPath && !this._args.appiumCaps[appPackage]) {
71-
console.log(`Trying to resolve automatically ${appPackage}!`);
72-
this._args.appiumCaps[appPackage] = this._deviceManager.getPackageId(this._args.device, appFullPath);
73-
console.log(`Setting capabilities ${this._args.runType}{ "${appPackage}" : "${this._args.appiumCaps[appPackage]}" }!`);
74-
}
75-
76-
if (!this._args.appiumCaps[appPackage]) {
77-
throw new Error(`In order to use reuse app functionality, please set ${appPackage} in ${this._args.appiumCapsLocation} file!`);
78-
}
61+
await this.prepareDevice(deviceManager);
62+
await this.prepareApp();
7963

80-
this._args.appiumCaps.app = "";
81-
}
82-
83-
if (this._args.isAndroid && (!this._args.appiumCaps['appActivity'] || this._args.appiumCaps['appActivity'].trim() === "")) {
84-
if (fileExists(this._args.appPath)) {
85-
this._args.appiumCaps['appActivity'] = AndroidController.getLaunchableActivity(this._args.appPath);
86-
console.log(`Setting capabilities ${this._args.runType}{ "appActivity" : "${this._args.appiumCaps['appActivity']}" }!`);
87-
} else {
88-
console.error(`No launchable activity found. You should set it here ${this._args.appiumCapsLocation} in runType: ${this._args.runType}!`);
89-
}
90-
}
91-
if (!this._args.devMode) {
92-
this._deviceManager.installApp(this._args);
93-
}
9464
log("Starting server...", this._args.verbose);
9565
const logLevel = this._args.verbose === true ? "debug" : "info";
9666
this.port = port || this._args.port;
@@ -162,6 +132,39 @@ export class AppiumServer {
162132
});
163133
}
164134

135+
private async prepareDevice(deviceManager: IDeviceManager) {
136+
this._deviceManager = deviceManager;
137+
if (!this._args.device) {
138+
const device = await this._deviceManager.startDevice(this._args);
139+
this._args.device = device;
140+
}
141+
}
142+
143+
private async prepareApp() {
144+
const appPackage = this._args.isAndroid ? "appActivity" : "bundleId";
145+
const appFullPath = this._args.appiumCaps.app;
146+
147+
if (appFullPath && !this._args.appiumCaps[appPackage]) {
148+
console.log(`Trying to resolve automatically ${appPackage}!`);
149+
this._args.appiumCaps[appPackage] = this._deviceManager.getPackageId(this._args.device, appFullPath);
150+
console.log(`Setting capabilities ${this._args.runType}{ "${appPackage}" : "${this._args.appiumCaps[appPackage]}" }!`);
151+
}
152+
153+
if (!this._args.appiumCaps[appPackage]) {
154+
throw new Error(`Please, provide ${appPackage} in ${this._args.appiumCapsLocation} file!`);
155+
}
156+
157+
const groupings = getRegexResultsAsArray(/(\w+)/gi, this._args.appiumCaps[appPackage]);
158+
this._args.appName = groupings[groupings.length - 1];
159+
console.log(`Setting application name as ${this._args.appName}`);
160+
if (!this._args.devMode) {
161+
await this._deviceManager.uninstallApp(this._args);
162+
} else {
163+
this._args.appiumCaps.app = "";
164+
}
165+
166+
}
167+
165168
// Resolve appium dependency
166169
private resolveAppiumDependency() {
167170
const projectDir = this._args.projectDir;

lib/device-controller.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export declare class DeviceManger implements IDeviceManager {
77
startDevice(args: INsCapabilities): Promise<IDevice>;
88
stopDevice(args: INsCapabilities): Promise<any>;
99
installApp(args: INsCapabilities): Promise<any>;
10-
unInstallApp(args: INsCapabilities): Promise<any>;
10+
uninstallApp(args: INsCapabilities): Promise<any>;
1111
static kill(device: IDevice): Promise<void>;
1212
private static getDefaultDevice(args);
1313
getPackageId(device: IDevice, appPath: string): string;

lib/device-controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ export class DeviceManger implements IDeviceManager {
113113
}
114114
}
115115

116-
public async unInstallApp(args: INsCapabilities): Promise<any> {
116+
public async uninstallApp(args: INsCapabilities): Promise<any> {
117117
if (args.isIOS) {
118-
IOSController.uninstallApp(args.device, args.appiumCaps.app);
118+
await IOSController.uninstallApp(args.device, args.appiumCaps.app);
119119
} else {
120-
AndroidController.uninstallApp(args.device, args.appiumCaps.app)
120+
await Promise.resolve(AndroidController.uninstallApp(args.device, args.appiumCaps.app));
121121
}
122122
}
123123

lib/frame-comparer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class FrameComparer {
3232
}
3333

3434
async compareFrameRanges(imageFrameCount: number, startRange, endRange, logImageComparisonResults: boolean = false, tollerancePixels = 0.1, verbose = false): Promise<boolean> {
35-
const result = await this._frameComparer.compareImageFromVideo(resolve(this._storage, `${this._framesGeneralName}${imageFrameCount}.png`), this._logPath, startRange, endRange, tollerancePixels, true, logImageComparisonResults, this._cropImageRect, verbose);
35+
const result = await this._frameComparer.compareImageFromVideo(resolve(this._storage, `${this._framesGeneralName}${imageFrameCount}.png`), this._logPath, startRange, endRange, tollerancePixels, this._cropImageRect, true, logImageComparisonResults, verbose);
3636
return result;
3737
}
3838

lib/interfaces/device-manager.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export interface IDeviceManager {
44
startDevice(args: INsCapabilities): Promise<IDevice>;
55
stopDevice(args: INsCapabilities): Promise<IDevice>;
66
installApp(args: INsCapabilities): Promise<void>;
7-
unInstallApp(args: INsCapabilities): Promise<void>;
7+
uninstallApp(args: INsCapabilities): Promise<void>;
88
getPackageId(device: any, appPath: any): string;
99
}

lib/interfaces/device-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export interface IDeviceManager {
55
startDevice(args: INsCapabilities): Promise<IDevice>
66
stopDevice(args: INsCapabilities): Promise<IDevice>
77
installApp(args: INsCapabilities): Promise<void>;
8-
unInstallApp(args: INsCapabilities): Promise<void>;
8+
uninstallApp(args: INsCapabilities): Promise<void>;
99
getPackageId(device, appPath): string;
1010
}

lib/interfaces/ns-capabilities.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface INsCapabilities {
1414
isIOS: boolean;
1515
isSauceLab: boolean;
1616
appPath: string;
17+
appName: string;
1718
emulatorOptions: string;
1819
storage: string;
1920
testReports: string;

lib/interfaces/ns-capabilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface INsCapabilities {
1515
isIOS: boolean;
1616
isSauceLab: boolean;
1717
appPath: string;
18+
appName: string;
1819
emulatorOptions: string;
1920
storage: string;
2021
testReports: string;

0 commit comments

Comments
 (0)