Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/wrappers/pages.js

Issue 29938555: Noissue - Upgrade to selenium-webdriver 4.0.0-alpha (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Renamed loc to rect Created Nov. 9, 2018, 10:26 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/browsers/firefox.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 const TEST_PAGES_URL = "https://testpages.adblockplus.org/en/"; 20 const TEST_PAGES_URL = "https://testpages.adblockplus.org/en/";
21 21
22 const assert = require("assert"); 22 const assert = require("assert");
23 const Jimp = require("jimp"); 23 const Jimp = require("jimp");
24 const {By, until} = require("selenium-webdriver"); 24 const {By, until} = require("selenium-webdriver");
25 25
26 let lastScreenshot = Promise.resolve();
27
26 // Once we require Node.js >= 10 this should be replaced with 28 // Once we require Node.js >= 10 this should be replaced with
27 // the built-in finally() method of the Promise object. 29 // the built-in finally() method of the Promise object.
28 function promiseFinally(p, callback) 30 function promiseFinally(p, callback)
29 { 31 {
30 return p.then( 32 return p.then(
31 callback, 33 callback,
32 err => Promise.resolve(callback()).then(() => 34 err => Promise.resolve(callback()).then(() =>
33 Promise.reject(err) 35 Promise.reject(err)
34 ) 36 )
35 ); 37 );
(...skipping 20 matching lines...) Expand all
56 function takeScreenshot(element) 58 function takeScreenshot(element)
57 { 59 {
58 return element.takeScreenshot().then( 60 return element.takeScreenshot().then(
59 imageFromBase64, 61 imageFromBase64,
60 62
61 // Chrome doesn't support taking screenshots of individual elements. So as 63 // Chrome doesn't support taking screenshots of individual elements. So as
62 // a workaround, we scroll to the position of the element, take a screenshot 64 // a workaround, we scroll to the position of the element, take a screenshot
63 // of the viewport and crop it to the size and position of our element. 65 // of the viewport and crop it to the size and position of our element.
64 // This is not guaranteed to work on other browsers (mostly because 66 // This is not guaranteed to work on other browsers (mostly because
65 // the behavior of Driver.takeScreenshot() may vary across browsers). 67 // the behavior of Driver.takeScreenshot() may vary across browsers).
66 () => element.getLocation().then(loc => 68 () =>
67 element.getDriver().executeScript(` 69 lastScreenshot = Promise.all([element.getRect(),
68 window.scrollTo(${loc.x}, ${loc.y}); 70 lastScreenshot]).then(([rect]) =>
69 return [window.scrollX, window.scrollY]; 71 element.getDriver().executeScript(`
70 `).then(result => 72 window.scrollTo(${rect.x}, ${rect.y});
71 { 73 return [window.scrollX, window.scrollY];
72 let x = loc.x - result[0]; 74 `).then(result =>
73 let y = loc.y - result[1]; 75 {
76 let x = rect.x - result[0];
77 let y = rect.y - result[1];
74 78
75 return Promise.all([ 79 return element.getDriver().takeScreenshot()
76 element.getDriver().takeScreenshot().then(imageFromBase64), 80 .then(imageFromBase64)
77 element.getSize() 81 .then(img => img.crop(x, y, rect.width, rect.height));
78 ]).then(([img, size]) => 82 })
79 img.crop(x, y, size.width, size.height) 83 )
80 );
81 })
82 )
83 ).then(img => img.bitmap); 84 ).then(img => img.bitmap);
84 } 85 }
85 86
86 function getSections(driver) 87 function getSections(driver)
87 { 88 {
88 return driver.findElements(By.css("section")).then(elements => 89 return driver.findElements(By.css("section")).then(elements =>
89 Promise.all(elements.map(e => 90 Promise.all(elements.map(e =>
90 Promise.all([ 91 Promise.all([
91 e.findElement(By.css("h2")).catch(() => null), 92 e.findElement(By.css("h2")).catch(() => null),
92 e.findElement(By.className("testcase-container")).catch(() => null), 93 e.findElement(By.className("testcase-container")).catch(() => null),
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 `) 247 `)
247 ).then(([added, err]) => 248 ).then(([added, err]) =>
248 { 249 {
249 if (err) 250 if (err)
250 throw err; 251 throw err;
251 assert.ok(added, "subscription added"); 252 assert.ok(added, "subscription added");
252 }) 253 })
253 ) 254 )
254 ); 255 );
255 }); 256 });
OLDNEW
« no previous file with comments | « test/browsers/firefox.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld