Skip to content

Commit

Permalink
feat(cli): add --chrome-path option (dequelabs#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Jul 5, 2023
1 parent ca07660 commit 7c8978d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions packages/cli/src/bin/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,15 @@ describe('cli', () => {
);
});
});

describe('--chrome-path', () => {
it('should throw error if path does not exist', async () => {
const result = await runCLI(
`file://${SIMPLE_HTML_FILE}`,
'--chrome-path="someinvalidpath"',
'--show-errors'
);
assert.include(result.stderr, 'no chrome binary at');
});
});
});
4 changes: 4 additions & 0 deletions packages/cli/src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ program
'--chromedriver-path <path>',
'Absolute path to the desired chromedriver executable'
)
.option(
'--chrome-path <path>',
'Absolute path to the desired chrome executable'
)
.action(cli);

program.parse(process.argv);
6 changes: 4 additions & 2 deletions packages/cli/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const cli = async (
rules,
disable,
loadDelay,
chromedriverPath
chromedriverPath,
chromePath
} = args;

const showErrors = args.showErrors === true;
Expand Down Expand Up @@ -67,7 +68,8 @@ const cli = async (
browser: args.browser,
timeout,
chromeOptions,
chromedriverPath
chromedriverPath,
chromePath
};

args.driver = startDriver(driverConfigs);
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/lib/webdriver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'path';
import chromedriver from 'chromedriver';
import { Builder, Capabilities, WebDriver } from 'selenium-webdriver';
import chrome from 'selenium-webdriver/chrome';
Expand All @@ -21,6 +22,10 @@ const startDriver = async (
}, options);
}

if (config.chromePath) {
options.setChromeBinaryPath(path.resolve(config.chromePath));
}

builder = new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface WebdriverConfigParams {
browser: string;
timeout: number;
chromedriverPath?: string;
chromePath?: string;
path?: string;
chromeOptions?: string[];
builder?: Builder;
Expand Down

0 comments on commit 7c8978d

Please sign in to comment.