fix(appium): use proper base driver package & random ports
MODIFY
packages/appium/lib/appium.js
packages/appium/lib/appium.js
@@ -2,7 +2,7 @@ import _ from 'lodash';
import log from './logger';
import { getBuildInfo, updateBuildInfo, APPIUM_VER } from './config';
import { findMatchingDriver } from './drivers';
-import { BaseDriver, errors, isSessionCommand } from 'appium-base-driver';
+import { BaseDriver, errors, isSessionCommand } from '@appium/base-driver';
import B from 'bluebird';
import AsyncLock from 'async-lock';
import { parseCapsForInnerDriver, pullSettings } from './utils';

MODIFY
packages/appium/lib/cli/args.js
packages/appium/lib/cli/args.js
-import { DEFAULT_BASE_PATH } from 'appium-base-driver';
+import { DEFAULT_BASE_PATH } from '@appium/base-driver';
import {
parseSecurityFeatures, parseDefaultCaps,
parsePluginNames, parseInstallTypes, parseDriverNames

MODIFY
packages/appium/lib/main.js
packages/appium/lib/main.js
import { init as logsinkInit } from './logsink';
import logger from './logger'; // logger needs to remain first of imports
import _ from 'lodash';
-import { server as baseServer, routeConfiguringFunction as makeRouter } from 'appium-base-driver';
+import { server as baseServer, routeConfiguringFunction as makeRouter } from '@appium/base-driver';
import { asyncify } from 'asyncbox';
import { default as getParser, getDefaultServerArgs } from './cli/parser';
import { USE_ALL_PLUGINS } from './cli/args';

MODIFY
packages/appium/lib/utils.js
packages/appium/lib/utils.js
import _ from 'lodash';
import logger from './logger';
-import { processCapabilities, PROTOCOLS } from 'appium-base-driver';
+import { processCapabilities, PROTOCOLS } from '@appium/base-driver';
import findRoot from 'find-root';
const W3C_APPIUM_PREFIX = 'appium';

MODIFY
packages/appium/test/driver-e2e-specs.js
packages/appium/test/driver-e2e-specs.js
@@ -9,8 +9,8 @@ import axios from 'axios';
import { remote as wdio } from 'webdriverio';
import { main as appiumServer } from '../lib/main';
import { DEFAULT_APPIUM_HOME, INSTALL_TYPE_LOCAL, DRIVER_TYPE } from '../lib/extension-config';
-import { W3C_PREFIXED_CAPS, TEST_FAKE_APP, TEST_HOST, TEST_PORT } from './helpers';
-import { BaseDriver } from 'appium-base-driver';
+import { W3C_PREFIXED_CAPS, TEST_FAKE_APP, TEST_HOST, getTestPort} from './helpers';
+import { BaseDriver } from '@appium/base-driver';
import DriverConfig from '../lib/driver-config';
import { runExtensionCommand } from '../lib/cli/extension';
import { removeAppiumPrefixes } from '../lib/utils';
@@ -18,7 +18,8 @@ import sinon from 'sinon';
chai.use(chaiAsPromised);
-const TEST_SERVER = `http://${TEST_HOST}:${TEST_PORT}`;
+let TEST_SERVER;
+let TEST_PORT;
const FAKE_DRIVER_DIR = path.resolve(__dirname, '..', '..', '..', 'fake-driver');
const should = chai.should();
@@ -26,7 +27,7 @@ const shouldStartServer = process.env.USE_RUNNING_SERVER !== '0';
const caps = W3C_PREFIXED_CAPS;
const wdOpts = {
hostname: TEST_HOST,
- port: TEST_PORT,
+ port: null,
connectionRetryCount: 0,
};
@@ -36,8 +37,11 @@ describe('FakeDriver - via HTTP', function () {
// since we update the FakeDriver.prototype below, make sure we update the FakeDriver which is
// actually going to be required by Appium
let FakeDriver = null;
- const baseUrl = `${TEST_SERVER}/session`;
+ let baseUrl;
before(async function () {
+ wdOpts.port = TEST_PORT = await getTestPort();
+ TEST_SERVER = `http://${TEST_HOST}:${TEST_PORT}`;
+ baseUrl = `${TEST_SERVER}/session`;
// first ensure we have fakedriver installed
const driverList = await runExtensionCommand({
appiumHome,

MODIFY
packages/appium/test/helpers.js
packages/appium/test/helpers.js
@@ -3,8 +3,7 @@ import {insertAppiumPrefixes} from '../lib/utils';
import findUp from 'find-up';
import getPort from 'get-port';
-const TEST_HOST = '0.0.0.0';
-const TEST_PORT = getPort.sync();
+const TEST_HOST = 'localhost';
// monorepo root. this cannot be hardcoded because:
// 1. we may be in 'build/test' or 'test', depending on our config
@@ -24,4 +23,13 @@ const W3C_CAPS = {
firstMatch: [{}],
};
-export { TEST_FAKE_APP, TEST_HOST, TEST_PORT, BASE_CAPS, W3C_PREFIXED_CAPS, W3C_CAPS, PROJECT_ROOT };
+let TEST_PORT;
+/**
+ * Returns a free port; one per process
+ * @returns {Promise<number>} a free port
+ */
+async function getTestPort () {
+ return await (TEST_PORT || getPort());
+}
+
+export { TEST_FAKE_APP, TEST_HOST, BASE_CAPS, W3C_PREFIXED_CAPS, W3C_CAPS, PROJECT_ROOT, getTestPort };

MODIFY
packages/appium/test/plugin-e2e-specs.js
packages/appium/test/plugin-e2e-specs.js
@@ -8,7 +8,7 @@ import { remote as wdio } from 'webdriverio';
import axios from 'axios';
import { main as appiumServer } from '../lib/main';
import { DEFAULT_APPIUM_HOME, INSTALL_TYPE_LOCAL, DRIVER_TYPE, PLUGIN_TYPE } from '../lib/extension-config';
-import { W3C_PREFIXED_CAPS, TEST_HOST, TEST_PORT, PROJECT_ROOT } from './helpers';
+import { W3C_PREFIXED_CAPS, TEST_HOST, getTestPort, PROJECT_ROOT } from './helpers';
import { runExtensionCommand } from '../lib/cli/extension';
chai.should();
@@ -17,19 +17,23 @@ chai.use(chaiAsPromised);
// TODO: update when fake-plugin pulled in to monorepo
const FAKE_PLUGIN_DIR = path.join(PROJECT_ROOT, 'node_modules', '@appium', 'fake-plugin');
const FAKE_DRIVER_DIR = path.join(PROJECT_ROOT, 'packages', 'fake-driver');
-const TEST_SERVER = `http://${TEST_HOST}:${TEST_PORT}`;
+let TEST_SERVER;
+let TEST_PORT;
const wdOpts = {
hostname: TEST_HOST,
- port: TEST_PORT,
+ port: null,
connectionRetryCount: 0,
capabilities: W3C_PREFIXED_CAPS,
};
describe('FakePlugin', function () {
const appiumHome = DEFAULT_APPIUM_HOME;
- const baseUrl = `${TEST_SERVER}/session`;
+ let baseUrl;
before(async function () {
+ wdOpts.port = TEST_PORT = await getTestPort();
+ TEST_SERVER = `http://${TEST_HOST}:${wdOpts.port}`;
+ baseUrl = `${TEST_SERVER}/session`;
// first ensure we have fakedriver installed
const driverList = await runExtensionCommand({
appiumHome,

fix(appium): use proper base driver package & random ports