Skip to content

chore(selenium): add selenium.LOGGER.level flag when starting the server #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/cmds/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
30 changes: 16 additions & 14 deletions lib/cmds/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,30 @@ export function start(options: Options): Promise<number> {
* @returns Promise starting the server with the resolved exit code.
*/
export function startBinary(optionsBinary: OptionsBinary): Promise<number> {
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');
}
2 changes: 2 additions & 0 deletions lib/cmds/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
18 changes: 18 additions & 0 deletions lib/provider/selenium_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface SeleniumServerProviderConfig extends ProviderConfig {
port?: number;
runAsNode?: boolean;
runAsDetach?: boolean;
logLevel?: string;
}

export class SeleniumServer extends ProviderClass implements ProviderInterface {
Expand All @@ -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();
Expand All @@ -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);
}
}

/**
Expand Down Expand Up @@ -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.
Expand Down