Skip to content

Commit 78b73b9

Browse files
authored
chore(selenium): add selenium.LOGGER.level flag when starting the server (#367)
closes #324
1 parent f83fb14 commit 78b73b9

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

lib/cli/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ const seleniumPort: yargs.Options = {
7474
default: 4444,
7575
type: 'number'
7676
};
77+
const SELENIUM_LOG_LEVEL = 'seleniumLogLevel';
78+
const seleniumLogLevelOption: yargs.Options = {
79+
describe: 'Set the -Dselenium.LOGGER.level flag when starting the server',
80+
type: 'string'
81+
};
7782
const STANDALONE = 'standalone';
7883
const standaloneOption: yargs.Options = {
7984
describe: 'Install or update selenium server standalone.',
@@ -137,6 +142,7 @@ yargs
137142
.option(LOG_LEVEL, logLevelOption)
138143
.option(OUT_DIR, outDirOption)
139144
.option(SELENIUM_PORT, seleniumPort)
145+
.option(SELENIUM_LOG_LEVEL, seleniumLogLevelOption)
140146
.option(STANDALONE, standaloneOption)
141147
.option(STANDALONE_NODE, standaloneNodeOption)
142148
.option(VERSIONS_CHROME, versionsChromeOption)

lib/cmds/options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ export interface Server {
4545
runAsDetach?: boolean;
4646
// Port number to start the server.
4747
port?: number;
48+
// Set the log level when starting the server. -Dselenium.LOGGER.level
49+
logLevel?: string;
4850
}

lib/cmds/start.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,30 @@ export function start(options: Options): Promise<number> {
5050
* @returns Promise starting the server with the resolved exit code.
5151
*/
5252
export function startBinary(optionsBinary: OptionsBinary): Promise<number> {
53-
const javaOpts: {[key: string]: string} = {};
54-
for (const browserDriver of optionsBinary.browserDrivers) {
55-
if (browserDriver.binary) {
56-
javaOpts[browserDriver.binary.seleniumFlag] =
57-
browserDriver.binary.getBinaryPath(browserDriver.version);
58-
}
59-
}
60-
61-
if (optionsBinary.server) {
53+
if (optionsBinary.server && optionsBinary.server.binary) {
54+
const seleniumServer = (optionsBinary.server.binary as SeleniumServer);
6255
if (optionsBinary.server.chromeLogs) {
6356
const chromeLogs =
6457
optionsBinary.server.chromeLogs.replace('"', '').replace('\'', '');
65-
javaOpts['-Dwebdriver.chrome.logfile'] = path.resolve(chromeLogs);
58+
seleniumServer.setJavaFlag('-Dwebdriver.chrome.logfile',
59+
path.resolve(chromeLogs));
6660
}
6761
if (optionsBinary.server.edge) {
6862
const edge = optionsBinary.server.edge.replace('"', '').replace('\'', '');
69-
javaOpts['-Dwebdriver.edge.driver'] = path.resolve(edge);
63+
seleniumServer.setJavaFlag('-Dwebdriver.edge.driver', path.resolve(edge));
64+
}
65+
if (optionsBinary.server.logLevel) {
66+
const logLevel = optionsBinary.server.logLevel;
67+
seleniumServer.setJavaFlag('-Dselenium.LOGGER.level', logLevel);
7068
}
71-
if (optionsBinary.server.binary) {
72-
return (optionsBinary.server.binary as SeleniumServer)
73-
.startServer(javaOpts, optionsBinary.server.version);
69+
for (const browserDriver of optionsBinary.browserDrivers) {
70+
if (browserDriver.binary) {
71+
seleniumServer.setJavaFlag(browserDriver.binary.seleniumFlag,
72+
browserDriver.binary.getBinaryPath(browserDriver.version));
73+
}
7474
}
75+
return seleniumServer.startServer(seleniumServer.javaOpts,
76+
optionsBinary.server.version);
7577
}
7678
return Promise.reject('Could not start the server');
7779
}

lib/cmds/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function addOptionsBinary(options: Options): OptionsBinary {
4242
seleniumProviderConfig.port = optionsBinary.server.port;
4343
seleniumProviderConfig.runAsDetach = optionsBinary.server.runAsDetach;
4444
seleniumProviderConfig.runAsNode = optionsBinary.server.runAsNode;
45+
seleniumProviderConfig.logLevel = optionsBinary.server.logLevel;
4546
optionsBinary.server.binary = new SeleniumServer(seleniumProviderConfig);
4647
}
4748
return optionsBinary;
@@ -121,6 +122,7 @@ export function convertArgs2Options(argv: yargs.Arguments): Options {
121122
options.server.chromeLogs = argv.chrome_logs as string;
122123
options.server.edge = argv.edge as string;
123124
options.server.port = argv.seleniumPort as number;
125+
options.server.logLevel = argv.seleniumLogLevel as string;
124126
}
125127
return options;
126128
}

lib/provider/selenium_server.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface SeleniumServerProviderConfig extends ProviderConfig {
1717
port?: number;
1818
runAsNode?: boolean;
1919
runAsDetach?: boolean;
20+
logLevel?: string;
2021
}
2122

2223
export class SeleniumServer extends ProviderClass implements ProviderInterface {
@@ -32,6 +33,8 @@ export class SeleniumServer extends ProviderClass implements ProviderInterface {
3233
seleniumProcess: childProcess.ChildProcess;
3334
runAsNode = false;
3435
runAsDetach = false;
36+
logLevel: string = null;
37+
javaOpts: {[key: string]: string} = {};
3538

3639
constructor(config?: SeleniumServerProviderConfig) {
3740
super();
@@ -49,6 +52,10 @@ export class SeleniumServer extends ProviderClass implements ProviderInterface {
4952
if (this.runAsDetach) {
5053
this.runAsNode = true;
5154
}
55+
this.logLevel = this.setVar('logLevel', this.logLevel, config);
56+
if (this.logLevel) {
57+
this.setJavaFlag('-Dselenium.LOGGER.level', this.logLevel);
58+
}
5259
}
5360

5461
/**
@@ -146,6 +153,17 @@ export class SeleniumServer extends ProviderClass implements ProviderInterface {
146153
}
147154
}
148155

156+
/**
157+
* Sets a java flag option.
158+
* @param key The java option flag.
159+
* @param value The value of the flag.
160+
*/
161+
setJavaFlag(key: string, value: string) {
162+
if (value) {
163+
this.javaOpts[key] = value;
164+
}
165+
}
166+
149167
/**
150168
* Get the selenium server start command (not including the java command)
151169
* @param opts The options to pass to the jar file.

0 commit comments

Comments
 (0)