@eyeo/get-browser-binary 0.2.0 → 0.4.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/.dockerignore +3 -0
- package/.gitlab-ci.yml +27 -20
- package/CODE_OF_CONDUCT.md +132 -0
- package/README.md +47 -9
- package/RELEASE_NOTES.md +14 -0
- package/index.js +1 -0
- package/package.json +4 -4
- package/src/browsers.js +430 -87
- package/src/utils.js +80 -9
- package/test/browsers.js +163 -0
- package/test/docker/Dockerfile +20 -0
- package/test/docker/entrypoint.sh +4 -0
- package/test/utils.js +42 -0
- package/test/runner.js +0 -178
package/src/utils.js
CHANGED
|
@@ -25,6 +25,12 @@ import got from "got";
|
|
|
25
25
|
import fsExtra from "fs-extra";
|
|
26
26
|
import dmg from "dmg";
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Downloads url resources.
|
|
30
|
+
* @param {string} url - The url of the resource to be downloaded.
|
|
31
|
+
* @param {string} destFile - The destination file path.
|
|
32
|
+
* @throws {TypeError} Invalid URL.
|
|
33
|
+
*/
|
|
28
34
|
export async function download(url, destFile) {
|
|
29
35
|
let cacheDir = path.dirname(destFile);
|
|
30
36
|
|
|
@@ -37,7 +43,11 @@ export async function download(url, destFile) {
|
|
|
37
43
|
await promisify(pipeline)(got.stream(url), writable);
|
|
38
44
|
}
|
|
39
45
|
catch (error) {
|
|
40
|
-
|
|
46
|
+
try {
|
|
47
|
+
await fs.promises.rm(tempDest, {recursive: true});
|
|
48
|
+
}
|
|
49
|
+
catch (e) {}
|
|
50
|
+
|
|
41
51
|
throw error;
|
|
42
52
|
}
|
|
43
53
|
|
|
@@ -46,7 +56,7 @@ export async function download(url, destFile) {
|
|
|
46
56
|
|
|
47
57
|
export async function extractTar(archive, dir) {
|
|
48
58
|
await fs.promises.mkdir(dir);
|
|
49
|
-
await promisify(exec)(
|
|
59
|
+
await promisify(exec)(`tar -jxf ${archive} -C ${dir}`);
|
|
50
60
|
}
|
|
51
61
|
|
|
52
62
|
export async function extractDmg(archive, dir) {
|
|
@@ -68,13 +78,74 @@ export async function extractDmg(archive, dir) {
|
|
|
68
78
|
}
|
|
69
79
|
}
|
|
70
80
|
|
|
71
|
-
export async function runWinInstaller(archive, dir) {
|
|
72
|
-
// Procedure inspired from mozinstall. Uninstaller will also need to be run.
|
|
73
|
-
// https://hg.mozilla.org/mozilla-central/file/tip/testing/mozbase/mozinstall/mozinstall/mozinstall.py
|
|
74
|
-
await promisify(exec)(`"${archive}" /extractdir=${dir}`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
81
|
export async function getBrowserVersion(driver) {
|
|
78
82
|
let version = (await driver.getCapabilities()).getBrowserVersion();
|
|
79
|
-
return parseInt(version.split(".")[0], 10);
|
|
83
|
+
return version ? parseInt(version.split(".")[0], 10) : null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Useful to unlock the driver file before replacing it or executing it
|
|
87
|
+
export async function killDriverProcess(driverName) {
|
|
88
|
+
let cmd = `kill $(pgrep ${driverName})`;
|
|
89
|
+
let shell;
|
|
90
|
+
if (process.platform == "win32") {
|
|
91
|
+
cmd = `Get-Process -Name ${driverName} | Stop-Process; Start-Sleep 1`;
|
|
92
|
+
shell = "powershell.exe";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
await promisify(exec)(cmd, {shell});
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
// Command will fail when the driver process is not found
|
|
100
|
+
if (!err.toString().includes("Command failed"))
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function wait(condition, timeout = 0, message, pollTimeout = 100) {
|
|
106
|
+
if (typeof condition !== "function")
|
|
107
|
+
throw TypeError("Wait condition must be a function");
|
|
108
|
+
|
|
109
|
+
function evaluateCondition() {
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
try {
|
|
112
|
+
resolve(condition(this));
|
|
113
|
+
}
|
|
114
|
+
catch (ex) {
|
|
115
|
+
reject(ex);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let result = new Promise((resolve, reject) => {
|
|
121
|
+
let startTime = Date.now();
|
|
122
|
+
let pollCondition = async() => {
|
|
123
|
+
evaluateCondition().then(value => {
|
|
124
|
+
let elapsed = Date.now() - startTime;
|
|
125
|
+
if (value) {
|
|
126
|
+
resolve(value);
|
|
127
|
+
}
|
|
128
|
+
else if (timeout && elapsed >= timeout) {
|
|
129
|
+
try {
|
|
130
|
+
let timeoutMessage = message ?
|
|
131
|
+
`${typeof message === "function" ? message() : message}\n` : "";
|
|
132
|
+
reject(
|
|
133
|
+
new Error(`${timeoutMessage}Wait timed out after ${elapsed}ms`)
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
catch (ex) {
|
|
137
|
+
reject(
|
|
138
|
+
new Error(`${ex.message}\nWait timed out after ${elapsed}ms`)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
setTimeout(pollCondition, pollTimeout);
|
|
144
|
+
}
|
|
145
|
+
}, reject);
|
|
146
|
+
};
|
|
147
|
+
pollCondition();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return result;
|
|
80
151
|
}
|
package/test/browsers.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2006-present eyeo GmbH
|
|
3
|
+
*
|
|
4
|
+
* This module is free software: you can redistribute it and/or modify
|
|
5
|
+
* it under the terms of the GNU General Public License as published by
|
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
* (at your option) any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU General Public License
|
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import fs from "fs";
|
|
19
|
+
import expect from "expect";
|
|
20
|
+
import path from "path";
|
|
21
|
+
|
|
22
|
+
import {BROWSERS, snapshotsBaseDir} from "../index.js";
|
|
23
|
+
import {killDriverProcess} from "../src/utils.js";
|
|
24
|
+
|
|
25
|
+
// Required to set the driver path on Windows
|
|
26
|
+
import "chromedriver";
|
|
27
|
+
import "geckodriver";
|
|
28
|
+
import "msedgedriver";
|
|
29
|
+
|
|
30
|
+
const VERSIONS = {
|
|
31
|
+
chromium: [void 0, "77.0.3865.0", "beta", "dev"],
|
|
32
|
+
firefox: [void 0, "68.0", "beta"],
|
|
33
|
+
edge: [void 0, "95.0.1020.53", "beta", "dev"],
|
|
34
|
+
opera: [void 0, "64.0.3417.92"]
|
|
35
|
+
};
|
|
36
|
+
const TEST_URL = "https://gitlab.com/eyeo/developer-experience/get-browser-binary";
|
|
37
|
+
let extensionPaths = [path.resolve(process.cwd(), "test", "extension")];
|
|
38
|
+
|
|
39
|
+
async function switchToHandle(driver, testFn) {
|
|
40
|
+
for (let handle of await driver.getAllWindowHandles()) {
|
|
41
|
+
let url;
|
|
42
|
+
try {
|
|
43
|
+
await driver.switchTo().window(handle);
|
|
44
|
+
url = await driver.getCurrentUrl();
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (testFn(url))
|
|
51
|
+
return handle;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function getHandle(driver, page) {
|
|
56
|
+
let url;
|
|
57
|
+
let handle = await driver.wait(() => switchToHandle(driver, handleUrl => {
|
|
58
|
+
if (!handleUrl)
|
|
59
|
+
return false;
|
|
60
|
+
|
|
61
|
+
url = new URL(handleUrl);
|
|
62
|
+
return url.pathname == page;
|
|
63
|
+
}), 8000, `${page} did not open`);
|
|
64
|
+
|
|
65
|
+
return handle;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function normalize(version) {
|
|
69
|
+
// Discards any numbers after the third dot. For example, "103.0.5060.134"
|
|
70
|
+
// will return "103.0.5060", and "68.0" will return "68.0"
|
|
71
|
+
let normalized = version.split(".").slice(0, 3).join(".");
|
|
72
|
+
// On Windows, Firefox beta versions look like "103.0b9", but the installed
|
|
73
|
+
// version returned by the browser is actually "103.0"
|
|
74
|
+
return normalized.split("b")[0];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (let browser of Object.keys(BROWSERS)) {
|
|
78
|
+
describe(`Browser: ${browser}`, function() {
|
|
79
|
+
this.timeout(40000);
|
|
80
|
+
|
|
81
|
+
before(async() => {
|
|
82
|
+
try {
|
|
83
|
+
await fs.promises.rm(snapshotsBaseDir, {recursive: true});
|
|
84
|
+
}
|
|
85
|
+
catch (e) {}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
for (let version of VERSIONS[browser]) {
|
|
89
|
+
describe(`Version: ${version || "latest"}`, () => {
|
|
90
|
+
let driver = null;
|
|
91
|
+
afterEach(async() => {
|
|
92
|
+
if (!driver)
|
|
93
|
+
return;
|
|
94
|
+
|
|
95
|
+
await driver.quit();
|
|
96
|
+
driver = null;
|
|
97
|
+
// Some platforms don't immediately kill the driver process
|
|
98
|
+
if (browser == "chromium")
|
|
99
|
+
await killDriverProcess("chromedriver");
|
|
100
|
+
else if (browser == "firefox")
|
|
101
|
+
await killDriverProcess("geckodriver");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("downloads", async function() {
|
|
105
|
+
if (browser == "edge" && process.platform != "linux")
|
|
106
|
+
this.skip();
|
|
107
|
+
|
|
108
|
+
let {binary, versionNumber} =
|
|
109
|
+
await BROWSERS[browser].downloadBinary(version);
|
|
110
|
+
let browserDir = browser == "opera" ? /(opera|Opera)/ : browser;
|
|
111
|
+
expect(binary).toEqual(expect.stringMatching(browserDir));
|
|
112
|
+
|
|
113
|
+
let installedVersion =
|
|
114
|
+
await BROWSERS[browser].getInstalledVersion(binary);
|
|
115
|
+
expect(installedVersion).toEqual(
|
|
116
|
+
expect.stringContaining(normalize(versionNumber)));
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("runs", async() => {
|
|
120
|
+
let names = {
|
|
121
|
+
chromium: "chrome",
|
|
122
|
+
firefox: "firefox",
|
|
123
|
+
edge: /(MicrosoftEdge|msedge)/,
|
|
124
|
+
opera: /(opera|chrome)/
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
driver = await BROWSERS[browser].getDriver(version);
|
|
128
|
+
await driver.navigate().to(TEST_URL);
|
|
129
|
+
|
|
130
|
+
expect((await driver.getCapabilities()).getBrowserName())
|
|
131
|
+
.toEqual(expect.stringMatching(names[browser]));
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("supports extra args", async() => {
|
|
135
|
+
let extraArgs = browser == "firefox" ?
|
|
136
|
+
["--devtools"] : ["auto-open-devtools-for-tabs"];
|
|
137
|
+
driver = await BROWSERS[browser].getDriver(version, {extraArgs});
|
|
138
|
+
await driver.navigate().to(TEST_URL);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("loads an extension", async() => {
|
|
142
|
+
let headless = browser == "firefox";
|
|
143
|
+
|
|
144
|
+
driver = await BROWSERS[browser].getDriver(
|
|
145
|
+
version, {headless, extensionPaths});
|
|
146
|
+
await getHandle(driver, "/index.html");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("loads an extension in incognito mode", async function() {
|
|
150
|
+
if (browser == "firefox" && version == "68.0")
|
|
151
|
+
this.skip();
|
|
152
|
+
|
|
153
|
+
driver = await BROWSERS[browser].getDriver(
|
|
154
|
+
version, {headless: false, extensionPaths, incognito: true});
|
|
155
|
+
await BROWSERS[browser].enableExtensionInIncognito(
|
|
156
|
+
driver, "Browser download test extension"
|
|
157
|
+
);
|
|
158
|
+
await getHandle(driver, "/index.html");
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
FROM node:16-bullseye-slim
|
|
2
|
+
|
|
3
|
+
# General packages
|
|
4
|
+
RUN apt-get update && apt-get install -y git procps wget unzip bzip2 gnupg
|
|
5
|
+
# xvfb (headful browser run)
|
|
6
|
+
RUN apt-get install -y libgtk-3-0 libxt6 xvfb libnss3 libxss1
|
|
7
|
+
# General browser dependencies
|
|
8
|
+
RUN apt-get install -y libgconf-2-4 libasound2 libgbm1
|
|
9
|
+
# Edge dependencies
|
|
10
|
+
RUN apt-get install -y fonts-liberation libatomic1 xdg-utils
|
|
11
|
+
# Opera dependencies
|
|
12
|
+
RUN apt-get install -y libcurl4 libgdk-pixbuf2.0-0
|
|
13
|
+
|
|
14
|
+
COPY package*.json get-browser-binary/
|
|
15
|
+
RUN cd get-browser-binary && npm install
|
|
16
|
+
|
|
17
|
+
COPY . get-browser-binary/
|
|
18
|
+
|
|
19
|
+
ENV TEST_ARGS="--grep Browser"
|
|
20
|
+
ENTRYPOINT get-browser-binary/test/docker/entrypoint.sh
|
package/test/utils.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2006-present eyeo GmbH
|
|
3
|
+
*
|
|
4
|
+
* This module is free software: you can redistribute it and/or modify
|
|
5
|
+
* it under the terms of the GNU General Public License as published by
|
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
* (at your option) any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU General Public License
|
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import fs from "fs";
|
|
19
|
+
import expect from "expect";
|
|
20
|
+
import path from "path";
|
|
21
|
+
|
|
22
|
+
import {snapshotsBaseDir, download} from "../index.js";
|
|
23
|
+
|
|
24
|
+
describe("Utils", () => {
|
|
25
|
+
it("defines a browser snapshots folder", () => expect(snapshotsBaseDir)
|
|
26
|
+
.toBe(path.join(process.cwd(), "browser-snapshots")));
|
|
27
|
+
|
|
28
|
+
let destFile = path.join(snapshotsBaseDir, "download-test.txt");
|
|
29
|
+
|
|
30
|
+
it("downloads resources", async() => {
|
|
31
|
+
let url = "https://gitlab.com/eyeo/developer-experience/get-browser-binary/-/raw/main/package.json";
|
|
32
|
+
await download(url, destFile);
|
|
33
|
+
let contents = await fs.promises.readFile(destFile, {encoding: "utf8"});
|
|
34
|
+
expect(contents).toEqual(
|
|
35
|
+
expect.stringContaining("\"name\": \"@eyeo/get-browser-binary\""));
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("does not download invalid resources", async() => {
|
|
39
|
+
expect(download("invalid", destFile)).rejects
|
|
40
|
+
.toThrow("TypeError [ERR_INVALID_URL]: Invalid URL");
|
|
41
|
+
});
|
|
42
|
+
});
|
package/test/runner.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2006-present eyeo GmbH
|
|
3
|
-
*
|
|
4
|
-
* This module is free software: you can redistribute it and/or modify
|
|
5
|
-
* it under the terms of the GNU General Public License as published by
|
|
6
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
7
|
-
* (at your option) any later version.
|
|
8
|
-
*
|
|
9
|
-
* This program is distributed in the hope that it will be useful,
|
|
10
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
-
* GNU General Public License for more details.
|
|
13
|
-
*
|
|
14
|
-
* You should have received a copy of the GNU General Public License
|
|
15
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import fs from "fs";
|
|
19
|
-
import expect from "expect";
|
|
20
|
-
import path from "path";
|
|
21
|
-
import {exec} from "child_process";
|
|
22
|
-
import {promisify} from "util";
|
|
23
|
-
|
|
24
|
-
import {BROWSERS, snapshotsBaseDir} from "../src/browsers.js";
|
|
25
|
-
|
|
26
|
-
// Required to start the driver on some platforms (e.g. Windows).
|
|
27
|
-
import "chromedriver";
|
|
28
|
-
import "geckodriver";
|
|
29
|
-
import "msedgedriver";
|
|
30
|
-
|
|
31
|
-
const VERSIONS = {
|
|
32
|
-
chromium: [void 0, "beta", "dev", "77.0.3865.0"],
|
|
33
|
-
firefox: [void 0, "beta", "68.0"],
|
|
34
|
-
edge: [void 0]
|
|
35
|
-
};
|
|
36
|
-
let extensionPaths = [path.resolve(process.cwd(), "test", "extension")];
|
|
37
|
-
|
|
38
|
-
async function switchToHandle(driver, testFn) {
|
|
39
|
-
for (let handle of await driver.getAllWindowHandles()) {
|
|
40
|
-
let url;
|
|
41
|
-
try {
|
|
42
|
-
await driver.switchTo().window(handle);
|
|
43
|
-
url = await driver.getCurrentUrl();
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (testFn(url))
|
|
50
|
-
return handle;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function getHandle(driver, page) {
|
|
55
|
-
let url;
|
|
56
|
-
let handle = await driver.wait(() => switchToHandle(driver, handleUrl => {
|
|
57
|
-
if (!handleUrl)
|
|
58
|
-
return false;
|
|
59
|
-
|
|
60
|
-
url = new URL(handleUrl);
|
|
61
|
-
return url.pathname == page;
|
|
62
|
-
}), 8000, `${page} did not open`);
|
|
63
|
-
|
|
64
|
-
return handle;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async function killDriverProcess() {
|
|
68
|
-
for (let name of ["chromedriver", "msedgedriver"]) {
|
|
69
|
-
let stdout;
|
|
70
|
-
if (process.platform == "win32") {
|
|
71
|
-
try {
|
|
72
|
-
({stdout} = await promisify(exec)(
|
|
73
|
-
`(Get-Process -Name ${name}).Id | Stop-Process`,
|
|
74
|
-
{shell: "powershell.exe"}
|
|
75
|
-
));
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
if (err.toString().includes("Command failed"))
|
|
79
|
-
continue; // Command will fail when driver process is not found
|
|
80
|
-
|
|
81
|
-
throw err;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
try {
|
|
86
|
-
({stdout} =
|
|
87
|
-
await promisify(exec)(`ps -a | grep ${name} | grep -v grep`));
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
if (err.toString().includes("Command failed"))
|
|
91
|
-
continue; // Command will fail when driver process is not found
|
|
92
|
-
|
|
93
|
-
throw err;
|
|
94
|
-
}
|
|
95
|
-
let pid = /\s*(\d*)/.exec(stdout)[1]; // first number after any spaces
|
|
96
|
-
await promisify(exec)(`kill ${pid}`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
for (let browser of Object.keys(BROWSERS)) {
|
|
102
|
-
for (let version of VERSIONS[browser]) {
|
|
103
|
-
describe(`Browser: ${browser} ${version || "latest"}`, function() {
|
|
104
|
-
this.timeout(15000);
|
|
105
|
-
|
|
106
|
-
before(async() => {
|
|
107
|
-
try {
|
|
108
|
-
await fs.promises.rm(snapshotsBaseDir, {recursive: true});
|
|
109
|
-
}
|
|
110
|
-
catch (e) {}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
let driver = null;
|
|
114
|
-
afterEach(async() => {
|
|
115
|
-
if (!driver)
|
|
116
|
-
return;
|
|
117
|
-
|
|
118
|
-
await driver.quit();
|
|
119
|
-
driver = null;
|
|
120
|
-
// Some platforms don't immediately kill the webdriver process
|
|
121
|
-
await killDriverProcess();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("downloads", async function() {
|
|
125
|
-
if (browser == "edge")
|
|
126
|
-
// Edge download is not implemented. It is assumed to be installed.
|
|
127
|
-
this.skip();
|
|
128
|
-
|
|
129
|
-
this.timeout(40000);
|
|
130
|
-
let {binary} = await BROWSERS[browser].downloadBinary(version);
|
|
131
|
-
|
|
132
|
-
await fs.promises.access(binary);
|
|
133
|
-
expect(binary).toEqual(
|
|
134
|
-
expect.stringContaining(path.join(snapshotsBaseDir, browser)));
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it("runs", async() => {
|
|
138
|
-
let names = {
|
|
139
|
-
chromium: "chrome",
|
|
140
|
-
firefox: "firefox",
|
|
141
|
-
edge: /(MicrosoftEdge|msedge)/
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
driver = await BROWSERS[browser].getDriver(version);
|
|
145
|
-
await driver.navigate().to("about:blank");
|
|
146
|
-
|
|
147
|
-
expect((await driver.getCapabilities()).getBrowserName())
|
|
148
|
-
.toEqual(expect.stringMatching(names[browser]));
|
|
149
|
-
});
|
|
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
|
-
|
|
157
|
-
it("loads an extension", async() => {
|
|
158
|
-
let headless = browser == "firefox";
|
|
159
|
-
|
|
160
|
-
driver = await BROWSERS[browser].getDriver(
|
|
161
|
-
version, {headless, extensionPaths});
|
|
162
|
-
await getHandle(driver, "/index.html");
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("loads an extension in incognito mode", async function() {
|
|
166
|
-
if (browser != "firefox" || version == "68.0")
|
|
167
|
-
this.skip();
|
|
168
|
-
|
|
169
|
-
driver = await BROWSERS[browser].getDriver(
|
|
170
|
-
version, {headless: false, extensionPaths, incognito: true});
|
|
171
|
-
await BROWSERS[browser].enableExtensionInIncognito(
|
|
172
|
-
driver, "Browser download test extension"
|
|
173
|
-
);
|
|
174
|
-
await getHandle(driver, "/index.html");
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|