Attach server instance to each driver being created (#10400)

This commit is contained in:
Mykola Mokhnach
2018-03-23 07:39:15 +01:00
committed by GitHub
parent 01eae28622
commit 0774ffcefc
3 changed files with 13 additions and 21 deletions

View File

@@ -1,8 +1,7 @@
import _ from 'lodash';
import log from './logger';
import { getAppiumConfig } from './config';
import { BaseDriver, routeConfiguringFunction, errors,
isSessionCommand } from 'appium-base-driver';
import { BaseDriver, errors, isSessionCommand } from 'appium-base-driver';
import { FakeDriver } from 'appium-fake-driver';
import { AndroidDriver } from 'appium-android-driver';
import { IosDriver } from 'appium-ios-driver';
@@ -214,10 +213,15 @@ class AppiumDriver extends BaseDriver {
let runningDriversData, otherPendingDriversData;
let d = new InnerDriver(this.args);
if (this.args.relaxedSecurityEnabled) {
log.info(`Applying relaxed security to ${InnerDriver.name} as per server command line argument`);
d.relaxedSecurityEnabled = true;
}
// Attach server instance
d.server = this.server;
try {
runningDriversData = await this.curSessionDataForDriver(InnerDriver);
} catch (e) {
@@ -251,7 +255,6 @@ class AppiumDriver extends BaseDriver {
// unexpectedly shuts down
this.attachUnexpectedShutdownHandler(d, innerSessionId);
log.info(`New ${InnerDriver.name} session created successfully, session ` +
`${innerSessionId} added to master session list`);
@@ -364,10 +367,4 @@ function isAppiumDriverCommand (cmd) {
return !isSessionCommand(cmd) || cmd === "deleteSession";
}
function getAppiumRouter (args) {
let appium = new AppiumDriver(args);
return routeConfiguringFunction(appium);
}
export { AppiumDriver, getAppiumRouter };
export default getAppiumRouter;
export { AppiumDriver };

View File

@@ -4,13 +4,13 @@
import { init as logsinkInit } from './logsink';
import logger from './logger'; // logger needs to remain first of imports
import _ from 'lodash';
import { server as baseServer } from 'appium-base-driver';
import { server as baseServer, routeConfiguringFunction } from 'appium-base-driver';
import { asyncify } from 'asyncbox';
import { default as getParser, getDefaultArgs } from './parser';
import { showConfig, checkNodeOk, validateServerArgs,
warnNodeDeprecations, validateTmpDir, getNonDefaultArgs,
getDeprecatedArgs, getGitRev, APPIUM_VER } from './config';
import getAppiumRouter from './appium';
import { AppiumDriver } from './appium';
import registerNode from './grid-register';
import { inspectObject } from './utils';
@@ -120,8 +120,10 @@ async function main (args = null) {
await logsinkInit(args);
await preflightChecks(parser, args, throwInsteadOfExit);
await logStartupInfo(parser, args);
let router = getAppiumRouter(args);
let appiumDriver = new AppiumDriver(args);
let router = routeConfiguringFunction(appiumDriver);
let server = await baseServer(router, args.port, args.address);
appiumDriver.server = server;
try {
// TODO prelaunch if args.launch is set
// TODO: startAlertSocket(server, appiumServer);

View File

@@ -1,6 +1,6 @@
// transpile:mocha
import { AppiumDriver, getAppiumRouter } from '../lib/appium';
import { AppiumDriver } from '../lib/appium';
import { FakeDriver } from 'appium-fake-driver';
import { BASE_CAPS, W3C_CAPS } from './helpers';
import _ from 'lodash';
@@ -18,13 +18,6 @@ chai.use(chaiAsPromised);
const SESSION_ID = 1;
describe('AppiumDriver', function () {
describe('getAppiumRouter', function () {
it('should return a route configuring function', async function () {
let routeConfiguringFunction = getAppiumRouter({});
routeConfiguringFunction.should.be.a.function;
});
});
describe('AppiumDriver', function () {
function getDriverAndFakeDriver () {
let appium = new AppiumDriver({});