diff --git a/lib/cli/index.ts b/lib/cli/index.ts index a813596f..fdb079ff 100644 --- a/lib/cli/index.ts +++ b/lib/cli/index.ts @@ -74,6 +74,11 @@ const seleniumPort: yargs.Options = { default: 4444, type: 'number' }; +const SELENIUM_LOG_LEVEL = 'seleniumLogLevel'; +const seleniumLogLevelOption: yargs.Options = { + describe: 'Set the -Dselenium.LOGGER.level flag when starting the server', + type: 'string' +}; const STANDALONE = 'standalone'; const standaloneOption: yargs.Options = { describe: 'Install or update selenium server standalone.', @@ -137,6 +142,7 @@ yargs .option(LOG_LEVEL, logLevelOption) .option(OUT_DIR, outDirOption) .option(SELENIUM_PORT, seleniumPort) + .option(SELENIUM_LOG_LEVEL, seleniumLogLevelOption) .option(STANDALONE, standaloneOption) .option(STANDALONE_NODE, standaloneNodeOption) .option(VERSIONS_CHROME, versionsChromeOption) diff --git a/lib/cmds/options.ts b/lib/cmds/options.ts index 0b8848ee..e5ef3a1f 100644 --- a/lib/cmds/options.ts +++ b/lib/cmds/options.ts @@ -45,4 +45,6 @@ export interface Server { runAsDetach?: boolean; // Port number to start the server. port?: number; + // Set the log level when starting the server. -Dselenium.LOGGER.level + logLevel?: string; } \ No newline at end of file diff --git a/lib/cmds/start.ts b/lib/cmds/start.ts index 0f36f97b..9b9f3569 100644 --- a/lib/cmds/start.ts +++ b/lib/cmds/start.ts @@ -50,28 +50,30 @@ export function start(options: Options): Promise { * @returns Promise starting the server with the resolved exit code. */ export function startBinary(optionsBinary: OptionsBinary): Promise { - const javaOpts: {[key: string]: string} = {}; - for (const browserDriver of optionsBinary.browserDrivers) { - if (browserDriver.binary) { - javaOpts[browserDriver.binary.seleniumFlag] = - browserDriver.binary.getBinaryPath(browserDriver.version); - } - } - - if (optionsBinary.server) { + if (optionsBinary.server && optionsBinary.server.binary) { + const seleniumServer = (optionsBinary.server.binary as SeleniumServer); if (optionsBinary.server.chromeLogs) { const chromeLogs = optionsBinary.server.chromeLogs.replace('"', '').replace('\'', ''); - javaOpts['-Dwebdriver.chrome.logfile'] = path.resolve(chromeLogs); + seleniumServer.setJavaFlag('-Dwebdriver.chrome.logfile', + path.resolve(chromeLogs)); } if (optionsBinary.server.edge) { const edge = optionsBinary.server.edge.replace('"', '').replace('\'', ''); - javaOpts['-Dwebdriver.edge.driver'] = path.resolve(edge); + seleniumServer.setJavaFlag('-Dwebdriver.edge.driver', path.resolve(edge)); + } + if (optionsBinary.server.logLevel) { + const logLevel = optionsBinary.server.logLevel; + seleniumServer.setJavaFlag('-Dselenium.LOGGER.level', logLevel); } - if (optionsBinary.server.binary) { - return (optionsBinary.server.binary as SeleniumServer) - .startServer(javaOpts, optionsBinary.server.version); + for (const browserDriver of optionsBinary.browserDrivers) { + if (browserDriver.binary) { + seleniumServer.setJavaFlag(browserDriver.binary.seleniumFlag, + browserDriver.binary.getBinaryPath(browserDriver.version)); + } } + return seleniumServer.startServer(seleniumServer.javaOpts, + optionsBinary.server.version); } return Promise.reject('Could not start the server'); } \ No newline at end of file diff --git a/lib/cmds/utils.ts b/lib/cmds/utils.ts index 714735fd..8cf391ff 100644 --- a/lib/cmds/utils.ts +++ b/lib/cmds/utils.ts @@ -42,6 +42,7 @@ export function addOptionsBinary(options: Options): OptionsBinary { seleniumProviderConfig.port = optionsBinary.server.port; seleniumProviderConfig.runAsDetach = optionsBinary.server.runAsDetach; seleniumProviderConfig.runAsNode = optionsBinary.server.runAsNode; + seleniumProviderConfig.logLevel = optionsBinary.server.logLevel; optionsBinary.server.binary = new SeleniumServer(seleniumProviderConfig); } return optionsBinary; @@ -121,6 +122,7 @@ export function convertArgs2Options(argv: yargs.Arguments): Options { options.server.chromeLogs = argv.chrome_logs as string; options.server.edge = argv.edge as string; options.server.port = argv.seleniumPort as number; + options.server.logLevel = argv.seleniumLogLevel as string; } return options; } \ No newline at end of file diff --git a/lib/provider/selenium_server.ts b/lib/provider/selenium_server.ts index 3b66d2e2..28fb1f41 100644 --- a/lib/provider/selenium_server.ts +++ b/lib/provider/selenium_server.ts @@ -17,6 +17,7 @@ export interface SeleniumServerProviderConfig extends ProviderConfig { port?: number; runAsNode?: boolean; runAsDetach?: boolean; + logLevel?: string; } export class SeleniumServer extends ProviderClass implements ProviderInterface { @@ -32,6 +33,8 @@ export class SeleniumServer extends ProviderClass implements ProviderInterface { seleniumProcess: childProcess.ChildProcess; runAsNode = false; runAsDetach = false; + logLevel: string = null; + javaOpts: {[key: string]: string} = {}; constructor(config?: SeleniumServerProviderConfig) { super(); @@ -49,6 +52,10 @@ export class SeleniumServer extends ProviderClass implements ProviderInterface { if (this.runAsDetach) { this.runAsNode = true; } + this.logLevel = this.setVar('logLevel', this.logLevel, config); + if (this.logLevel) { + this.setJavaFlag('-Dselenium.LOGGER.level', this.logLevel); + } } /** @@ -146,6 +153,17 @@ export class SeleniumServer extends ProviderClass implements ProviderInterface { } } + /** + * Sets a java flag option. + * @param key The java option flag. + * @param value The value of the flag. + */ + setJavaFlag(key: string, value: string) { + if (value) { + this.javaOpts[key] = value; + } + } + /** * Get the selenium server start command (not including the java command) * @param opts The options to pass to the jar file.