Skip to content

Commit

Permalink
selenium v4 fixes #554 #449 (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrybyk authored Jun 18, 2021
1 parent a912029 commit 7e575d6
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 24 deletions.
5 changes: 4 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
{
"name": "install",
"program": "${workspaceFolder}/bin/selenium-standalone",
"args": ["install"],
"args": [
"install",
// "--version=4.0.0-alpha-7"
],
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"type": "node",
Expand Down
4 changes: 2 additions & 2 deletions lib/check-paths-existence.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = checkPathsExistence;

const fs = require('fs');

function checkPathsExistence(paths, cb) {
function checkPathsExistence(paths, opts, cb) {
const pathValues = Object.keys(paths).map((key) => {
return paths[key];
});
Expand All @@ -21,6 +21,6 @@ function checkPathsExistence(paths, cb) {
})
)
)
.then(() => cb())
.then(() => cb(undefined, opts))
.catch((err) => cb(err));
}
4 changes: 2 additions & 2 deletions lib/check-started.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const got = require('got');
const statusUrl = require('./get-selenium-status-url.js');
const { sleep } = require('./delay');

async function checkStarted(seleniumArgs) {
const seleniumStatusUrl = statusUrl.getSeleniumStatusUrl(seleniumArgs);
async function checkStarted(seleniumArgs, opts) {
const seleniumStatusUrl = statusUrl.getSeleniumStatusUrl(seleniumArgs, opts);
const options = {
responseType: 'json',
timeout: 10000,
Expand Down
4 changes: 3 additions & 1 deletion lib/compute-download-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ module.exports = computeDownloadUrls;

const got = require('got');
const util = require('util');
const { isSelenium4 } = require('./isSelenium4');

const urls = {
selenium: '%s/%s/selenium-server-standalone-%s.jar',
seleniumV4: '%s/%s/selenium-server-%s.jar',
chrome: '%s/%s/chromedriver_%s.zip',
ie: '%s/%s/IEDriverServer_%s_%s.zip',
firefox: '%s/%s/%s-%s-%s',
Expand Down Expand Up @@ -45,7 +47,7 @@ async function computeDownloadUrls(opts) {
selenium:
opts.seleniumFullURL ||
util.format(
urls.selenium,
isSelenium4(opts.seleniumVersion) ? urls.seleniumV4 : urls.selenium,
opts.seleniumBaseURL,
opts.seleniumVersion.replace(/(\d+\.\d+)\.\d+/, '$1'),
opts.seleniumVersion
Expand Down
5 changes: 3 additions & 2 deletions lib/get-selenium-status-url.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs');
const { isSelenium4 } = require('./isSelenium4');

const PROCESS_TYPES = {
STANDALONE: 0,
Expand Down Expand Up @@ -31,7 +32,7 @@ exports.getRunningProcessType = function (seleniumArgs) {
return parseRole(role);
};

exports.getSeleniumStatusUrl = function (seleniumArgs) {
exports.getSeleniumStatusUrl = function (seleniumArgs, opts) {
const nodeConfigArg = seleniumArgs.indexOf('-nodeConfig');
const portArg = seleniumArgs.indexOf('-port');
const hostArg = seleniumArgs.indexOf('-host');
Expand Down Expand Up @@ -68,7 +69,7 @@ exports.getSeleniumStatusUrl = function (seleniumArgs) {
}

const statusURI = new URL('http://' + host);
const nodeStatusAPIPath = '/wd/hub/status';
const nodeStatusAPIPath = isSelenium4(opts.version) ? '/status' : '/wd/hub/status';
const hubStatusAPIPath = '/grid/api/hub';

switch (processType) {
Expand Down
5 changes: 5 additions & 0 deletions lib/isSelenium4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const isSelenium4 = (seleniumVersion = '') => seleniumVersion.startsWith('4.');

module.exports = {
isSelenium4,
};
9 changes: 7 additions & 2 deletions lib/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const computeFsPaths = require('./compute-fs-paths');
const defaultConfig = require('./default-config')();
const noop = require('./noop');
const { checkArgs } = require('./check-args');
const { isSelenium4 } = require('./isSelenium4');

function start(_opts, _cb) {
const { opts, cb } = checkArgs('Start API', _opts, _cb);
Expand All @@ -28,6 +29,10 @@ function start(_opts, _cb) {
opts.version = defaultConfig.version;
}

if (isSelenium4(opts.version) && opts.seleniumArgs.length === 0) {
opts.seleniumArgs.push('standalone');
}

if (!opts.spawnCb) {
opts.spawnCb = noop;
}
Expand Down Expand Up @@ -101,7 +106,7 @@ function start(_opts, _cb) {

args = args.concat(opts.seleniumArgs);

checkPathsExistence(getInstallPaths(fsPaths), (errExist) => {
checkPathsExistence(getInstallPaths(fsPaths), opts, (errExist) => {
if (errExist) {
cb(errExist);
return;
Expand All @@ -115,7 +120,7 @@ function start(_opts, _cb) {

selenium.on('exit', errorIfNeverStarted);

checkStarted(args).then(function started(errStarted) {
checkStarted(args, opts).then(function started(errStarted) {
process.nextTick(() => {
// Add empty handler to stdout and stderr so the buffers can be flushed
// otherwise the process would eat up memory for nothing and crash
Expand Down
35 changes: 21 additions & 14 deletions test/get-selenium-hub-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const assert = require('assert');
const statusUrl = require('../lib/get-selenium-status-url');

const nodeStatusAPIPath = '/wd/hub/status';
const nodeStatusAPIPath = (isV4) => (isV4 ? '/status' : '/wd/hub/status');
const hubStatusAPIPath = '/grid/api/hub';
describe('getRunningProcessType', () => {
const tests = [
Expand Down Expand Up @@ -30,12 +30,13 @@ describe('getRunningProcessType', () => {
describe('getSeleniumStatusUrl', () => {
const data = [
// Started as a standalone Selenium Server
{ args: [], expectedUrl: 'localhost:4444' + nodeStatusAPIPath },
{ args: ['-port', '5678'], expectedUrl: 'localhost:5678' + nodeStatusAPIPath },
{ args: ['-hub', 'https://foo/wd/register'], expectedUrl: 'localhost:4444' + nodeStatusAPIPath },
{ args: [], expectedUrl: 'localhost:4444' + nodeStatusAPIPath(false) },
{ args: [], expectedUrl: 'localhost:4444' + nodeStatusAPIPath(true), seleniumVersion: '4.0.0-alpha-7' },
{ args: ['-port', '5678'], expectedUrl: 'localhost:5678' + nodeStatusAPIPath(false) },
{ args: ['-hub', 'https://foo/wd/register'], expectedUrl: 'localhost:4444' + nodeStatusAPIPath(false) },
{
args: ['-hub', 'https://foo:6666/wd/register', '-port', '7777'],
expectedUrl: 'localhost:7777' + nodeStatusAPIPath,
expectedUrl: 'localhost:7777' + nodeStatusAPIPath(false),
},

// Started as a Selenium Grid hub
Expand All @@ -49,22 +50,28 @@ describe('getSeleniumStatusUrl', () => {
},

// Started as a Selenium Grid node
{ args: ['-role', 'node'], expectedUrl: 'localhost:5555' + nodeStatusAPIPath },
{ args: ['-role', 'node', '-port', '7777'], expectedUrl: 'localhost:7777' + nodeStatusAPIPath },
{ args: ['-role', 'node', '-host', 'alias', '-port', '7777'], expectedUrl: 'alias:7777' + nodeStatusAPIPath },
{ args: ['-role', 'node', '-hub', 'https://foo/wd/register'], expectedUrl: 'localhost:5555' + nodeStatusAPIPath },
{ args: ['-role', 'node'], expectedUrl: 'localhost:5555' + nodeStatusAPIPath(false) },
{ args: ['-role', 'node', '-port', '7777'], expectedUrl: 'localhost:7777' + nodeStatusAPIPath(false) },
{
args: ['-role', 'node', '-host', 'alias', '-port', '7777'],
expectedUrl: 'alias:7777' + nodeStatusAPIPath(false),
},
{
args: ['-role', 'node', '-hub', 'https://foo/wd/register'],
expectedUrl: 'localhost:5555' + nodeStatusAPIPath(false),
},
{
args: ['-role', 'node', '-hub', 'https://foo:6666/wd/register', '-port', '7777'],
expectedUrl: 'localhost:7777' + nodeStatusAPIPath,
expectedUrl: 'localhost:7777' + nodeStatusAPIPath(false),
},

{
args: ['-role', 'node', '-nodeConfig', path.join(__dirname, 'fixtures', 'config.node.json')],
expectedUrl: 'foo:123' + nodeStatusAPIPath,
expectedUrl: 'foo:123' + nodeStatusAPIPath(false),
},
{
args: ['-role', 'node', '-host', 'alias', '-nodeConfig', path.join(__dirname, 'fixtures', 'config.node.json')],
expectedUrl: 'alias:123' + nodeStatusAPIPath,
expectedUrl: 'alias:123' + nodeStatusAPIPath(false),
},
{
args: [
Expand All @@ -77,12 +84,12 @@ describe('getSeleniumStatusUrl', () => {
'-nodeConfig',
path.join(__dirname, 'fixtures', 'config.node.json'),
],
expectedUrl: 'alias:7777' + nodeStatusAPIPath,
expectedUrl: 'alias:7777' + nodeStatusAPIPath(false),
},
];
const testWithData = function (dataItem) {
return function () {
const actual = statusUrl.getSeleniumStatusUrl(dataItem.args);
const actual = statusUrl.getSeleniumStatusUrl(dataItem.args, { version: dataItem.seleniumVersion || '3.141.59' });
const expected = 'http://' + dataItem.expectedUrl;

assert.strictEqual(actual, expected);
Expand Down

0 comments on commit 7e575d6

Please sign in to comment.