@eyeo/get-browser-binary 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.2.0
2
+
3
+ Change `Browser.getDriver` signature to use `driverOptions` parameter.
4
+
1
5
  # 0.1.1
2
6
 
3
7
  Change project name to `get-browser-binary`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eyeo/get-browser-binary",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Download browser binaries and matching webdrivers",
5
5
  "repository": {
6
6
  "type": "git",
package/src/browsers.js CHANGED
@@ -67,22 +67,30 @@ class Browser {
67
67
  * @see https://www.selenium.dev/selenium/docs/api/javascript/index.html
68
68
  */
69
69
 
70
+ /**
71
+ * @typedef {Object} driverOptions
72
+ * @property {boolean} headless=true - Run the browser in headless mode,
73
+ * or not.
74
+ * @property {Array.<string>} [extensionPaths=[]] - Loads extensions to the
75
+ * browser.
76
+ * @property {boolean} incognito=false - Runs the browser in incognito mode,
77
+ * or not.
78
+ * @property {boolean} insecure=false - Forces the browser to accept insecure
79
+ * certificates, or not.
80
+ * @property {Array.<string>} [extraArgs=[]] - Additional arguments to start
81
+ * the browser with.
82
+ */
83
+
70
84
  /**
71
85
  * Installs the webdriver matching the browser version and runs the
72
86
  * browser. If needed, the browser binary is also installed.
73
87
  * @param {string} version - Either full version number or channel/release.
74
88
  * Please find examples on the subclasses. On Edge this parameter has
75
89
  * no effect.
76
- * @param {boolean?} headless - Run the browser in headless mode, or not.
77
- * @param {Array.<string>?} extensionPaths - Loads extensions to the running
78
- * browser.
79
- * @param {boolean?} incognito - Runs the browser in incognito mode, or not.
80
- * @param {boolean?} insecure - Forces the browser to accept insecure
81
- certificates, or not.
90
+ * @param {driverOptions?} options - Options to start the browser with.
82
91
  * @return {webdriver}
83
92
  */
84
- static async getDriver(version, headless = true, extensionPaths = [],
85
- incognito = false, insecure = false) {
93
+ static async getDriver(version, options = {}) {
86
94
  // to be implemented by the subclass
87
95
  }
88
96
 
@@ -252,8 +260,9 @@ class Chromium extends Browser {
252
260
  }
253
261
 
254
262
  /** @see Browser.getDriver */
255
- static async getDriver(version, headless = true, extensionPaths = [],
256
- incognito = false, insecure = false) {
263
+ static async getDriver(version, {headless = true, extensionPaths = [],
264
+ incognito = false, insecure = false,
265
+ extraArgs = []} = {}) {
257
266
  if (incognito)
258
267
  throw new Error(ERROR_INCOGNITO_NOT_SUPPORTED);
259
268
 
@@ -261,7 +270,7 @@ class Chromium extends Browser {
261
270
  await Chromium.downloadBinary(version);
262
271
  await Chromium.#installDriver(revision, downloadedVersion);
263
272
 
264
- let options = new chrome.Options().addArguments("no-sandbox");
273
+ let options = new chrome.Options().addArguments("no-sandbox", ...extraArgs);
265
274
  if (extensionPaths.length > 0)
266
275
  options.addArguments(`load-extension=${extensionPaths.join(",")}`);
267
276
  if (headless)
@@ -367,8 +376,9 @@ class Firefox {
367
376
  }
368
377
 
369
378
  /** @see Browser.getDriver */
370
- static async getDriver(version, headless = true, extensionPaths = [],
371
- incognito = false, insecure = false) {
379
+ static async getDriver(version, {headless = true, extensionPaths = [],
380
+ incognito = false, insecure = false,
381
+ extraArgs = []} = {}) {
372
382
  let {binary} = await Firefox.downloadBinary(version);
373
383
 
374
384
  let options = new firefox.Options();
@@ -378,6 +388,8 @@ class Firefox {
378
388
  options.addArguments("--private");
379
389
  if (insecure)
380
390
  options.set("acceptInsecureCerts", true);
391
+ if (extraArgs.length > 0)
392
+ options.addArguments(...extraArgs);
381
393
  options.setBinary(binary);
382
394
 
383
395
  let driver = await new webdriver.Builder()
@@ -501,14 +513,15 @@ class Edge {
501
513
  }
502
514
 
503
515
  /** @see Browser.getDriver */
504
- static async getDriver(version, headless = true, extensionPaths = [],
505
- incognito = false, insecure = false) {
516
+ static async getDriver(version, {headless = true, extensionPaths = [],
517
+ incognito = false, insecure = false,
518
+ extraArgs = []} = {}) {
506
519
  if (incognito)
507
520
  throw new Error(ERROR_INCOGNITO_NOT_SUPPORTED);
508
521
 
509
522
  await Edge.#installDriver();
510
523
 
511
- let args = ["no-sandbox"];
524
+ let args = ["no-sandbox", ...extraArgs];
512
525
  if (headless)
513
526
  args.push("headless");
514
527
  if (extensionPaths.length > 0)
package/test/runner.js CHANGED
@@ -148,11 +148,17 @@ for (let browser of Object.keys(BROWSERS)) {
148
148
  .toEqual(expect.stringMatching(names[browser]));
149
149
  });
150
150
 
151
+ it("supports extra args", async() => {
152
+ driver = await BROWSERS[browser].getDriver(
153
+ version, {extraArgs: ["auto-open-devtools-for-tabs"]});
154
+ await driver.navigate().to("about:blank");
155
+ });
156
+
151
157
  it("loads an extension", async() => {
152
158
  let headless = browser == "firefox";
153
159
 
154
- driver = await BROWSERS[browser].getDriver(version, headless,
155
- extensionPaths);
160
+ driver = await BROWSERS[browser].getDriver(
161
+ version, {headless, extensionPaths});
156
162
  await getHandle(driver, "/index.html");
157
163
  });
158
164
 
@@ -160,8 +166,8 @@ for (let browser of Object.keys(BROWSERS)) {
160
166
  if (browser != "firefox" || version == "68.0")
161
167
  this.skip();
162
168
 
163
- driver = await BROWSERS[browser].getDriver(version, false,
164
- extensionPaths, true);
169
+ driver = await BROWSERS[browser].getDriver(
170
+ version, {headless: false, extensionPaths, incognito: true});
165
171
  await BROWSERS[browser].enableExtensionInIncognito(
166
172
  driver, "Browser download test extension"
167
173
  );