Skip to content

Commit 5c40e3b

Browse files
refactor: remove --reuseDevice option (#182)
BREAKING CHANGES: There will be no longer --reuseDevice option available. From now on will be preserved options from appium caps "fullReset" Migration steps: To reuse device set in your Appium capabilities file <b>"fullReset": false</b> Not to reuse device set <b>"fullReset": true</b>
1 parent e98799b commit 5c40e3b

File tree

9 files changed

+105
-47
lines changed

9 files changed

+105
-47
lines changed

index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ export async function stopServer() {
8383
await appiumServer.stop();
8484
}
8585

86-
if (nsCapabilities.cleanApp) {
86+
if (nsCapabilities.cleanApp && !nsCapabilities.ignoreDeviceController) {
8787
await DeviceController.uninstallApp(nsCapabilities.device, nsCapabilities.appPath);
88+
logInfo("Application from device is uninstalled.")
8889
}
8990
};
9091

lib/device-manager.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { INsCapabilities } from "./interfaces/ns-capabilities";
22
import { IDeviceManager } from "./interfaces/device-manager";
3-
import { IDevice, DeviceType } from "mobile-devices-controller";
3+
import { IDevice, Device, DeviceType } from "mobile-devices-controller";
44
export declare class DeviceManager implements IDeviceManager {
55
private static _emulators;
66
constructor();
@@ -9,7 +9,7 @@ export declare class DeviceManager implements IDeviceManager {
99
installApp(args: INsCapabilities): Promise<any>;
1010
uninstallApp(args: INsCapabilities): Promise<any>;
1111
static kill(device: IDevice): Promise<void>;
12-
static getDefaultDevice(args: INsCapabilities, deviceName?: string, token?: string, type?: DeviceType, platformVersion?: number): any;
12+
static getDefaultDevice(args: INsCapabilities, deviceName?: string, token?: string, type?: DeviceType, platformVersion?: number): Device;
1313
static setDontKeepActivities(args: INsCapabilities, driver: any, value: any): Promise<void>;
1414
static executeShellCommand(driver: any, commandAndargs: {
1515
command: string;

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: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export class NsCapabilities implements INsCapabilities {
5858
this._testFolder = this._parser.testFolder;
5959
this._storage = this._parser.storage;
6060
this._testReports = this._parser.testReports;
61-
this._reuseDevice = this._parser.reuseDevice;
6261
this._devMode = this._parser.devMode;
6362
this._runType = this._parser.runType;
6463
this._isSauceLab = this._parser.isSauceLab;
@@ -116,7 +115,7 @@ export class NsCapabilities implements INsCapabilities {
116115
//set isValidated(isValidated: boolean) { this._isValidated = isValidated; }
117116

118117
setAutomationNameFromString(automationName: String) {
119-
const key = Object.keys(AutomationName).filter((v,i,a) => v.toLowerCase() === automationName.toLowerCase());
118+
const key = Object.keys(AutomationName).filter((v, i, a) => v.toLowerCase() === automationName.toLowerCase());
120119
this._automationName = AutomationName[key[0]];
121120
}
122121

@@ -134,6 +133,7 @@ export class NsCapabilities implements INsCapabilities {
134133
if (this._attachToDebug || this._sessionId) {
135134
this._isValidated = true;
136135
}
136+
137137
if (!this._attachToDebug && !this._sessionId) {
138138
this._appiumCaps = resolveCapabilities(this.appiumCapsLocation, this.runType, this.projectDir, this._capabilitiesName);
139139

@@ -151,10 +151,15 @@ export class NsCapabilities implements INsCapabilities {
151151
private isAndroidPlatform() { return this._appiumCaps && this._appiumCaps ? this._appiumCaps.platformName.toLowerCase().includes("android") : undefined; }
152152

153153
private shouldSetFullResetOption() {
154-
if (this._ignoreDeviceController) {
155-
this.appiumCaps["fullReset"] = true;
156-
this.appiumCaps["noReset"] = false;
157-
logInfo("Changing appium setting fullReset: true and noReset: false ");
154+
if (!this._ignoreDeviceController) {
155+
this._reuseDevice = !this.appiumCaps["fullReset"];
156+
this.appiumCaps["fullReset"] = false;
157+
if(!this.reuseDevice){
158+
logWarn("The started device will be killed after the session!");
159+
logInfo("To avoid it, set 'fullReset: false' in appium capabilities.");
160+
}
161+
162+
this._cleanApp = !this.appiumCaps["noReset"];
158163
}
159164

160165
if (this._attachToDebug || this._devMode) {

lib/parser.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export declare const projectDir: string, projectBinary: string, pluginRoot: string, pluginBinary: string, port: number, verbose: boolean, appiumCapsLocation: string, testFolder: string, runType: string, isSauceLab: boolean, appPath: string, storage: string, testReports: string, reuseDevice: boolean, devMode: boolean, ignoreDeviceController: boolean, wdaLocalPort: number, path: string, relaxedSecurity: boolean, cleanApp: boolean, attachToDebug: boolean, sessionId: string, startSession: boolean, capabilitiesName: string, imagesPath: string;
1+
export declare const projectDir: string, projectBinary: string, pluginRoot: string, pluginBinary: string, port: number, verbose: boolean, appiumCapsLocation: string, testFolder: string, runType: string, isSauceLab: boolean, appPath: string, storage: string, testReports: string, devMode: boolean, ignoreDeviceController: boolean, wdaLocalPort: number, path: string, relaxedSecurity: boolean, cleanApp: boolean, attachToDebug: boolean, sessionId: string, startSession: boolean, capabilitiesName: string, imagesPath: string;

lib/parser.ts

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,82 @@ import { INsCapabilitiesArgs } from "./interfaces/ns-capabilities-args";
55

66
const config = (() => {
77
const options = yargs
8-
.option("runType", { describe: "Path to excute command.", type: "string", default: null })
9-
.option("testFolder", { describe: "e2e test folder name", default: "e2e", type: "string" })
10-
.option("appiumCapsLocation", { describe: "Capabilities", type: "string" })
11-
.option("sauceLab", { describe: "SauceLab", default: false, type: "boolean" })
12-
.option("port", { alias: "p", describe: "Appium port", type: "number"})
13-
.option("attachToDebug", { alias: "a", describe: "Attach to appium desktop app.", default: false, type: "boolean" })
14-
.option("capabilitiesName", { describe: "Capabilities file name", default: "appium.capabilities.json", type: "string" })
15-
.option("sessionId", { alias: "s", describe: "Session to attach", default: false, type: "string" })
16-
.option("startSession", { describe: "Start session.", default: false, type: "boolean" })
8+
.option("runType",
9+
{
10+
describe: "Which option to use from appium capabilities.json",
11+
type: "string"
12+
})
13+
.option("testFolder",
14+
{
15+
describe: "e2e test folder name",
16+
default: "e2e",
17+
type: "string"
18+
})
19+
.option("appiumCapsLocation",
20+
{
21+
describe: "Custom capabilities location",
22+
type: "string"
23+
})
24+
.option("sauceLab",
25+
{
26+
describe: "Use it mandatory for sauceLab run!",
27+
default: false,
28+
type: "boolean"
29+
})
30+
.option("port",
31+
{
32+
alias: "p",
33+
describe: "Appium port",
34+
type: "number"
35+
})
36+
.option("attachToDebug",
37+
{
38+
alias: "a",
39+
describe: "Attach to appium desktop application. Will use first met session!",
40+
default: false,
41+
type: "boolean"
42+
})
43+
.option("capabilitiesName",
44+
{
45+
describe: "Capabilities file name",
46+
default: "appium.capabilities.json",
47+
type: "string"
48+
})
49+
.option("startSession",
50+
{
51+
describe: "Start session. This option will start a new session can be reused for tests!",
52+
default: false,
53+
type: "boolean"
54+
})
55+
.option("sessionId", {
56+
alias: "s",
57+
describe: "Provide session id which you want to attach",
58+
default: false,
59+
type: "string"
60+
})
1761
.option("wdaLocalPort", { alias: "wda", describe: "WDA port", type: "number" })
1862
.option("verbose", { alias: "v", describe: "Log actions", type: "boolean" })
19-
.option("path", { describe: "path", default: process.cwd(), type: "string" })
63+
.option("path", { describe: "Execution path", default: process.cwd(), type: "string" })
2064
.option("relaxedSecurity", { describe: "appium relaxedSecurity", default: false, type: "boolean" })
2165
.option("appPath", { describe: "application path", type: "string" })
2266
.option("storage", { describe: "Storage for images folder.", type: "string" })
2367
.option("testReports", { describe: "Test reporting folder", type: "string" })
24-
.option("reuseDevice", { describe: "Reusing device if available.", type: "boolean", default: false })
25-
.option("devMode", { alias: "dev-mode", describe: "Will skipp app instalation and will reuse the one installed on device!", type: "boolean", default: false })
26-
.option("ignoreDeviceController", { alias: "i-ns-device-controller", describe: "Use default appium options for running emulatos/ simulators.", type: "boolean", default: false })
27-
.option("cleanApp", { alias: "c", describe: "Uninstall app after test are finished", type: "boolean", default: false })
68+
.option("devMode",
69+
{
70+
alias: "dev-mode",
71+
describe: "Skips app installation and uses the one that should already be installed on device! Good to use during development.",
72+
type: "boolean",
73+
default: false
74+
})
75+
.option("ignoreDeviceController",
76+
{
77+
alias: "idc",
78+
describe: `Use default appium options for running emulators/ simulators. Provide this option will not use custom device controller.
79+
Device controller is disabled by default when --sauceLab option is provided!`,
80+
type: "boolean",
81+
default: false
82+
})
83+
.option("cleanApp", { alias: "c", describe: "Clean app before and after run.", type: "boolean", default: false })
2884
.option("imagesPath", { describe: "comparison images path relative to resources/images", type: "string" })
2985
.help()
3086
.argv;
@@ -55,8 +111,7 @@ const config = (() => {
55111
options.attachToDebug = true;
56112
options.devMode = true;
57113
if (!options.port) {
58-
logError("Provide appium server port started from desktop application!")
59-
process.exit(1);
114+
logError(`Provide appium server port that has been used to start session or the default '${port}' one will be used`);
60115
}
61116
}
62117

@@ -70,7 +125,7 @@ const config = (() => {
70125
projectBinary: projectBinary,
71126
pluginRoot: pluginRoot,
72127
pluginBinary: pluginBinary,
73-
port: options.port || process.env.npm_config_port || process.env["APPIUM_PORT"] || 4723 ,
128+
port: options.port || process.env.npm_config_port || process.env["APPIUM_PORT"] || 4723,
74129
wdaLocalPort: options.wdaLocalPort || process.env.npm_config_wdaLocalPort || process.env["WDA_LOCAL_PORT"] || 8410,
75130
testFolder: options.testFolder || process.env.npm_config_testFolder || "e2e",
76131
runType: options.runType || process.env.npm_config_runType,
@@ -80,8 +135,7 @@ const config = (() => {
80135
appPath: options.appPath || process.env.npm_config_appPath,
81136
storage: options.storage || process.env.npm_config_STORAGE || process.env.STORAGE,
82137
testReports: options.testReports || process.env.npm_config_testReports || process.env.TEST_REPORTS,
83-
devMode: options.devMode || process.env.npm_config_devMode || process.env.REUSE_APP,
84-
reuseDevice: options.devMode ? true : options.reuseDevice || process.env.npm_config_reuseDevice || process.env.REUSE_DEVICE,
138+
devMode: options.devMode || process.env.npm_config_devMode || process.env.REUSE_APP,
85139
cleanApp: !options.devMode && options.cleanApp && !options.sauceLab && !options.ignoreDeviceController,
86140
ignoreDeviceController: options.ignoreDeviceController || process.env.npm_ignoreDeviceController,
87141
path: options.path || process.env.npm_path,
@@ -110,7 +164,6 @@ export const {
110164
appPath,
111165
storage,
112166
testReports,
113-
reuseDevice,
114167
devMode,
115168
ignoreDeviceController,
116169
wdaLocalPort,

lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ export const prepareApp = async (args: INsCapabilities) => {
537537
const groupings = getRegexResultsAsArray(/(\w+)/gi, args.appiumCaps[appPackage]);
538538
args.appName = groupings[groupings.length - 1];
539539
console.log(`Setting application name as ${args.appName}`);
540-
if (!args.devMode && !args.ignoreDeviceController) {
540+
if (!args.devMode && !args.ignoreDeviceController && args.cleanApp) {
541541
logInfo("Check and uninstall application from device.");
542542
await args.deviceManager.uninstallApp(args);
543543
} else {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"devDependencies": {
4848
"@types/node": "~10.12.15",
49-
"typescript": "^3.1.1"
49+
"typescript": "^3.2.0"
5050
},
5151
"scripts": {
5252
"postinstall": "node ./postinstall.js",

samples/config/appium.capabilities.json

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"avd": "Emulator-Api19-Default",
77
"lt": 60000,
88
"newCommandTimeout": 720,
9-
"noReset": true,
9+
"noReset": false,
1010
"fullReset": false,
1111
"app": ""
1212
},
@@ -17,7 +17,7 @@
1717
"avd": "Emulator-Api21-Default",
1818
"lt": 60000,
1919
"newCommandTimeout": 720,
20-
"noReset": true,
20+
"noReset": false,
2121
"fullReset": false,
2222
"app": ""
2323
},
@@ -28,7 +28,7 @@
2828
"avd": "Emulator-Api23-Default",
2929
"lt": 60000,
3030
"newCommandTimeout": 720,
31-
"noReset": true,
31+
"noReset": false,
3232
"fullReset": false,
3333
"app": ""
3434
},
@@ -39,7 +39,7 @@
3939
"avd": "Emulator-Api24-Default",
4040
"lt": 60000,
4141
"newCommandTimeout": 720,
42-
"noReset": true,
42+
"noReset": false,
4343
"fullReset": false,
4444
"app": ""
4545
},
@@ -50,7 +50,7 @@
5050
"avd": "Emulator-Api25-Google",
5151
"lt": 60000,
5252
"newCommandTimeout": 720,
53-
"noReset": true,
53+
"noReset": false,
5454
"fullReset": false,
5555
"app": ""
5656
},
@@ -61,7 +61,7 @@
6161
"avd": "Emulator-Api26-Google",
6262
"lt": 60000,
6363
"newCommandTimeout": 720,
64-
"noReset": true,
64+
"noReset": false,
6565
"fullReset": false,
6666
"app": ""
6767
},
@@ -72,7 +72,7 @@
7272
"avd": "Emulator-Api27-Google",
7373
"lt": 60000,
7474
"newCommandTimeout": 720,
75-
"noReset": true,
75+
"noReset": false,
7676
"fullReset": false,
7777
"app": ""
7878
},
@@ -83,41 +83,40 @@
8383
"avd": "Emulator-Api28-Google",
8484
"lt": 60000,
8585
"newCommandTimeout": 720,
86-
"noReset": true,
86+
"noReset": false,
8787
"fullReset": false,
8888
"app": ""
8989
},
9090
"sim.iPhone7": {
9191
"platformName": "iOS",
9292
"platformVersion": "12.*",
9393
"deviceName": "iPhone 7",
94-
"noReset": true,
94+
"noReset": false,
9595
"fullReset": false,
9696
"app": ""
9797
},
98-
9998
"sim.iPhone8": {
10099
"platformName": "iOS",
101100
"platformVersion": "12*",
102101
"deviceName": "iPhone 8",
103-
"noReset": true,
102+
"noReset": false,
104103
"fullReset": false,
105104
"app": ""
106105
},
107106
"sim.iPhoneX": {
108107
"platformName": "iOS",
109108
"platformVersion": "12*",
110109
"deviceName": "iPhone X",
111-
"noReset": true,
110+
"noReset": false,
112111
"fullReset": false,
113112
"app": ""
114113
},
115114
"sim.iPhoneXS": {
116115
"platformName": "ios",
117116
"platformVersion": "12*",
118117
"deviceName": "iPhone XS",
119-
"noReset": true,
118+
"noReset": false,
120119
"fullReset": false,
121120
"app": ""
122121
}
123-
}
122+
}

0 commit comments

Comments
 (0)