Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add --chrome-path option (#700) #704

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>',
'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, type 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