@wdio/appium-service 8.24.3 → 8.24.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"launcher.d.ts","sourceRoot":"","sources":["../src/launcher.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAIlE,OAAO,KAAK,EAAyB,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAY5E,MAAM,CAAC,OAAO,OAAO,cAAe,YAAW,QAAQ,CAAC,eAAe;IAO/D,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,OAAO,CAAC;IARpB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAe;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuB;IAC7C,OAAO,CAAC,QAAQ,CAAC,CAA+C;gBAGpD,QAAQ,EAAE,mBAAmB,EAC7B,aAAa,EAAE,YAAY,CAAC,kBAAkB,EAC9C,OAAO,CAAC,gCAAoB;YAS1B,WAAW;IAqBzB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAgDlB,SAAS;IAyBf,UAAU;IAOV,OAAO,CAAC,YAAY;YA+BN,kBAAkB;mBAeX,iBAAiB;CAezC"}
1
+ {"version":3,"file":"launcher.d.ts","sourceRoot":"","sources":["../src/launcher.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAIlE,OAAO,KAAK,EAAyB,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAW5E,MAAM,CAAC,OAAO,OAAO,cAAe,YAAW,QAAQ,CAAC,eAAe;IAO/D,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,OAAO,CAAC;IARpB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAe;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuB;IAC7C,OAAO,CAAC,QAAQ,CAAC,CAA+C;gBAGpD,QAAQ,EAAE,mBAAmB,EAC7B,aAAa,EAAE,YAAY,CAAC,kBAAkB,EAC9C,OAAO,CAAC,gCAAoB;YAS1B,WAAW;IAqBzB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAgDlB,SAAS;IAgCf,UAAU;IAOV,OAAO,CAAC,YAAY;YAiCN,kBAAkB;mBAeX,iBAAiB;CAezC"}
package/build/launcher.js CHANGED
@@ -3,19 +3,19 @@ import fsp from 'node:fs/promises';
3
3
  import url from 'node:url';
4
4
  import path from 'node:path';
5
5
  import { spawn } from 'node:child_process';
6
- import { promisify } from 'node:util';
7
6
  import logger from '@wdio/logger';
7
+ import getPort from 'get-port';
8
8
  import { resolve } from 'import-meta-resolve';
9
9
  import { isCloudCapability } from '@wdio/config';
10
10
  import { SevereServiceError } from 'webdriverio';
11
11
  import { isAppiumCapability } from '@wdio/utils';
12
12
  import { getFilePath, formatCliArgs } from './utils.js';
13
13
  const log = logger('@wdio/appium-service');
14
+ const DEFAULT_APPIUM_PORT = 4723;
14
15
  const DEFAULT_LOG_FILENAME = 'wdio-appium.log';
15
16
  const DEFAULT_CONNECTION = {
16
17
  protocol: 'http',
17
18
  hostname: '127.0.0.1',
18
- port: 4723,
19
19
  path: '/'
20
20
  };
21
21
  export default class AppiumLauncher {
@@ -58,7 +58,7 @@ export default class AppiumLauncher {
58
58
  * update capability connection options to connect
59
59
  * to Appium server
60
60
  */
61
- _setCapabilities() {
61
+ _setCapabilities(port) {
62
62
  /**
63
63
  * Multiremote sessions
64
64
  */
@@ -66,22 +66,25 @@ export default class AppiumLauncher {
66
66
  for (const [, capability] of Object.entries(this._capabilities)) {
67
67
  const cap = capability.capabilities || capability;
68
68
  const c = cap.alwaysMatch || cap;
69
- !isCloudCapability(c) && isAppiumCapability(c) && Object.assign(capability, DEFAULT_CONNECTION, 'port' in this._args ? { port: this._args.port } : {}, { path: this._args.basePath }, { ...capability });
69
+ !isCloudCapability(c) && isAppiumCapability(c) && Object.assign(capability, DEFAULT_CONNECTION, { path: this._args.basePath, port }, { ...capability });
70
70
  }
71
71
  return;
72
72
  }
73
73
  this._capabilities.forEach((cap) => {
74
+ const w3cCap = cap;
74
75
  /**
75
76
  * Parallel Multiremote
76
77
  */
77
78
  if (Object.values(cap).length > 0 && Object.values(cap).every(c => typeof c === 'object' && c.capabilities)) {
78
79
  Object.values(cap).forEach(c => {
79
- const capa = c.capabilities.alwaysMatch || c.capabilities || c;
80
- !isCloudCapability(capa) && isAppiumCapability(capa) && Object.assign(c, DEFAULT_CONNECTION, 'port' in this._args ? { port: this._args.port } : {}, { path: this._args.basePath }, { ...c });
80
+ const capability = c.capabilities.alwaysMatch || c.capabilities || c;
81
+ if (!isCloudCapability(capability) && isAppiumCapability(capability)) {
82
+ Object.assign(c, DEFAULT_CONNECTION, { path: this._args.basePath, port }, { ...c });
83
+ }
81
84
  });
82
85
  }
83
- else {
84
- !isCloudCapability(cap.alwaysMatch || cap) && isAppiumCapability(cap.alwaysMatch || cap) && Object.assign(cap, DEFAULT_CONNECTION, 'port' in this._args ? { port: this._args.port } : {}, { path: this._args.basePath }, { ...cap });
86
+ else if (!isCloudCapability(w3cCap.alwaysMatch || cap) && isAppiumCapability(w3cCap.alwaysMatch || cap)) {
87
+ Object.assign(cap, DEFAULT_CONNECTION, { path: this._args.basePath, port }, { ...cap });
85
88
  }
86
89
  });
87
90
  }
@@ -97,12 +100,18 @@ export default class AppiumLauncher {
97
100
  * Append remaining arguments
98
101
  */
99
102
  this._appiumCliArgs.push(...formatCliArgs(this._args));
100
- this._setCapabilities();
103
+ /**
104
+ * Get port from service option or use a random port
105
+ */
106
+ const port = typeof this._args.port === 'number'
107
+ ? this._args.port
108
+ : await getPort({ port: DEFAULT_APPIUM_PORT });
109
+ this._setCapabilities(port);
101
110
  /**
102
111
  * start Appium
103
112
  */
104
113
  const command = await this._getCommand(this._options.command);
105
- this._process = await promisify(this._startAppium)(command, this._appiumCliArgs);
114
+ this._process = await this._startAppium(command, this._appiumCliArgs);
106
115
  if (this._logPath) {
107
116
  this._redirectLogStream(this._logPath);
108
117
  }
@@ -113,32 +122,34 @@ export default class AppiumLauncher {
113
122
  this._process.kill();
114
123
  }
115
124
  }
116
- _startAppium(command, args, callback) {
125
+ _startAppium(command, args) {
117
126
  log.info(`Will spawn Appium process: ${command} ${args.join(' ')}`);
118
127
  const process = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'] });
119
128
  let error;
120
- process.stdout.on('data', (data) => {
121
- if (data.includes('Appium REST http interface listener started')) {
122
- log.info(`Appium started with ID: ${process.pid}`);
123
- callback(undefined, process);
124
- }
125
- });
126
- /**
127
- * only capture first error to print it in case Appium failed to start.
128
- */
129
- process.stderr.once('data', (err) => { error = err; });
130
- process.once('exit', exitCode => {
131
- let errorMessage = `Appium exited before timeout (exit code: ${exitCode})`;
132
- if (exitCode === 2) {
133
- errorMessage += '\n' + (error?.toString() || 'Check that you don\'t already have a running Appium service.');
134
- }
135
- else if (error) {
136
- errorMessage += `\n${error.toString()}`;
137
- }
138
- if (exitCode !== 0) {
139
- log.error(errorMessage);
140
- }
141
- callback(new Error(errorMessage), null);
129
+ return new Promise((resolve, reject) => {
130
+ process.stdout.on('data', (data) => {
131
+ if (data.includes('Appium REST http interface listener started')) {
132
+ log.info(`Appium started with ID: ${process.pid}`);
133
+ resolve(process);
134
+ }
135
+ });
136
+ /**
137
+ * only capture first error to print it in case Appium failed to start.
138
+ */
139
+ process.stderr.once('data', (err) => { error = err; });
140
+ process.once('exit', exitCode => {
141
+ let errorMessage = `Appium exited before timeout (exit code: ${exitCode})`;
142
+ if (exitCode === 2) {
143
+ errorMessage += '\n' + (error?.toString() || 'Check that you don\'t already have a running Appium service.');
144
+ }
145
+ else if (error) {
146
+ errorMessage += `\n${error.toString()}`;
147
+ }
148
+ if (exitCode !== 0) {
149
+ log.error(errorMessage);
150
+ }
151
+ reject(new Error(errorMessage));
152
+ });
142
153
  });
143
154
  }
144
155
  async _redirectLogStream(logPath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/appium-service",
3
- "version": "8.24.3",
3
+ "version": "8.24.4",
4
4
  "description": "A WebdriverIO service to start & stop Appium Server",
5
5
  "author": "Morten Bjerg Gregersen <morten@mogee.dk>",
6
6
  "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-appium-service",
@@ -33,16 +33,17 @@
33
33
  },
34
34
  "typeScriptVersion": "3.8.3",
35
35
  "dependencies": {
36
- "@wdio/config": "8.24.3",
36
+ "@wdio/config": "8.24.4",
37
37
  "@wdio/logger": "8.16.17",
38
38
  "@wdio/types": "8.24.2",
39
- "@wdio/utils": "8.24.3",
39
+ "@wdio/utils": "8.24.4",
40
+ "get-port": "^7.0.0",
40
41
  "import-meta-resolve": "^3.0.0",
41
42
  "param-case": "^3.0.4",
42
- "webdriverio": "8.24.3"
43
+ "webdriverio": "8.24.4"
43
44
  },
44
45
  "publishConfig": {
45
46
  "access": "public"
46
47
  },
47
- "gitHead": "365d1997d0303e41bc418e447a46573fdbcc2dce"
48
+ "gitHead": "08859dd23faf79e17469cdd2ec9a092a888f3677"
48
49
  }