Skip to content

Commit 7e7a17d

Browse files
committed
Add environment variable support for driver executables in Chrome, Edge, Firefox, IE, and Safari
1 parent 8b75d92 commit 7e7a17d

File tree

5 files changed

+318
-0
lines changed

5 files changed

+318
-0
lines changed

javascript/selenium-webdriver/test/chrome/service_test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,51 @@ test.suite(
4141
assert.ok(url.endsWith('/foo/bar/baz'), 'unexpected url: ' + url)
4242
})
4343
})
44+
45+
describe('environment variable support', function () {
46+
let originalEnvValue
47+
48+
beforeEach(function () {
49+
originalEnvValue = process.env.SE_CHROMEDRIVER
50+
})
51+
52+
afterEach(function () {
53+
if (originalEnvValue) {
54+
process.env.SE_CHROMEDRIVER = originalEnvValue
55+
} else {
56+
delete process.env.SE_CHROMEDRIVER
57+
}
58+
})
59+
60+
it('uses SE_CHROMEDRIVER environment variable when set', function () {
61+
const testPath = '/custom/path/to/chromedriver'
62+
process.env.SE_CHROMEDRIVER = testPath
63+
64+
const serviceBuilder = new chrome.ServiceBuilder()
65+
const service = serviceBuilder.build()
66+
assert.strictEqual(service.getExecutable(), testPath)
67+
})
68+
69+
it('explicit path overrides environment variable', function () {
70+
const envPath = '/env/path/to/chromedriver'
71+
const explicitPath = '/explicit/path/to/chromedriver'
72+
73+
process.env.SE_CHROMEDRIVER = envPath
74+
const serviceBuilder = new chrome.ServiceBuilder(explicitPath)
75+
const service = serviceBuilder.build()
76+
77+
assert.strictEqual(service.getExecutable(), explicitPath)
78+
})
79+
80+
it('falls back to default behavior when environment variable is not set', function () {
81+
delete process.env.SE_CHROMEDRIVER
82+
83+
const serviceBuilder = new chrome.ServiceBuilder()
84+
const service = serviceBuilder.build()
85+
// Should be null/undefined when no explicit path and no env var
86+
assert.ok(!service.getExecutable())
87+
})
88+
})
4489
})
4590
},
4691
{ browsers: ['chrome'] },

javascript/selenium-webdriver/test/edge/service_test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,51 @@ test.suite(
3939
let url = await service.start()
4040
assert(/127\.0\.0\.1/.test(url), `unexpected url: ${url}`)
4141
})
42+
43+
describe('environment variable support', function () {
44+
let originalEnvValue
45+
46+
beforeEach(function () {
47+
originalEnvValue = process.env.SE_EDGEDRIVER
48+
})
49+
50+
afterEach(function () {
51+
if (originalEnvValue) {
52+
process.env.SE_EDGEDRIVER = originalEnvValue
53+
} else {
54+
delete process.env.SE_EDGEDRIVER
55+
}
56+
})
57+
58+
it('uses SE_EDGEDRIVER environment variable when set', function () {
59+
const testPath = '/custom/path/to/edgedriver'
60+
process.env.SE_EDGEDRIVER = testPath
61+
62+
const serviceBuilder = new edge.ServiceBuilder()
63+
const service = serviceBuilder.build()
64+
assert.strictEqual(service.getExecutable(), testPath)
65+
})
66+
67+
it('explicit path overrides environment variable', function () {
68+
const envPath = '/env/path/to/edgedriver'
69+
const explicitPath = '/explicit/path/to/edgedriver'
70+
71+
process.env.SE_EDGEDRIVER = envPath
72+
const serviceBuilder = new edge.ServiceBuilder(explicitPath)
73+
const service = serviceBuilder.build()
74+
75+
assert.strictEqual(service.getExecutable(), explicitPath)
76+
})
77+
78+
it('falls back to default behavior when environment variable is not set', function () {
79+
delete process.env.SE_EDGEDRIVER
80+
81+
const serviceBuilder = new edge.ServiceBuilder()
82+
const service = serviceBuilder.build()
83+
// Should be null/undefined when no explicit path and no env var
84+
assert.ok(!service.getExecutable())
85+
})
86+
})
4287
})
4388
},
4489
{ browsers: ['MicrosoftEdge'] },
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
'use strict'
19+
20+
const assert = require('node:assert')
21+
const firefox = require('selenium-webdriver/firefox')
22+
const test = require('../../lib/test')
23+
const { getBinaryPaths } = require('selenium-webdriver/common/driverFinder')
24+
25+
test.suite(
26+
function (_env) {
27+
describe('geckodriver', function () {
28+
let service
29+
30+
afterEach(function () {
31+
if (service) {
32+
return service.kill()
33+
}
34+
})
35+
36+
it('can start geckodriver', async function () {
37+
service = new firefox.ServiceBuilder().build()
38+
service.setExecutable(getBinaryPaths(new firefox.Options()).driverPath)
39+
let url = await service.start()
40+
assert(/127\.0\.0\.1/.test(url), `unexpected url: ${url}`)
41+
})
42+
43+
describe('environment variable support', function () {
44+
let originalEnvValue
45+
46+
beforeEach(function () {
47+
originalEnvValue = process.env.SE_GECKODRIVER
48+
})
49+
50+
afterEach(function () {
51+
if (originalEnvValue) {
52+
process.env.SE_GECKODRIVER = originalEnvValue
53+
} else {
54+
delete process.env.SE_GECKODRIVER
55+
}
56+
})
57+
58+
it('uses SE_GECKODRIVER environment variable when set', function () {
59+
const testPath = '/custom/path/to/geckodriver'
60+
process.env.SE_GECKODRIVER = testPath
61+
62+
const serviceBuilder = new firefox.ServiceBuilder()
63+
const service = serviceBuilder.build()
64+
assert.strictEqual(service.getExecutable(), testPath)
65+
})
66+
67+
it('explicit path overrides environment variable', function () {
68+
const envPath = '/env/path/to/geckodriver'
69+
const explicitPath = '/explicit/path/to/geckodriver'
70+
71+
process.env.SE_GECKODRIVER = envPath
72+
const serviceBuilder = new firefox.ServiceBuilder(explicitPath)
73+
const service = serviceBuilder.build()
74+
75+
assert.strictEqual(service.getExecutable(), explicitPath)
76+
})
77+
78+
it('falls back to default behavior when environment variable is not set', function () {
79+
delete process.env.SE_GECKODRIVER
80+
81+
const serviceBuilder = new firefox.ServiceBuilder()
82+
const service = serviceBuilder.build()
83+
// Should be null/undefined when no explicit path and no env var
84+
assert.ok(!service.getExecutable())
85+
})
86+
})
87+
})
88+
},
89+
{ browsers: ['firefox'] },
90+
)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
'use strict'
19+
20+
const assert = require('node:assert')
21+
const ie = require('selenium-webdriver/ie')
22+
const test = require('../../lib/test')
23+
const { getBinaryPaths } = require('selenium-webdriver/common/driverFinder')
24+
25+
test.suite(
26+
function (_env) {
27+
describe('iedriver', function () {
28+
let service
29+
30+
afterEach(function () {
31+
if (service) {
32+
return service.kill()
33+
}
34+
})
35+
36+
it('can start iedriver', async function () {
37+
// Skip on non-Windows platforms
38+
if (process.platform !== 'win32') {
39+
this.skip()
40+
return
41+
}
42+
43+
service = new ie.ServiceBuilder().build()
44+
service.setExecutable(getBinaryPaths(new ie.Options()).driverPath)
45+
let url = await service.start()
46+
assert(/127\.0\.0\.1/.test(url), `unexpected url: ${url}`)
47+
})
48+
49+
describe('environment variable support', function () {
50+
let originalEnvValue
51+
52+
beforeEach(function () {
53+
originalEnvValue = process.env.SE_IEDRIVER
54+
})
55+
56+
afterEach(function () {
57+
if (originalEnvValue) {
58+
process.env.SE_IEDRIVER = originalEnvValue
59+
} else {
60+
delete process.env.SE_IEDRIVER
61+
}
62+
})
63+
64+
it('uses SE_IEDRIVER environment variable when set', function () {
65+
const testPath = '/custom/path/to/iedriver'
66+
process.env.SE_IEDRIVER = testPath
67+
68+
const serviceBuilder = new ie.ServiceBuilder()
69+
assert.strictEqual(serviceBuilder.getExecutable(), testPath)
70+
})
71+
72+
it('explicit path overrides environment variable', function () {
73+
const envPath = '/env/path/to/iedriver'
74+
const explicitPath = '/explicit/path/to/iedriver'
75+
76+
process.env.SE_IEDRIVER = envPath
77+
const serviceBuilder = new ie.ServiceBuilder(explicitPath)
78+
79+
assert.strictEqual(serviceBuilder.getExecutable(), explicitPath)
80+
})
81+
82+
it('falls back to default behavior when environment variable is not set', function () {
83+
delete process.env.SE_IEDRIVER
84+
85+
const serviceBuilder = new ie.ServiceBuilder()
86+
// Should be null/undefined when no explicit path and no env var
87+
assert.ok(!serviceBuilder.getExecutable())
88+
})
89+
})
90+
})
91+
},
92+
{ browsers: ['ie'] },
93+
)

javascript/selenium-webdriver/test/safari_test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,51 @@ test.suite(
3838
let url = await service.start()
3939
assert(/127\.0\.0\.1/.test(url), `unexpected url: ${url}`)
4040
})
41+
42+
describe('environment variable support', function () {
43+
let originalEnvValue
44+
45+
beforeEach(function () {
46+
originalEnvValue = process.env.SE_SAFARIDRIVER
47+
})
48+
49+
afterEach(function () {
50+
if (originalEnvValue) {
51+
process.env.SE_SAFARIDRIVER = originalEnvValue
52+
} else {
53+
delete process.env.SE_SAFARIDRIVER
54+
}
55+
})
56+
57+
it('uses SE_SAFARIDRIVER environment variable when set', function () {
58+
const testPath = '/custom/path/to/safaridriver'
59+
process.env.SE_SAFARIDRIVER = testPath
60+
61+
const serviceBuilder = new safari.ServiceBuilder()
62+
const service = serviceBuilder.build()
63+
assert.strictEqual(service.getExecutable(), testPath)
64+
})
65+
66+
it('explicit path overrides environment variable', function () {
67+
const envPath = '/env/path/to/safaridriver'
68+
const explicitPath = '/explicit/path/to/safaridriver'
69+
70+
process.env.SE_SAFARIDRIVER = envPath
71+
const serviceBuilder = new safari.ServiceBuilder(explicitPath)
72+
const service = serviceBuilder.build()
73+
74+
assert.strictEqual(service.getExecutable(), explicitPath)
75+
})
76+
77+
it('falls back to default behavior when environment variable is not set', function () {
78+
delete process.env.SE_SAFARIDRIVER
79+
80+
const serviceBuilder = new safari.ServiceBuilder()
81+
const service = serviceBuilder.build()
82+
// Should be null/undefined when no explicit path and no env var
83+
assert.ok(!service.getExecutable())
84+
})
85+
})
4186
})
4287
},
4388
{ browsers: ['safari'] },

0 commit comments

Comments
 (0)