Skip to content

Commit 4f8a55d

Browse files
committed
docs: add migration guide
1 parent 2e2ed52 commit 4f8a55d

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed

README.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ So instead you decided to pin to the `@latest` tag. This works great as now both
2929

3030
This is why this package exists. It will help keep the versions of Chrome and ChromeDriver in-sync so that your continuous integration system tests don't fail due to ChromeDriver versions.
3131

32-
So now instead of relying on pinning, you can ask the system which version of Chrome is installed and always get the version of ChromeDriver that matches. This will even work for Chrome channels that are not just Stable (i.e. Beta, Dev, and Canary).
32+
So now instead of relying on pinning, you can install the desired version of Chrome and Chromedriver. This will even work for Chrome channels that are not just Stable (i.e. Beta, Dev, and Canary).
3333

3434
Here's an example of doing just that in an npm script.
3535

@@ -46,22 +46,52 @@ If you wanted to install Chrome Beta and its associated driver:
4646
```json
4747
{
4848
"scripts": {
49-
"install:chromedriver": "browser-driver-manager install chrome@beta"
49+
"install:chrome": "browser-driver-manager install chrome@beta"
5050
}
5151
}
5252
```
5353

54+
Once installed, a directory is created in your home directory called `.browser-driver-manager`. The directory will contain a `.env` file which will list the install path of both Chrome and Chromedriver under `CHROME_TEST_PATH` and `CHROMEDRIVER_TEST_PATH` respectively.
55+
56+
```
57+
# ~/.browser-driver-manager/.env
58+
CHROME_TEST_PATH=".browser-driver-manager/chrome/mac_arm-125.0.6422.141/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing"
59+
CHROMEDRIVER_TEST_PATH=".browser-driver-manager/chromedriver/mac_arm-125.0.6422.141/chromedriver-mac-arm64/chromedriver"
60+
```
61+
62+
To use the Chrome or Chromedriver binaries, you'll have to read the contents of the file and grab the path to the desired path. For example, using [dotenv](https://www.npmjs.com/package/dotenv) you can do the following:
63+
64+
```js
65+
require('dotenv').config({ path: '~/.browser-driver-manager/.env' })
66+
```
67+
68+
## Migration from v1 to v2
69+
70+
V1 use to detect the version of Chrome installed on the system and install the corresponding version of the [chromedriver npm package](https://www.npmjs.com/package/chromedriver). However this had problems as the chromedriver package wasn't always up-to-date with the latest version so when Chrome updated to the next version, the chromedriver package could lag behind and still cause out-of-sync issues. Additionally the chromedriver package didn't always have the latest versions of non-stable channels so asking for Chrome Canary wasn't always reliable.
71+
72+
V2 uses the newly released [Chrome for Testing](https://developer.chrome.com/blog/chrome-for-testing) to manage Chrome. This enables both installing specific versions of Chrome and fixes the previous chromedriver package issue. V2 utilizes the [`puppeteer/browser`](https://pptr.dev/browsers-api) script to manage the installation of Chrome and Chromedriver as it can handle downloading the binaries (and the multiple changes to the chromedriver download URL). This means that v2 no longer uses the chromedriver npm package to get chromedriver.
73+
74+
This means in v2 you'll need to grab the Chromedriver path from the `~/.browser-driver-manager/.env` file and not from the chromedriver npm package. Additionally, you'll need to grab the Chrome path pass the path to any browser driver, such as Webdriver.
75+
76+
Here's an example of grabbing the Chromedriver path in v1 and the change for v2.
77+
78+
```js
79+
// v1
80+
const chromedriver = require('chromedriver');
81+
console.log(chromedriver.path);
82+
83+
// v2
84+
require('dotenv').config({ path: '.browser-driver-manager/.env' })
85+
console.log(process.env.CHROMEDRIVER_TEST_PATH);
86+
```
87+
5488
## Supported Platforms and Browsers
5589

5690
MacOS, Linux, and Windows platforms, and Chrome browser and drivers are supported. Firefox support is planned.
5791

5892
## System Requirements
5993

60-
Node is required to run commands.
61-
62-
Install dependencies with
63-
64-
`npm install`
94+
Node is required to run the commands.
6595

6696
## Commands and Options
6797

@@ -77,19 +107,22 @@ Install dependencies with
77107
# Install latest Chrome Beta and matching Chromedriver
78108
browser-driver-manager install chrome@beta
79109

110+
# Install ChromeDriver version 97 and matching Chromedriver
111+
browser-driver-manager install chrome@97
112+
80113
- **version:**
81114
Get the installed version of the browser or driver.
82115

83116
```bash
84117
# Get installed Chrome and Chromedriver versions
85-
browser-driver-manager version
118+
browser-driver-manager version chrome
86119
87120
- **which:**
88121
Get the installed location of the browser and driver.
89122
90123
```bash
91124
# Get installed Chrome and Chromedriver locations
92-
browser-driver-manager which
125+
browser-driver-manager which chrome
93126
```
94127

95128
### Options

src/browser-driver-manager.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ async function setEnv({ chromePath, chromedriverPath, version }) {
7575
try {
7676
await fsPromises.writeFile(
7777
envPath,
78-
`CHROME_TEST_PATH="${chromePath}"${os.EOL}CHROMEDRIVER_TEST_PATH="${chromedriverPath}"${os.EOL}VERSION="${version}"${os.EOL}`
78+
`CHROME_TEST_PATH="${chromePath}"${os.EOL}CHROMEDRIVER_TEST_PATH="${chromedriverPath}"${os.EOL}CHROME_TEST_VERSION="${version}"${os.EOL}`
79+
);
80+
console.log(
81+
`CHROME_TEST_PATH="${chromePath}"${os.EOL}CHROMEDRIVER_TEST_PATH="${chromedriverPath}"${os.EOL}CHROME_TEST_VERSION="${version}"${os.EOL}`
7982
);
80-
console.log('CHROME_TEST_PATH is set in', chromePath);
81-
console.log('CHROMEDRIVER_TEST_PATH is set in', chromedriverPath);
82-
console.log('VERSION:', version);
8383
} catch (e) {
8484
throw new ErrorWithSuggestion(
8585
`Error setting CHROME/CHROMEDRIVER_TEST_PATH/VERSION. Ensure that the environment file at ${envPath} is writable.`,
@@ -121,7 +121,7 @@ async function which() {
121121
* @throws {Error} - Environment file must have valid version.
122122
*/
123123
async function getVersion(suppressErrors = false) {
124-
const pattern = /^VERSION="([\d.]+)"$/m;
124+
const pattern = /^CHROME_TEST_VERSION="([\d.]+)"$/m;
125125
const env = await getEnv();
126126

127127
if (!env) {
@@ -139,7 +139,7 @@ async function getVersion(suppressErrors = false) {
139139
return null;
140140
}
141141
throw new Error(
142-
`No version found in the environment file. Either remove the environment file and reinstall, or add a line 'VERSION={YOUR_INSTALLED_VERSION} to it.`
142+
`No version found in the environment file. Either remove the environment file and reinstall, or add a line 'CHROME_TEST_VERSION={YOUR_INSTALLED_VERSION} to it.`
143143
);
144144
}
145145

test/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const MOCK_BDM_CACHE_DIR = path.resolve(
1919
const envPath = path.resolve(MOCK_BDM_CACHE_DIR, '.env');
2020
const chromeTestPath = `${MOCK_BDM_CACHE_DIR}/chrome/os_arch-${mockVersion}/chrome`;
2121
const chromedriverTestPath = `${MOCK_BDM_CACHE_DIR}/chromedriver/os_arch-${mockVersion}/chromedriver`;
22-
const envContents = `CHROME_TEST_PATH="${chromeTestPath}"${os.EOL}CHROMEDRIVER_TEST_PATH="${chromedriverTestPath}"${os.EOL}VERSION="${mockVersion}"`;
22+
const envContents = `CHROME_TEST_PATH="${chromeTestPath}"${os.EOL}CHROMEDRIVER_TEST_PATH="${chromedriverTestPath}"${os.EOL}CHROME_TEST_VERSION="${mockVersion}"`;
2323
const noVersionEnvContents = `CHROME_TEST_PATH="${chromeTestPath}"${os.EOL}CHROMEDRIVER_TEST_PATH="${chromedriverTestPath}"${os.EOL}"`;
2424

2525
const mockResolveBuildId = sinon.stub();
@@ -91,8 +91,11 @@ let consoleLogStub;
9191

9292
const wrapConsoleLogStub = async fn => {
9393
consoleLogStub = sinon.stub(console, 'log');
94-
await fn();
95-
consoleLogStub.restore();
94+
try {
95+
await fn();
96+
} finally {
97+
consoleLogStub.restore();
98+
}
9699
};
97100

98101
describe('browser-driver-manager', () => {

0 commit comments

Comments
 (0)