Skip to content
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

feat(selenium-grid): run webdriver-manager as a selenium-grid node (merge against master branch) #386

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ Options:
--versions.gecko The geckodriver version. [string]
--versions.ie The ie driver version. [string]
--versions.standalone The selenium server standalone version. [string]
```
```
filipzamorsky marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions lib/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ const standaloneNodeOption: yargs.Options = {
describe: 'Start the selenium server standalone with role set to "node".',
type: 'boolean'
};
const GRID_NODE = 'gridNode';
const gridNodeOption: yargs.Options = {
describe: 'Start the selenium grid with role set to "node".',
type: 'string'
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rebase. STANDALONE is now SELENIUM and SELENIUM_ALIAS

Could we call this as SELENIUM_GRID_URL?
We should use underscores. So the string would be 'selenium_grid_url'

And have one called SELENIUM_GRID_URL_ALIAS?
And this string would be 'standalone_grid_url'

I am trying to standardize this and add a README for this. I have a few flags to fix that I also need to fix.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - done

const VERSIONS_CHROME = 'versions.chrome';
const versionsChromeOption: yargs.Options = {
describe: 'The chromedriver version.',
Expand Down Expand Up @@ -139,6 +144,7 @@ yargs
.option(SELENIUM_PORT, seleniumPort)
.option(STANDALONE, standaloneOption)
.option(STANDALONE_NODE, standaloneNodeOption)
.option(GRID_NODE, gridNodeOption)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - done

.option(VERSIONS_CHROME, versionsChromeOption)
.option(VERSIONS_GECKO, versionsGeckoOption)
.option(VERSIONS_IE, versionsIeOption)
Expand Down
2 changes: 2 additions & 0 deletions lib/cmds/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface Server {
version?: string;
// Run as role = node option.
runAsNode?: boolean;
// Run as grid node role = hub registration URL path.
gridNode?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this gridUrl or nodeGridUrl?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - done

// The relative or full path to the chrome logs file.
chromeLogs?: string;
// The full path to the edge driver server.
Expand Down
6 changes: 6 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.gridNode = optionsBinary.server.gridNode;
optionsBinary.server.binary = new SeleniumServer(seleniumProviderConfig);
}
return optionsBinary;
Expand Down Expand Up @@ -112,10 +113,15 @@ export function convertArgs2Options(argv: yargs.Arguments): Options {
if (argv.iedriver as boolean) {
options.browserDrivers.push({name: 'iedriver', version: versionsIe});
}
if (argv.gridNode as string === '') {
console.log('Please specify a grid hub URL...');
process.exit();
}
if (argv.standalone as boolean) {
options.server = {};
options.server.name = 'selenium';
options.server.runAsNode = argv.standalone_node as boolean;
options.server.gridNode = argv.gridNode as string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When grabbing things from the argv, we should use the selenium_grid_url and not the standalone_ alias

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - done

options.server.runAsDetach = argv.detach as boolean;
options.server.version = versionsStandalone;
options.server.chromeLogs = argv.chrome_logs as string;
Expand Down
16 changes: 16 additions & 0 deletions lib/provider/selenium_server.spec-unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ describe('selenium_server', () => {
const javaArgs = '-role node ' +
'-servlet org.openqa.grid.web.servlet.LifecycleServlet ' +
'-registerCycle 0 -port 4444';
const javaGridArgs = '-role node ' +
'-hub ';
const javaArgsPort = '-port 4444';
it('should use a selenium server with no options', () => {
spyOn(fs, 'readFileSync').and.returnValue(configBinaries);
Expand Down Expand Up @@ -71,6 +73,20 @@ describe('selenium_server', () => {
'-Dwebdriver.chrome.driver=path/to/chromedriver ' +
'-jar path/to/selenium-server-3.0.jar ' + javaArgs);
});

it('should use a selenium server with a grid node option', () => {
spyOn(fs, 'readFileSync').and.returnValue(configBinaries);
const seleniumServer = new SeleniumServer();
seleniumServer.runAsDetach = true;
seleniumServer.runAsNode = true;
seleniumServer.runAsGrid = true;
const cmd = seleniumServer.getCmdStartServer(
{'-Dwebdriver.chrome.driver': 'path/to/chromedriver'});
expect(cmd.join(' '))
.toContain(
'-Dwebdriver.chrome.driver=path/to/chromedriver ' +
'-jar path/to/selenium-server-3.0.jar ' + javaGridArgs);
});
});

describe('getStatus', () => {
Expand Down
25 changes: 21 additions & 4 deletions lib/provider/selenium_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const log = loglevel.getLogger('webdriver-manager');

export interface SeleniumServerProviderConfig extends ProviderConfig {
port?: number;
gridNode?: string;
runAsNode?: boolean;
runAsGrid?: boolean;
runAsDetach?: boolean;
}

Expand All @@ -27,10 +29,12 @@ export class SeleniumServer implements ProviderInterface {
osArch = os.arch();
outDir = OUT_DIR;
port = 4444;
gridNode = '';
proxy: string = null;
requestUrl = 'https://selenium-release.storage.googleapis.com/';
seleniumProcess: childProcess.ChildProcess;
runAsNode = false;
runAsGrid = false;
runAsDetach = false;

constructor(providerConfig?: SeleniumServerProviderConfig) {
Expand Down Expand Up @@ -63,6 +67,10 @@ export class SeleniumServer implements ProviderInterface {
if (providerConfig.runAsNode) {
this.runAsNode = providerConfig.runAsNode;
}
if (providerConfig.gridNode) {
this.runAsGrid = true;
this.gridNode = providerConfig.gridNode;
}
if (providerConfig.runAsDetach) {
this.runAsDetach = providerConfig.runAsDetach;
this.runAsNode = true;
Expand Down Expand Up @@ -182,7 +190,7 @@ export class SeleniumServer implements ProviderInterface {
options.push('-jar');
options.push(jarFile);

if (this.runAsNode) {
if (this.runAsNode && !this.runAsGrid) {
options.push('-role');
options.push('node');

Expand All @@ -192,8 +200,17 @@ export class SeleniumServer implements ProviderInterface {
options.push('-registerCycle');
options.push('0');
}
options.push('-port');
options.push(this.port.toString());
if (this.runAsGrid) {
options.push('-role');
options.push('node');

options.push('-hub');
options.push(this.gridNode);
}
if (!this.runAsGrid) {
options.push('-port');
options.push(this.port.toString());
}

return options;
}
Expand Down Expand Up @@ -332,4 +349,4 @@ export function semanticVersionParser(xmlKey: string) {
*/
export function matchBinaries(): RegExp|null {
return /selenium-server-standalone-\d+.\d+.\d+.*.jar/g;
}
}