Skip to content

Commit 0a3e80e

Browse files
authored
fix: respect executableDir even non-adb environment such as desktop (#383)
* chore: remove unnecessary adb check as no usage * add test temporary * fix test * add a flag * add comment * fix lint
1 parent 602aa7b commit 0a3e80e

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lib/chromedriver.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class Chromedriver extends events.EventEmitter {
4444
port = DEFAULT_PORT,
4545
useSystemExecutable = false,
4646
executable,
47-
executableDir = getChromedriverDir(),
47+
executableDir,
4848
bundleId,
4949
mappingPath,
5050
cmdArgs,
@@ -74,6 +74,15 @@ export class Chromedriver extends events.EventEmitter {
7474
port: this.proxyPort,
7575
log: this._log,
7676
});
77+
78+
if (this.executableDir) {
79+
// Expects the user set the executable directory explicitly
80+
this.isCustomExecutableDir = true;
81+
} else {
82+
this.isCustomExecutableDir = false;
83+
this.executableDir = getChromedriverDir();
84+
}
85+
7786
this.verbose = verbose;
7887
this.logPath = logPath;
7988
this.disableBuildCheck = !!disableBuildCheck;
@@ -323,10 +332,12 @@ export class Chromedriver extends events.EventEmitter {
323332
}
324333

325334
/**
335+
* When executableDir is given explicitly for non-adb environment,
336+
* this method will respect the executableDir rather than the system installed binary.
326337
* @returns {Promise<string>}
327338
*/
328339
async getCompatibleChromedriver() {
329-
if (!this.adb) {
340+
if (!this.adb && !this.isCustomExecutableDir) {
330341
return await getChromedriverBinaryPath();
331342
}
332343

test/unit/chromedriver-specs.js

+15
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ describe('chromedriver', function () {
3030
const binPath = await cd.getCompatibleChromedriver();
3131
binPath.should.eql('/path/to/chromedriver');
3232
});
33+
34+
it('should search specified directory if provided', async function () {
35+
const cd = new Chromedriver({
36+
executableDir: '/some/local/dir/for/chromedrivers',
37+
});
38+
39+
sandbox.stub(utils, 'getChromeVersion').returns('63.0.3239.99');
40+
sandbox.stub(fs, 'glob').returns(['/some/local/dir/for/chromedrivers/chromedriver']);
41+
sandbox.stub(tp, 'exec').returns({
42+
stdout: 'ChromeDriver 2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',
43+
});
44+
45+
const binPath = await cd.getCompatibleChromedriver();
46+
binPath.should.eql('/some/local/dir/for/chromedrivers/chromedriver');
47+
});
3348
});
3449

3550
describe('Android', function () {

0 commit comments

Comments
 (0)