Skip to content

Commit

Permalink
fix: respect executableDir even non-adb environment such as desktop (#…
Browse files Browse the repository at this point in the history
…383)

* chore: remove unnecessary adb check as no usage

* add test temporary

* fix test

* add a flag

* add comment

* fix lint
  • Loading branch information
KazuCocoa committed Mar 8, 2024
1 parent 602aa7b commit 0a3e80e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/chromedriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Chromedriver extends events.EventEmitter {
port = DEFAULT_PORT,
useSystemExecutable = false,
executable,
executableDir = getChromedriverDir(),
executableDir,
bundleId,
mappingPath,
cmdArgs,
Expand Down Expand Up @@ -74,6 +74,15 @@ export class Chromedriver extends events.EventEmitter {
port: this.proxyPort,
log: this._log,
});

if (this.executableDir) {
// Expects the user set the executable directory explicitly
this.isCustomExecutableDir = true;
} else {
this.isCustomExecutableDir = false;
this.executableDir = getChromedriverDir();
}

this.verbose = verbose;
this.logPath = logPath;
this.disableBuildCheck = !!disableBuildCheck;
Expand Down Expand Up @@ -323,10 +332,12 @@ export class Chromedriver extends events.EventEmitter {
}

/**
* When executableDir is given explicitly for non-adb environment,
* this method will respect the executableDir rather than the system installed binary.
* @returns {Promise<string>}
*/
async getCompatibleChromedriver() {
if (!this.adb) {
if (!this.adb && !this.isCustomExecutableDir) {
return await getChromedriverBinaryPath();
}

Expand Down
15 changes: 15 additions & 0 deletions test/unit/chromedriver-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ describe('chromedriver', function () {
const binPath = await cd.getCompatibleChromedriver();
binPath.should.eql('/path/to/chromedriver');
});

it('should search specified directory if provided', async function () {
const cd = new Chromedriver({
executableDir: '/some/local/dir/for/chromedrivers',
});

sandbox.stub(utils, 'getChromeVersion').returns('63.0.3239.99');
sandbox.stub(fs, 'glob').returns(['/some/local/dir/for/chromedrivers/chromedriver']);
sandbox.stub(tp, 'exec').returns({
stdout: 'ChromeDriver 2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',
});

const binPath = await cd.getCompatibleChromedriver();
binPath.should.eql('/some/local/dir/for/chromedrivers/chromedriver');
});
});

describe('Android', function () {
Expand Down

0 comments on commit 0a3e80e

Please sign in to comment.