Skip to content

Commit e360eaa

Browse files
authored
fixed args prefix for selenium3 (#722)
1 parent f6ceca0 commit e360eaa

File tree

4 files changed

+138
-30
lines changed

4 files changed

+138
-30
lines changed

lib/get-selenium-status-url.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ exports.getRunningProcessType = function (seleniumArgs) {
4646
*/
4747
exports.getSeleniumStatusUrl = function (seleniumArgs, opts) {
4848
const nodeConfigArg = seleniumArgs.indexOf('-nodeConfig');
49-
const portArg = seleniumArgs.indexOf('--port');
50-
const hostArg = seleniumArgs.indexOf('--host');
49+
50+
// args prefix differs for selenium3 and selenium4
51+
let argsPrefix = '--';
52+
if (!isSelenium4(opts.version)) {
53+
argsPrefix = '-';
54+
}
55+
const portArg = seleniumArgs.indexOf(`${argsPrefix}port`);
56+
const hostArg = seleniumArgs.indexOf(`${argsPrefix}host`);
57+
5158
let host = 'localhost';
5259
let port;
5360
let config;

package-lock.json

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/compute-download-urls-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('compute-download-urls', () => {
109109
});
110110

111111
it('generates URLs that respond successfully', async function () {
112-
this.timeout(5000); // HTTP requests take a few seconds
112+
this.timeout(10000); // HTTP requests take a few seconds
113113

114114
const versionsExpectedToFail = ['3.150.0'];
115115

test/get-selenium-hub-test.js

Lines changed: 112 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const statusUrl = require('../lib/get-selenium-status-url');
44

55
const nodeStatusAPIPath = (isV4) => (isV4 ? '/status' : '/wd/hub/status');
66
const hubStatusAPIPath = '/grid/api/hub';
7+
78
describe('getRunningProcessType', () => {
89
const tests = [
910
// Started as a standalone Selenium Server
@@ -28,54 +29,148 @@ describe('getRunningProcessType', () => {
2829
});
2930

3031
describe('getSeleniumStatusUrl', () => {
32+
// selenium 4 version
33+
const seleniumVersion = '4.5.0';
3134
const data = [
3235
// Started as a standalone Selenium Server
3336
{ args: [], expectedUrl: 'localhost:4444' + nodeStatusAPIPath(false) },
34-
{ args: [], expectedUrl: 'localhost:4444' + nodeStatusAPIPath(true), seleniumVersion: '4.0.0-alpha-7' },
35-
{ args: ['--port', '5678'], expectedUrl: 'localhost:5678' + nodeStatusAPIPath(false) },
37+
{ args: [], expectedUrl: 'localhost:4444' + nodeStatusAPIPath(true), seleniumVersion },
38+
39+
{ args: ['-port', '5678'], expectedUrl: 'localhost:5678' + nodeStatusAPIPath(false) },
40+
{
41+
args: ['--port', '5678'],
42+
expectedUrl: 'localhost:5678' + nodeStatusAPIPath(true),
43+
seleniumVersion,
44+
},
45+
3646
{ args: ['--grid-url', 'https://foo/wd/register'], expectedUrl: 'localhost:4444' + nodeStatusAPIPath(false) },
3747
{
38-
args: ['--grid-url', 'https://foo:6666/wd/register', '--port', '7777'],
48+
args: ['--grid-url', 'https://foo/wd/register'],
49+
expectedUrl: 'localhost:4444' + nodeStatusAPIPath(true),
50+
seleniumVersion,
51+
},
52+
53+
{
54+
args: ['--grid-url', 'https://foo:6666/wd/register', '-port', '7777'],
3955
expectedUrl: 'localhost:7777' + nodeStatusAPIPath(false),
4056
},
4157

58+
{
59+
args: ['--grid-url', 'https://foo:6666/wd/register', '--port', '7777'],
60+
expectedUrl: 'localhost:7777' + nodeStatusAPIPath(true),
61+
seleniumVersion,
62+
},
63+
4264
// Started as a Selenium Grid hub
4365
{ args: ['hub'], expectedUrl: 'localhost:4444' + hubStatusAPIPath },
44-
{ args: ['hub', '--port', '12345'], expectedUrl: 'localhost:12345' + hubStatusAPIPath },
45-
{ args: ['hub', '--host', 'alias', '--port', '12345'], expectedUrl: 'alias:12345' + hubStatusAPIPath },
66+
{ args: ['hub'], expectedUrl: 'localhost:4444' + hubStatusAPIPath, seleniumVersion },
67+
68+
{ args: ['hub', '-port', '12345'], expectedUrl: 'localhost:12345' + hubStatusAPIPath },
69+
{
70+
args: ['hub', '--port', '12345'],
71+
expectedUrl: 'localhost:12345' + hubStatusAPIPath,
72+
seleniumVersion,
73+
},
74+
75+
{ args: ['hub', '-host', 'alias', '-port', '12345'], expectedUrl: 'alias:12345' + hubStatusAPIPath },
76+
{
77+
args: ['hub', '--host', 'alias', '--port', '12345'],
78+
expectedUrl: 'alias:12345' + hubStatusAPIPath,
79+
seleniumVersion,
80+
},
81+
82+
{
83+
args: ['hub', '--grid-url', 'https://foo/wd/register'],
84+
expectedUrl: 'localhost:4444' + hubStatusAPIPath,
85+
},
4686
{
4787
args: ['hub', '--grid-url', 'https://foo/wd/register'],
4888
expectedUrl: 'localhost:4444' + hubStatusAPIPath,
89+
seleniumVersion,
90+
},
91+
92+
{
93+
args: ['hub', '--grid-url', 'https://foo:6666/wd/register', '-port', '12345'],
94+
expectedUrl: 'localhost:12345' + hubStatusAPIPath,
4995
},
5096
{
5197
args: ['hub', '--grid-url', 'https://foo:6666/wd/register', '--port', '12345'],
5298
expectedUrl: 'localhost:12345' + hubStatusAPIPath,
99+
seleniumVersion,
53100
},
54101

55102
// Started as a Selenium Grid node
56103
{ args: ['node'], expectedUrl: 'localhost:5555' + nodeStatusAPIPath(false) },
57-
{ args: ['node', '--port', '7777'], expectedUrl: 'localhost:7777' + nodeStatusAPIPath(false) },
104+
{ args: ['node'], expectedUrl: 'localhost:5555' + nodeStatusAPIPath(true), seleniumVersion },
105+
106+
{ args: ['node', '-port', '7777'], expectedUrl: 'localhost:7777' + nodeStatusAPIPath(false) },
58107
{
59-
args: ['node', '--host', 'alias', '--port', '7777'],
108+
args: ['node', '--port', '7777'],
109+
expectedUrl: 'localhost:7777' + nodeStatusAPIPath(true),
110+
seleniumVersion,
111+
},
112+
113+
{
114+
args: ['node', '-host', 'alias', '-port', '7777'],
60115
expectedUrl: 'alias:7777' + nodeStatusAPIPath(false),
61116
},
117+
{
118+
args: ['node', '--host', 'alias', '--port', '7777'],
119+
expectedUrl: 'alias:7777' + nodeStatusAPIPath(true),
120+
seleniumVersion,
121+
},
122+
62123
{
63124
args: ['node', '--grid-url', 'https://foo/wd/register'],
64125
expectedUrl: 'localhost:5555' + nodeStatusAPIPath(false),
65126
},
66127
{
67-
args: ['node', '--grid-url', 'https://foo:6666/wd/register', '--port', '7777'],
128+
args: ['node', '--grid-url', 'https://foo/wd/register'],
129+
expectedUrl: 'localhost:5555' + nodeStatusAPIPath(true),
130+
seleniumVersion,
131+
},
132+
133+
{
134+
args: ['node', '-grid-url', 'https://foo:6666/wd/register', '-port', '7777'],
68135
expectedUrl: 'localhost:7777' + nodeStatusAPIPath(false),
69136
},
137+
{
138+
args: ['node', '--grid-url', 'https://foo:6666/wd/register', '--port', '7777'],
139+
expectedUrl: 'localhost:7777' + nodeStatusAPIPath(true),
140+
seleniumVersion,
141+
},
70142

71143
{
72144
args: ['node', '-nodeConfig', path.join(__dirname, 'fixtures', 'config.node.json')],
73145
expectedUrl: 'foo:123' + nodeStatusAPIPath(false),
74146
},
75147
{
76-
args: ['node', '--host', 'alias', '-nodeConfig', path.join(__dirname, 'fixtures', 'config.node.json')],
148+
args: ['node', '-nodeConfig', path.join(__dirname, 'fixtures', 'config.node.json')],
149+
expectedUrl: 'foo:123' + nodeStatusAPIPath(true),
150+
seleniumVersion,
151+
},
152+
153+
{
154+
args: ['node', '-host', 'alias', '-nodeConfig', path.join(__dirname, 'fixtures', 'config.node.json')],
77155
expectedUrl: 'alias:123' + nodeStatusAPIPath(false),
78156
},
157+
{
158+
args: ['node', '--host', 'alias', '-nodeConfig', path.join(__dirname, 'fixtures', 'config.node.json')],
159+
expectedUrl: 'alias:123' + nodeStatusAPIPath(true),
160+
seleniumVersion,
161+
},
162+
{
163+
args: [
164+
'node',
165+
'-host',
166+
'alias',
167+
'-port',
168+
'7777',
169+
'-nodeConfig',
170+
path.join(__dirname, 'fixtures', 'config.node.json'),
171+
],
172+
expectedUrl: 'alias:7777' + nodeStatusAPIPath(false),
173+
},
79174
{
80175
args: [
81176
'node',
@@ -86,9 +181,11 @@ describe('getSeleniumStatusUrl', () => {
86181
'-nodeConfig',
87182
path.join(__dirname, 'fixtures', 'config.node.json'),
88183
],
89-
expectedUrl: 'alias:7777' + nodeStatusAPIPath(false),
184+
expectedUrl: 'alias:7777' + nodeStatusAPIPath(true),
185+
seleniumVersion,
90186
},
91187
];
188+
92189
const testWithData = function (dataItem) {
93190
return function () {
94191
const actual = statusUrl.getSeleniumStatusUrl(dataItem.args, { version: dataItem.seleniumVersion || '3.141.59' });
@@ -99,6 +196,10 @@ describe('getSeleniumStatusUrl', () => {
99196
};
100197

101198
data.forEach((dataItem) => {
102-
it('getSeleniumStatusUrl with seleniumArgs: ' + dataItem.args.join(' '), testWithData(dataItem));
199+
it(
200+
`getSeleniumStatusUrl (version: : ${dataItem.seleniumVersion || '3.141.59'}) with seleniumArgs :` +
201+
dataItem.args.join(' '),
202+
testWithData(dataItem)
203+
);
103204
});
104205
});

0 commit comments

Comments
 (0)