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

Delta Between Two Patch Sets: test/wrappers/pages.js

Issue 29938555: Noissue - Upgrade to selenium-webdriver 4.0.0-alpha (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Some changes I was missing Created Nov. 9, 2018, 9:03 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « test/browsers/firefox.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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.getRect().then(rect => 68 () =>
67 element.getDriver().executeScript(` 69 lastScreenshot = Promise.all([element.getRect(),
68 window.scrollTo(${rect.x}, ${rect.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 = rect.x - result[0]; 74 `).then(result =>
73 let y = rect.y - result[1]; 75 {
74 76 let x = rect.x - result[0];
75 return element.getDriver().takeScreenshot().then( 77 let y = rect.y - result[1];
76 imageFromBase64).then(img => img.crop(x, y, rect.width, rect.height)); 78
77 }) 79 return element.getDriver().takeScreenshot()
78 ) 80 .then(imageFromBase64)
81 .then(img => img.crop(x, y, rect.width, rect.height));
82 })
83 )
79 ).then(img => img.bitmap); 84 ).then(img => img.bitmap);
80 } 85 }
81 86
82 function getSections(driver) 87 function getSections(driver)
83 { 88 {
84 return driver.findElements(By.css("section")).then(elements => 89 return driver.findElements(By.css("section")).then(elements =>
85 Promise.all(elements.map(e => 90 Promise.all(elements.map(e =>
86 Promise.all([ 91 Promise.all([
87 e.findElement(By.css("h2")).catch(() => null), 92 e.findElement(By.css("h2")).catch(() => null),
88 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
242 `) 247 `)
243 ).then(([added, err]) => 248 ).then(([added, err]) =>
244 { 249 {
245 if (err) 250 if (err)
246 throw err; 251 throw err;
247 assert.ok(added, "subscription added"); 252 assert.ok(added, "subscription added");
248 }) 253 })
249 ) 254 )
250 ); 255 );
251 }); 256 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld