@eyeo/get-browser-binary 0.7.0 → 0.8.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 +14 -0
- package/index.js +1 -1
- package/package.json +14 -1
- package/src/browsers.js +0 -61
- package/src/utils.js +60 -0
- package/test/browsers.js +5 -2
package/RELEASE_NOTES.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# 0.8.0
|
|
2
|
+
|
|
3
|
+
- Move `takeFullPageScreenshot` to the utils module (#38)
|
|
4
|
+
- Add keywords to package.json (#36)
|
|
5
|
+
|
|
6
|
+
### Testing
|
|
7
|
+
|
|
8
|
+
- Log the running browser version on test suites (#37)
|
|
9
|
+
|
|
10
|
+
### Notes for integrators
|
|
11
|
+
|
|
12
|
+
- `takeFullPageScreenshot()` has been moved from the browsers module to the
|
|
13
|
+
utils module (!46).
|
|
14
|
+
|
|
1
15
|
# 0.7.0
|
|
2
16
|
|
|
3
17
|
- Implement takeFullPageScreenshot (#32)
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eyeo/get-browser-binary",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Install browser binaries and matching webdrivers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,6 +14,19 @@
|
|
|
14
14
|
},
|
|
15
15
|
"type": "module",
|
|
16
16
|
"main": "index.js",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"browser",
|
|
19
|
+
"chromium",
|
|
20
|
+
"chrome",
|
|
21
|
+
"firefox",
|
|
22
|
+
"msedge",
|
|
23
|
+
"chromedriver",
|
|
24
|
+
"geckodriver",
|
|
25
|
+
"msedgedriver",
|
|
26
|
+
"selenium",
|
|
27
|
+
"webdriver",
|
|
28
|
+
"selenium-webdriver"
|
|
29
|
+
],
|
|
17
30
|
"dependencies": {
|
|
18
31
|
"dmg": "^0.1.0",
|
|
19
32
|
"extract-zip": "^2.0.1",
|
package/src/browsers.js
CHANGED
|
@@ -27,7 +27,6 @@ import firefox from "selenium-webdriver/firefox.js";
|
|
|
27
27
|
import edge from "selenium-webdriver/edge.js";
|
|
28
28
|
import command from "selenium-webdriver/lib/command.js";
|
|
29
29
|
import extractZip from "extract-zip";
|
|
30
|
-
import Jimp from "jimp";
|
|
31
30
|
|
|
32
31
|
import {download, extractTar, extractDmg, killDriverProcess, wait}
|
|
33
32
|
from "./utils.js";
|
|
@@ -158,66 +157,6 @@ class Browser {
|
|
|
158
157
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1729315
|
|
159
158
|
// That is done through the UI, to be implemented by the subclass
|
|
160
159
|
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* @typedef {Object} Jimp
|
|
164
|
-
* @see https://github.com/oliver-moran/jimp/tree/master/packages/jimp
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Takes a screenshot of the full page by scrolling from top to bottom.
|
|
169
|
-
* @param {webdriver} driver - The driver controlling the browser.
|
|
170
|
-
* @property {boolean} hideScrollbars=true - Hides any scrollbars before
|
|
171
|
-
* taking the screenshot, or not.
|
|
172
|
-
* @return {Jimp} A Jimp image object containing the screenshot.
|
|
173
|
-
* @example
|
|
174
|
-
* // Getting a base-64 encoded PNG from the returned screenshot
|
|
175
|
-
* let image = await Browser.takeFullPageScreenshot(driver);
|
|
176
|
-
* let encodedPNG = await image.getBase64Async("image/png");
|
|
177
|
-
*/
|
|
178
|
-
static async takeFullPageScreenshot(driver, hideScrollbars = true) {
|
|
179
|
-
// On macOS scrollbars appear and disappear overlapping the content as
|
|
180
|
-
// scrolling occurs. Hiding the scrollbars helps getting reproducible
|
|
181
|
-
// screenshots.
|
|
182
|
-
if (hideScrollbars) {
|
|
183
|
-
await driver.executeScript(() => {
|
|
184
|
-
if (!document.head)
|
|
185
|
-
return;
|
|
186
|
-
|
|
187
|
-
let style = document.createElement("style");
|
|
188
|
-
style.textContent = "html { overflow-y: scroll; }";
|
|
189
|
-
document.head.appendChild(style);
|
|
190
|
-
if (document.documentElement.clientWidth == window.innerWidth)
|
|
191
|
-
style.textContent = "html::-webkit-scrollbar { display: none; }";
|
|
192
|
-
else
|
|
193
|
-
document.head.removeChild(style);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
let fullScreenshot = new Jimp(0, 0);
|
|
198
|
-
while (true) {
|
|
199
|
-
let [width, height, offset] = await driver.executeScript((...args) => {
|
|
200
|
-
window.scrollTo(0, args[0]);
|
|
201
|
-
// Math.ceil rounds up potential decimal values on window.scrollY,
|
|
202
|
-
// ensuring the loop will not hang due to never reaching enough
|
|
203
|
-
// fullScreenshot's height.
|
|
204
|
-
return [document.documentElement.clientWidth,
|
|
205
|
-
document.documentElement.scrollHeight,
|
|
206
|
-
Math.ceil(window.scrollY)];
|
|
207
|
-
}, fullScreenshot.bitmap.height);
|
|
208
|
-
let data = await driver.takeScreenshot();
|
|
209
|
-
let partialScreenshot = await Jimp.read(Buffer.from(data, "base64"));
|
|
210
|
-
let combinedScreenshot =
|
|
211
|
-
new Jimp(width, offset + partialScreenshot.bitmap.height);
|
|
212
|
-
combinedScreenshot.composite(fullScreenshot, 0, 0);
|
|
213
|
-
combinedScreenshot.composite(partialScreenshot, 0, offset);
|
|
214
|
-
fullScreenshot = combinedScreenshot;
|
|
215
|
-
|
|
216
|
-
if (fullScreenshot.bitmap.height >= height)
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
return fullScreenshot;
|
|
220
|
-
}
|
|
221
160
|
}
|
|
222
161
|
|
|
223
162
|
/**
|
package/src/utils.js
CHANGED
|
@@ -23,6 +23,7 @@ import {exec} from "child_process";
|
|
|
23
23
|
|
|
24
24
|
import got from "got";
|
|
25
25
|
import dmg from "dmg";
|
|
26
|
+
import Jimp from "jimp";
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Downloads url resources.
|
|
@@ -143,3 +144,62 @@ export function wait(condition, timeout = 0, message, pollTimeout = 100) {
|
|
|
143
144
|
|
|
144
145
|
return result;
|
|
145
146
|
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @typedef {Object} Jimp
|
|
150
|
+
* @see https://github.com/oliver-moran/jimp/tree/master/packages/jimp
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Takes a screenshot of the full page by scrolling from top to bottom.
|
|
155
|
+
* @param {webdriver} driver - The driver controlling the browser.
|
|
156
|
+
* @property {boolean} hideScrollbars=true - Hides any scrollbars before
|
|
157
|
+
* taking the screenshot, or not.
|
|
158
|
+
* @return {Jimp} A Jimp image object containing the screenshot.
|
|
159
|
+
* @example
|
|
160
|
+
* // Getting a base-64 encoded PNG from the returned Jimp image
|
|
161
|
+
* let image = await takeFullPageScreenshot(driver);
|
|
162
|
+
* let encodedPNG = await image.getBase64Async("image/png");
|
|
163
|
+
*/
|
|
164
|
+
export async function takeFullPageScreenshot(driver, hideScrollbars = true) {
|
|
165
|
+
// On macOS scrollbars appear and disappear overlapping the content as
|
|
166
|
+
// scrolling occurs. Hiding the scrollbars helps getting reproducible
|
|
167
|
+
// screenshots.
|
|
168
|
+
if (hideScrollbars) {
|
|
169
|
+
await driver.executeScript(() => {
|
|
170
|
+
if (!document.head)
|
|
171
|
+
return;
|
|
172
|
+
let style = document.createElement("style");
|
|
173
|
+
style.textContent = "html { overflow-y: scroll; }";
|
|
174
|
+
document.head.appendChild(style);
|
|
175
|
+
if (document.documentElement.clientWidth == window.innerWidth)
|
|
176
|
+
style.textContent = "html::-webkit-scrollbar { display: none; }";
|
|
177
|
+
else
|
|
178
|
+
document.head.removeChild(style);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
let fullScreenshot = new Jimp(0, 0);
|
|
183
|
+
while (true) {
|
|
184
|
+
let [width, height, offset] = await driver.executeScript((...args) => {
|
|
185
|
+
window.scrollTo(0, args[0]);
|
|
186
|
+
// Math.ceil rounds up potential decimal values on window.scrollY,
|
|
187
|
+
// ensuring the loop will not hang due to never reaching enough
|
|
188
|
+
// fullScreenshot's height.
|
|
189
|
+
return [document.documentElement.clientWidth,
|
|
190
|
+
document.documentElement.scrollHeight,
|
|
191
|
+
Math.ceil(window.scrollY)];
|
|
192
|
+
}, fullScreenshot.bitmap.height);
|
|
193
|
+
let data = await driver.takeScreenshot();
|
|
194
|
+
let partialScreenshot = await Jimp.read(Buffer.from(data, "base64"));
|
|
195
|
+
let combinedScreenshot =
|
|
196
|
+
new Jimp(width, offset + partialScreenshot.bitmap.height);
|
|
197
|
+
combinedScreenshot.composite(fullScreenshot, 0, 0);
|
|
198
|
+
combinedScreenshot.composite(partialScreenshot, 0, offset);
|
|
199
|
+
fullScreenshot = combinedScreenshot;
|
|
200
|
+
if (fullScreenshot.bitmap.height >= height)
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return fullScreenshot;
|
|
205
|
+
}
|
package/test/browsers.js
CHANGED
|
@@ -19,7 +19,7 @@ import fs from "fs";
|
|
|
19
19
|
import expect from "expect";
|
|
20
20
|
import path from "path";
|
|
21
21
|
|
|
22
|
-
import {BROWSERS, snapshotsBaseDir} from "../index.js";
|
|
22
|
+
import {BROWSERS, snapshotsBaseDir, takeFullPageScreenshot} from "../index.js";
|
|
23
23
|
import {killDriverProcess} from "../src/utils.js";
|
|
24
24
|
import Jimp from "jimp";
|
|
25
25
|
|
|
@@ -148,6 +148,9 @@ for (let browser of Object.keys(BROWSERS)) {
|
|
|
148
148
|
await BROWSERS[browser].getInstalledVersion(binary);
|
|
149
149
|
expect(installedVersion).toEqual(
|
|
150
150
|
expect.stringContaining(normalize(versionNumber)));
|
|
151
|
+
|
|
152
|
+
// Adding the version number to the test title for logging purposes
|
|
153
|
+
this.test.title = `${this.test.title} [v${versionNumber}]`;
|
|
151
154
|
});
|
|
152
155
|
|
|
153
156
|
it("runs", async() => {
|
|
@@ -186,7 +189,7 @@ for (let browser of Object.keys(BROWSERS)) {
|
|
|
186
189
|
driver = await BROWSERS[browser].getDriver(version);
|
|
187
190
|
await driver.navigate().to(TEST_URL_LONG_PAGE);
|
|
188
191
|
|
|
189
|
-
let fullImg = await
|
|
192
|
+
let fullImg = await takeFullPageScreenshot(driver);
|
|
190
193
|
// Taking a regular webdriver screenshot, which should be shorter
|
|
191
194
|
let data = await driver.takeScreenshot();
|
|
192
195
|
let partImg = await Jimp.read(Buffer.from(data, "base64"));
|