Skip to content

Commit 74d11bb

Browse files
Include guard for minimum required configurations.
1 parent c292f87 commit 74d11bb

File tree

5 files changed

+76
-23
lines changed

5 files changed

+76
-23
lines changed

e2e/config/appium.capabilities.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"lt": 60000,
88
"appActivity": "com.tns.NativeScriptActivity",
99
"newCommandTimeout": 720,
10-
"noReset": false,
11-
"fullReset": true,
10+
"noReset": true,
11+
"fullReset": false,
1212
"app": ""
1313
},
1414
"android21": {
@@ -19,8 +19,8 @@
1919
"lt": 60000,
2020
"appActivity": "com.tns.NativeScriptActivity",
2121
"newCommandTimeout": 720,
22-
"noReset": false,
23-
"fullReset": true,
22+
"noReset": true,
23+
"fullReset": false,
2424
"app": ""
2525
},
2626
"android23": {
@@ -31,8 +31,8 @@
3131
"lt": 60000,
3232
"appActivity": "com.tns.NativeScriptActivity",
3333
"newCommandTimeout": 720,
34-
"noReset": false,
35-
"fullReset": true,
34+
"noReset": true,
35+
"fullReset": false,
3636
"app": ""
3737
},
3838
"android24": {
@@ -43,8 +43,8 @@
4343
"lt": 60000,
4444
"appActivity": "com.tns.NativeScriptActivity",
4545
"newCommandTimeout": 720,
46-
"noReset": false,
47-
"fullReset": true,
46+
"noReset": true,
47+
"fullReset": false,
4848
"app": ""
4949
},
5050
"android25": {
@@ -55,8 +55,8 @@
5555
"lt": 60000,
5656
"appActivity": "com.tns.NativeScriptActivity",
5757
"newCommandTimeout": 720,
58-
"noReset": false,
59-
"fullReset": true,
58+
"noReset": true,
59+
"fullReset": false,
6060
"app": ""
6161
},
6262
"android26": {
@@ -67,8 +67,8 @@
6767
"lt": 60000,
6868
"appActivity": "com.tns.NativeScriptActivity",
6969
"newCommandTimeout": 720,
70-
"noReset": false,
71-
"fullReset": true,
70+
"noReset": true,
71+
"fullReset": false,
7272
"app": ""
7373
},
7474
"sim.iPhone7.iOS100": {

lib/appium-driver.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,6 @@ export class AppiumDriver {
340340
const driver = await wd.promiseChainRemote(driverConfig);
341341
AppiumDriver.configureLogging(driver, args.verbose);
342342

343-
if (args.appPath) {
344-
args.appiumCaps.app = args.appPath;
345-
}
346-
347-
if (!args.appiumCaps.app) {
348-
log("Getting caps.app!", args.verbose);
349-
args.appiumCaps.app = getAppPath(args.appiumCaps.platformName.toLowerCase(), args.runType.toLowerCase());
350-
}
351-
352343
if (args.isSauceLab) {
353344
const sauceUser = process.env.SAUCE_USER;
354345
const sauceKey = process.env.SAUCE_KEY;
@@ -362,6 +353,7 @@ export class AppiumDriver {
362353
}
363354

364355
args.appiumCaps.app = "sauce-storage:" + args.appiumCaps.app
356+
console.log("Using Sauce Labs. The application path is changed to: " + args.appiumCaps.app);
365357
}
366358

367359
log("Creating driver!", args.verbose);

lib/appium-server.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as child_process from "child_process";
2-
import { log, resolve, waitForOutput, shutdown, fileExists, isWin } from "./utils";
2+
import { log, resolve, waitForOutput, shutdown, fileExists, isWin, executeCommand } from "./utils";
33
import { INsCapabilities } from "./ins-capabilities";
44
import { SimulatorManager } from "./simulator-manager";
55
import { EmulatorManager } from "./emulator-manager";
@@ -132,7 +132,14 @@ export class AppiumServer {
132132
log("Using project-local Appium binary.", this._args.verbose);
133133
appium = projectAppiumBinary;
134134
} else {
135-
log("Using global Appium binary.", this._args.verbose);
135+
const result = executeCommand("npm list -g");
136+
if (result.includes("appium")) {
137+
log("Using global Appium binary.", this._args.verbose);
138+
} else if (result.includes("appium")) {
139+
const msg = "Appium not found. Please install appium before runnig tests!";
140+
log(msg, this._args.verbose);
141+
new Error(msg);
142+
}
136143
}
137144

138145
this._appium = appium;

lib/ns-capabilities.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export declare class NsCapabilities implements INsCapabilities {
1616
private _isSauceLab;
1717
private _appPath;
1818
private _emulatorOptions;
19+
private exceptions;
1920
constructor();
2021
readonly projectDir: any;
2122
readonly projectBinary: any;
@@ -33,4 +34,7 @@ export declare class NsCapabilities implements INsCapabilities {
3334
readonly isSauceLab: any;
3435
appPath: string;
3536
readonly emulatorOptions: string;
37+
private resolveAppPath();
38+
private checkMendatoryCapabiliies();
39+
private throwExceptions();
3640
}

lib/ns-capabilities.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as parser from "./parser"
22
import { INsCapabilities } from "./ins-capabilities";
33
import { resolveCapabilities } from "./capabilities-helper";
4+
import { getAppPath, fileExists, logErr } from "./utils";
45

56
export class NsCapabilities implements INsCapabilities {
67
private _projectDir;
@@ -19,6 +20,7 @@ export class NsCapabilities implements INsCapabilities {
1920
private _isSauceLab;
2021
private _appPath: string;
2122
private _emulatorOptions: string;
23+
private exceptions: Array<string> = new Array();
2224

2325
constructor() {
2426
this._projectDir = parser.projectDir;
@@ -36,6 +38,8 @@ export class NsCapabilities implements INsCapabilities {
3638
this._runType = parser.runType;
3739
this._isSauceLab = parser.isSauceLab;
3840
this._appiumCaps = resolveCapabilities(this._appiumCapsLocation, parser.runType, parser.projectDir);
41+
this.resolveAppPath();
42+
this.checkMendatoryCapabiliies()
3943
}
4044

4145
get projectDir() { return this._projectDir; }
@@ -55,4 +59,50 @@ export class NsCapabilities implements INsCapabilities {
5559
get appPath() { return this._appPath; }
5660
set appPath(appPath: string) { this._appPath = appPath; }
5761
get emulatorOptions() { return (this._emulatorOptions || "-wipe-data -gpu on") }
62+
63+
private resolveAppPath() {
64+
65+
if (this._appPath) {
66+
this._appiumCaps.app = this._appPath;
67+
}
68+
69+
if (!this._appiumCaps.app) {
70+
this._appiumCaps.app = getAppPath(this._appiumCaps.platformName.toLowerCase(), this._runType.toLowerCase());
71+
}
72+
73+
console.log("Application full path: " + this._appiumCaps.app);
74+
}
75+
76+
private checkMendatoryCapabiliies() {
77+
if (!fileExists(this._appiumCaps.appPath)) {
78+
this.exceptions.push("The application folder doesn't exist!");
79+
}
80+
81+
if (!this._appiumCaps._runType) {
82+
this.exceptions.push("Missing runType! Please select one from appium capabilities file!");
83+
}
84+
85+
if (this._appiumCaps.platformName) {
86+
this.exceptions.push("Platform name is missing! Please, check appium capabilities file!");
87+
}
88+
89+
if (this._appiumCaps.platformName) {
90+
this.exceptions.push("Platform version is missing! Please, check appium capabilities file!");
91+
}
92+
93+
if (this._appiumCaps.deviceName && this._appiumCaps.uidid) {
94+
this.exceptions.push("The device name or uidid are missing! Please, check appium capabilities file!");
95+
}
96+
}
97+
98+
private throwExceptions() {
99+
this.exceptions.forEach(msg => {
100+
logErr(msg, true);
101+
});
102+
103+
if (this.exceptions.length > 0) {
104+
const messagesString = this.exceptions.length > 1 ? "messages" : "message";
105+
throw new Error(`See the ${messagesString} above and fullfill the conditions!!!`);
106+
}
107+
}
58108
}

0 commit comments

Comments
 (0)