Skip to content

Commit 51446b1

Browse files
fix: resolve app path (#97)
1 parent c847536 commit 51446b1

File tree

3 files changed

+42
-31
lines changed

3 files changed

+42
-31
lines changed

lib/image-helper.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export declare class ImageHelper {
1010
blockOutAreas: IRectangle[];
1111
imageOutputLimit(): ImageOptions;
1212
thresholdType(): ImageOptions;
13-
threshold(thresholdType: any): 10 | 0.01;
13+
threshold(thresholdType: any): 0.01 | 10;
1414
delta(): number;
1515
static cropImageDefault(_args: INsCapabilities): {
1616
x: number;

lib/ns-capabilities.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,7 @@ export class NsCapabilities implements INsCapabilities {
8080
private isAndroidPlatform() { return this._appiumCaps.platformName.toLowerCase().includes("android"); }
8181

8282
private resolveAppPath() {
83-
if (this._appPath) {
84-
this._appiumCaps.app = this._appPath;
85-
}
86-
87-
if (!this._appiumCaps.app) {
88-
this._appiumCaps.app = getAppPath(this);
89-
}
83+
this._appiumCaps.app = getAppPath(this);
9084
console.log("Application full path: " + this._appiumCaps.app);
9185
}
9286

lib/utils.ts

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -287,32 +287,49 @@ function getAppName(args: INsCapabilities) {
287287
}
288288

289289
export function getAppPath(caps: INsCapabilities) {
290-
if (caps.appiumCaps.platformName.toLowerCase().includes("android")) {
291-
//platforms/android/build/outputs/apk/
292-
//platforms/android/app/build/outputs/apk
293-
let apks = glob.sync("platforms/android/build/outputs/apk/*.apk").filter(function (file) { return file.indexOf("unaligned") < 0; });
294-
if (!apks || apks.length === 0) {
295-
apks = glob.sync("platforms/android/app/build/outputs/apk/*.apk").filter(function (file) { return file.indexOf("unaligned") < 0; });
296-
}
297-
if (!apks || apks.length === 0) {
298-
apks = glob.sync(`${caps.projectDir}/platforms/android/app/build/outputs/apk/*.apk`).filter(function (file) { return file.indexOf("unaligned") < 0; });
299-
}
300-
return apks[0];
301-
} else if (caps.appiumCaps.platformName.toLowerCase().includes("ios")) {
302-
let path = "platforms/ios/build/emulator/**/*.app";
303-
if (caps.runType.includes("device")) {
304-
path = "platforms/ios/build/device/**/*.ipa";
305-
}
290+
let basePath = caps.appPath;
291+
if (isFile(basePath)) {
292+
return basePath;
293+
}
294+
295+
// try to resolve app automatically
296+
if (!fs.existsSync(basePath)) {
297+
if (caps.appiumCaps.platformName.toLowerCase().includes("android")) {
298+
const androidPlatformsPath = 'platforms/android';
299+
//platforms/android/build/outputs/apk/
300+
//platforms/android/app/build/outputs/apk
301+
//platforms/android/app/build/outputs/apk
302+
// /release
303+
// /debug
304+
305+
basePath = `${androidPlatformsPath}/app/build/outputs/apk/**/*.apk`;
306+
if (!fs.existsSync(`${androidPlatformsPath}/app/build/outputs/apk`)) {
307+
basePath = `${androidPlatformsPath}/build/outputs/apk/**/*.apk`;
308+
}
309+
} else if (caps.appiumCaps.platformName.toLowerCase().includes("ios")) {
310+
const iosPlatformsPath = 'platforms/ios';
311+
basePath = `${iosPlatformsPath}/build/emulator/**/*.app`;
312+
if (caps.runType.includes("device")) {
313+
basePath = `${iosPlatformsPath}/build/device/**/*.ipa`;
314+
}
306315

307-
let apps = glob.sync("platforms/ios/build/device/**/*.ipa");
308-
if (!apps || apps.length === 0) {
309-
apps = glob.sync(`${caps.projectDir}/${path}`).filter(function (file) { return file.indexOf("unaligned") < 0; });
316+
} else {
317+
throw new Error("No 'app' capability provided and incorrect 'runType' convention used: " + caps.runType +
318+
". In order to automatically search and locate app package please use 'android','device','sim' in your 'runType' option. E.g --runType android25, --runType sim.iPhone7.iOS110");
310319
}
311-
return apps[0];
312-
} else {
313-
throw new Error("No 'app' capability provided and incorrect 'runType' convention used: " + caps.runType +
314-
". In order to automatically search and locate app package please use 'android','device','sim' in your 'runType' option. E.g --runType android25, --runType sim.iPhone7.iOS110");
315320
}
321+
322+
let apps = glob.sync(basePath);
323+
324+
if (!apps || apps.length === 0) {
325+
apps = glob.sync(`${caps.projectDir}`)
326+
.filter(function (file) {
327+
return file.endsWith(".ipa") || file.endsWith(".app") || file.endsWith(".apk")
328+
});
329+
}
330+
331+
console.log(`Available apks:`, apps);
332+
return apps[0];
316333
}
317334

318335
export function calculateOffset(direction, y: number, yOffset: number, x: number, xOffset: number, isIOS: boolean, verbose) {

0 commit comments

Comments
 (0)