sefiutils 1.0.0 → 1.0.1
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/lib/fiberUtils.d.ts +13 -0
- package/lib/fiberUtils.d.ts.map +1 -0
- package/lib/fiberUtils.js +60 -0
- package/lib/fiberUtils.js.map +1 -0
- package/lib/globalSetup.d.ts +22 -0
- package/lib/globalSetup.d.ts.map +1 -0
- package/lib/globalSetup.js +88 -0
- package/lib/globalSetup.js.map +1 -0
- package/{src/globalTeardown.ts → lib/globalTeardown.d.ts} +5 -12
- package/lib/globalTeardown.d.ts.map +1 -0
- package/lib/globalTeardown.js +34 -0
- package/lib/globalTeardown.js.map +1 -0
- package/lib/localSetup.d.ts +4 -0
- package/lib/localSetup.d.ts.map +1 -0
- package/lib/localSetup.js +139 -0
- package/lib/localSetup.js.map +1 -0
- package/lib/localTeardown.d.ts +6 -0
- package/lib/localTeardown.d.ts.map +1 -0
- package/lib/localTeardown.js +28 -0
- package/lib/localTeardown.js.map +1 -0
- package/lib/seUtils.d.ts +127 -0
- package/lib/seUtils.d.ts.map +1 -0
- package/lib/seUtils.js +510 -0
- package/lib/seUtils.js.map +1 -0
- package/package.json +4 -1
- package/.gitlab-ci.yml +0 -20
- package/jest.config.js +0 -11
- package/logo.graffle +0 -0
- package/logo.png +0 -0
- package/src/fiberUtils.ts +0 -60
- package/src/globalSetup.ts +0 -62
- package/src/localSetup.ts +0 -100
- package/src/localTeardown.ts +0 -14
- package/src/seUtils.ts +0 -448
- package/tests/tsconfig.json +0 -7
- package/tsconfig.json +0 -102
- /package/{src → lib}/execScripts/dom.js +0 -0
- /package/{src → lib}/execScripts/fiber.js +0 -0
package/lib/seUtils.js
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.getButtonsAndHRefs = exports.getAllTextNodes = exports.getInheritedColorsByJS = exports.getInheritedBackgroundColorsByJS = exports.setViewPortSize = exports.setBrowserWindowSize = exports.isInViewPort = exports.getViewPortSize = exports.getInnerSizeOfWindow = exports.getComputedStyles = exports.getTextContents = exports.getRectsOfContent = exports.getRects = exports.getBoundingClientRects = exports.getBoundingClientRect = exports.getElementContainingText = exports.getElementByTag = exports.getElementByClass = exports.getElementById = exports.describe = exports.saveScreenshot = exports.waitFor = exports.circa = exports.toFloor = exports.boundsToString = exports.execScript = void 0;
|
|
39
|
+
/**
|
|
40
|
+
* (C) Jens von Pilgrim, 2022
|
|
41
|
+
*/
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const fsPromises = __importStar(require("fs/promises"));
|
|
44
|
+
const path_1 = __importDefault(require("path"));
|
|
45
|
+
const selenium_webdriver_1 = require("selenium-webdriver");
|
|
46
|
+
function execScript(driver, scriptName, fct) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const scriptPath = path_1.default.join(path_1.default.dirname(__filename), scriptName);
|
|
49
|
+
const script = fs.readFileSync(scriptPath, "utf-8");
|
|
50
|
+
const res = yield driver.executeScript(script + `
|
|
51
|
+
return ${fct}();
|
|
52
|
+
`);
|
|
53
|
+
return res;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
exports.execScript = execScript;
|
|
57
|
+
function boundsToString(bounds) {
|
|
58
|
+
return `(${bounds.left};${bounds.top})x(${bounds.right};${bounds.bottom})`;
|
|
59
|
+
}
|
|
60
|
+
exports.boundsToString = boundsToString;
|
|
61
|
+
function toFloor(bounds) {
|
|
62
|
+
const floors = [];
|
|
63
|
+
for (const b of bounds) {
|
|
64
|
+
floors.push({
|
|
65
|
+
top: Math.floor(b.top),
|
|
66
|
+
bottom: Math.floor(b.bottom),
|
|
67
|
+
left: Math.floor(b.left),
|
|
68
|
+
right: Math.floor(b.right)
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return floors;
|
|
72
|
+
}
|
|
73
|
+
exports.toFloor = toFloor;
|
|
74
|
+
/**
|
|
75
|
+
* Coordinates are sometimes floats. We compare two numbers with a delta of 1 to ignore rounding problems.
|
|
76
|
+
*/
|
|
77
|
+
function circa(n1, n2) {
|
|
78
|
+
const delta = n1 - n2;
|
|
79
|
+
return Math.abs(delta) < 1;
|
|
80
|
+
}
|
|
81
|
+
exports.circa = circa;
|
|
82
|
+
function waitFor(callback, timeout = 1000, intervalTime = 100) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
// try first time
|
|
85
|
+
const start = new Date().getTime();
|
|
86
|
+
try {
|
|
87
|
+
const result = yield callback();
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
// ignore error
|
|
92
|
+
}
|
|
93
|
+
// if error, try until timeout ms have passed
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const interval = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
try {
|
|
97
|
+
const result = yield callback();
|
|
98
|
+
clearInterval(interval);
|
|
99
|
+
resolve(result);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
const duration = new Date().getTime() - start;
|
|
103
|
+
if (duration > timeout) {
|
|
104
|
+
clearInterval(interval);
|
|
105
|
+
reject(error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}), intervalTime);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
exports.waitFor = waitFor;
|
|
113
|
+
/**
|
|
114
|
+
* Takes screenshot of current window and saves it to the given file.
|
|
115
|
+
* The folder is created if it does not yet exists.
|
|
116
|
+
*/
|
|
117
|
+
function saveScreenshot(driver, fileName) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const pngBase64 = yield driver.takeScreenshot();
|
|
120
|
+
const dirName = path_1.default.dirname(fileName);
|
|
121
|
+
if (!fs.existsSync(dirName)) {
|
|
122
|
+
yield fsPromises.mkdir(dirName, { recursive: true });
|
|
123
|
+
}
|
|
124
|
+
yield fsPromises.writeFile(fileName, pngBase64, 'base64');
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
exports.saveScreenshot = saveScreenshot;
|
|
128
|
+
/**
|
|
129
|
+
* Helper function for printing out an element (tag, id if present)
|
|
130
|
+
*/
|
|
131
|
+
function describe(we) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
let s = yield we.getTagName();
|
|
134
|
+
const id = yield we.getAttribute("id");
|
|
135
|
+
if (id) {
|
|
136
|
+
s += "#" + id;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
const clazz = yield we.getAttribute("class");
|
|
140
|
+
if (clazz) {
|
|
141
|
+
s += "." + clazz;
|
|
142
|
+
}
|
|
143
|
+
let text = yield we.getText();
|
|
144
|
+
s += ` ("${text.substring(0, 7)}${text.length > 7 ? '…' : ''})"`;
|
|
145
|
+
}
|
|
146
|
+
return s;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
exports.describe = describe;
|
|
150
|
+
/**
|
|
151
|
+
* Gets the element by means of `WebElement` by its id attribute.
|
|
152
|
+
*/
|
|
153
|
+
function getElementById(driver, id) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
const el = yield driver.findElement(selenium_webdriver_1.By.id(id));
|
|
156
|
+
return el;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
exports.getElementById = getElementById;
|
|
160
|
+
/**
|
|
161
|
+
* Gets the first element by means of `WebElement` by its class attribute.
|
|
162
|
+
*/
|
|
163
|
+
function getElementByClass(driver, clazz) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
const el = yield driver.findElement(selenium_webdriver_1.By.className(clazz));
|
|
166
|
+
return el;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
exports.getElementByClass = getElementByClass;
|
|
170
|
+
/**
|
|
171
|
+
* Gets the first element by means of `WebElement` by its tag name.
|
|
172
|
+
*/
|
|
173
|
+
function getElementByTag(driver, tagName) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
const el = yield driver.findElement(selenium_webdriver_1.By.css(tagName));
|
|
176
|
+
return el;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
exports.getElementByTag = getElementByTag;
|
|
180
|
+
/**
|
|
181
|
+
* Returns first element containing given text or undefined.
|
|
182
|
+
*
|
|
183
|
+
* Test in browser console: `$x("//*[contains(text(), 'Hello')]")`
|
|
184
|
+
*/
|
|
185
|
+
function getElementContainingText(driver, text) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
try {
|
|
188
|
+
// cf. https://stackoverflow.com/questions/3655549/xpath-containstext-some-string-doesnt-work-when-used-with-node-with-more
|
|
189
|
+
//const el = await driver.findElement(By.xpath(`//*[contains(text(), "${text}")]`));
|
|
190
|
+
const el = yield driver.findElement(selenium_webdriver_1.By.xpath(`//*[text()[contains(., '${text}')]]`));
|
|
191
|
+
return el;
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
exports.getElementContainingText = getElementContainingText;
|
|
199
|
+
/**
|
|
200
|
+
* Returns the bounding client rect (the bounding box relative to the viewport)
|
|
201
|
+
* of an element (found by its is attribute) by means of a JavaScript call.
|
|
202
|
+
*/
|
|
203
|
+
function getBoundingClientRect(driver, id) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
const bcr = yield driver.executeScript('return document.getElementById("' + id + '").getBoundingClientRect()');
|
|
206
|
+
return bcr;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
exports.getBoundingClientRect = getBoundingClientRect;
|
|
210
|
+
/**
|
|
211
|
+
* Returns all {@link getBoundingClientRect} values of the elements
|
|
212
|
+
* found in the given element list.
|
|
213
|
+
* The element list is computed by means of JavaScript code,
|
|
214
|
+
* e.g. `document.getElementsByClassName('grid').item(0).children`.
|
|
215
|
+
*
|
|
216
|
+
* @param elementList JavaScript code to determine the element list
|
|
217
|
+
*/
|
|
218
|
+
function getBoundingClientRects(driver, jsElementList) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
const bcr = yield driver.executeScript(`return (()=>{
|
|
221
|
+
const elements = ${jsElementList};
|
|
222
|
+
const bounds=[];
|
|
223
|
+
for (let el of elements) { bounds.push(el.getBoundingClientRect()) }
|
|
224
|
+
return bounds;
|
|
225
|
+
})()`);
|
|
226
|
+
return bcr;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
exports.getBoundingClientRects = getBoundingClientRects;
|
|
230
|
+
/**
|
|
231
|
+
* Returns the rects using the driver API.
|
|
232
|
+
*/
|
|
233
|
+
function getRects(driver, locator) {
|
|
234
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
const elements = yield driver.findElements(locator);
|
|
236
|
+
const bounds = [];
|
|
237
|
+
for (const element of elements) {
|
|
238
|
+
const rect = yield element.getRect();
|
|
239
|
+
bounds.push({
|
|
240
|
+
top: rect.x, left: rect.y,
|
|
241
|
+
bottom: rect.x + rect.width, right: rect.y + rect.height
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
return bounds;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
exports.getRects = getRects;
|
|
248
|
+
/**
|
|
249
|
+
* Returns the rects of the first child (of each found element) using the driver API.
|
|
250
|
+
*/
|
|
251
|
+
function getRectsOfContent(driver, locator) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
const elements = yield driver.findElements(locator);
|
|
254
|
+
const bounds = [];
|
|
255
|
+
for (const element of elements) {
|
|
256
|
+
const rect = yield element.getRect();
|
|
257
|
+
bounds.push({
|
|
258
|
+
top: rect.x, left: rect.y,
|
|
259
|
+
bottom: rect.x + rect.width, right: rect.y + rect.height
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
return bounds;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
exports.getRectsOfContent = getRectsOfContent;
|
|
266
|
+
/**
|
|
267
|
+
* Returns all text content of the elements
|
|
268
|
+
* found in the given element list.
|
|
269
|
+
* The elements list is computed by means of JavaScript code,
|
|
270
|
+
* e.g. `document.getElementsByClassName('grid').item(0).children`.
|
|
271
|
+
*
|
|
272
|
+
* This is useful in combination with {@link getBoundingClientRects} in
|
|
273
|
+
* order to describe the items.
|
|
274
|
+
*
|
|
275
|
+
* @param elementList JavaScript code to determine the element list
|
|
276
|
+
*/
|
|
277
|
+
function getTextContents(driver, jsElementList) {
|
|
278
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
279
|
+
const tcs = yield driver.executeScript(`const elements = ${jsElementList};
|
|
280
|
+
const tcs=[];
|
|
281
|
+
for (let el of elements) { tcs.push(el.textContent) }
|
|
282
|
+
return tcs;
|
|
283
|
+
`);
|
|
284
|
+
return tcs;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
exports.getTextContents = getTextContents;
|
|
288
|
+
/**
|
|
289
|
+
* Returns all computed styles of the elements
|
|
290
|
+
* found in the given element list.
|
|
291
|
+
* The elements list is computed by means of JavaScript code,
|
|
292
|
+
* e.g. `document.getElementsByClassName('grid').item(0).children`.
|
|
293
|
+
*
|
|
294
|
+
* @param elementList JavaScript code to determine the element list
|
|
295
|
+
*/
|
|
296
|
+
function getComputedStyles(driver, jsElementList, style) {
|
|
297
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
298
|
+
const tcs = yield driver.executeScript(`const elements = ${jsElementList};
|
|
299
|
+
const tcs=[];
|
|
300
|
+
for (let el of elements) { tcs.push(getComputedStyle(el).${style}) }
|
|
301
|
+
return tcs;
|
|
302
|
+
`);
|
|
303
|
+
return tcs;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
exports.getComputedStyles = getComputedStyles;
|
|
307
|
+
/**
|
|
308
|
+
* Returns the inner size of the windows bounding client rect (the bounding box relative to the viewport)
|
|
309
|
+
* of an element (found by its is attribute) by means of a JavaScript call.
|
|
310
|
+
* The window size contains the scrollbars. I.e. it is a bit larger than {@link getViewPortSize}.
|
|
311
|
+
*/
|
|
312
|
+
function getInnerSizeOfWindow(driver) {
|
|
313
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
314
|
+
const w = yield driver.executeScript('return window.innerWidth');
|
|
315
|
+
const h = yield driver.executeScript('return window.innerHeight');
|
|
316
|
+
return { width: w, height: h };
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
exports.getInnerSizeOfWindow = getInnerSizeOfWindow;
|
|
320
|
+
/**
|
|
321
|
+
* Returns the viewport size, which is the inner window size but not with the scrollbars.
|
|
322
|
+
* I.e. the viewport size is a bit smaller than {@link getInnerSizeOfWindow} (if scrollbars are visible).
|
|
323
|
+
* The value is retrieved by means of JavaScript.
|
|
324
|
+
*/
|
|
325
|
+
function getViewPortSize(driver) {
|
|
326
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
327
|
+
const [clientWidthOfHTML, clientHeightOfHTML] = yield Promise.all([
|
|
328
|
+
driver.executeScript("return document.documentElement.clientWidth"),
|
|
329
|
+
driver.executeScript("return document.documentElement.clientHeight")
|
|
330
|
+
]);
|
|
331
|
+
return { width: clientWidthOfHTML, height: clientHeightOfHTML };
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
exports.getViewPortSize = getViewPortSize;
|
|
335
|
+
/**
|
|
336
|
+
* Returns true if the element identified by its id attribute is with the view port.
|
|
337
|
+
* That does not necessarily means that it is visible, since its display or visible attribute may
|
|
338
|
+
* hide the element.
|
|
339
|
+
*/
|
|
340
|
+
function isInViewPort(driver, id) {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
const innerSize = yield getInnerSizeOfWindow(driver);
|
|
343
|
+
const [x, y] = yield Promise.all([
|
|
344
|
+
driver.executeScript('return window.scrollX'),
|
|
345
|
+
driver.executeScript('return window.scrollY')
|
|
346
|
+
]);
|
|
347
|
+
const bounds = yield getBoundingClientRect(driver, id);
|
|
348
|
+
return bounds.x + bounds.width >= x && bounds.y + bounds.height >= y
|
|
349
|
+
&& bounds.x < x + innerSize.width && bounds.y < y + innerSize.height;
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
exports.isInViewPort = isInViewPort;
|
|
353
|
+
/**
|
|
354
|
+
* Sets the window so that the {@link getViewPortSize} matches the given width and height.
|
|
355
|
+
*/
|
|
356
|
+
function setBrowserWindowSize(driver, width, height) {
|
|
357
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
358
|
+
// const rect = await driver.manage().window().getRect();
|
|
359
|
+
yield waitForSetRect(driver, width, height);
|
|
360
|
+
// await driver.manage().window().setRect({ width: width, height: height });
|
|
361
|
+
// return waitFor(async () => {
|
|
362
|
+
// const rectAfter = await driver.manage().window().getRect();
|
|
363
|
+
// if (check && (rectAfter.width != width || rectAfter.height != height)) {
|
|
364
|
+
// throw new Error(`Cannot set window to size (${width}, ${height}). Size is probably too small or too large, got ${rectAfter.width}/${rectAfter.height}, was before ${rect.width}/${rect.height}.`);
|
|
365
|
+
// }
|
|
366
|
+
// });
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
exports.setBrowserWindowSize = setBrowserWindowSize;
|
|
370
|
+
function waitForSetRect(driver, width, height) {
|
|
371
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
372
|
+
const rectBefore = yield driver.manage().window().getRect();
|
|
373
|
+
yield driver.manage().window().setRect({ width: width, height: height });
|
|
374
|
+
return waitFor(() => __awaiter(this, void 0, void 0, function* () {
|
|
375
|
+
const rectAfter = yield driver.manage().window().getRect();
|
|
376
|
+
if (rectAfter.width != width || rectAfter.height != height) {
|
|
377
|
+
throw new Error(`Cannot set window to size (${width}, ${height}). Size is probably too small or too large, got ${rectAfter.width}/${rectAfter.height}, was before ${rectBefore.width}/${rectBefore.height}.`);
|
|
378
|
+
}
|
|
379
|
+
}));
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Sets the window so that the {@link getViewPortSize} matches the given width and height. Warning: This does not work reliably.
|
|
384
|
+
*/
|
|
385
|
+
function setViewPortSize(driver, width, height) {
|
|
386
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
387
|
+
const rect = yield driver.manage().window().getRect();
|
|
388
|
+
const innerBefore = yield getInnerSizeOfWindow(driver);
|
|
389
|
+
const deltaX = rect.width - innerBefore.width;
|
|
390
|
+
const deltaY = rect.height - innerBefore.height;
|
|
391
|
+
yield waitForSetRect(driver, width + deltaX, height + deltaY);
|
|
392
|
+
const [innerAfter, viewport] = yield Promise.all([getInnerSizeOfWindow(driver), getViewPortSize(driver)]);
|
|
393
|
+
// adjust scrollbars if necessary
|
|
394
|
+
const sbHeight = innerAfter.height - viewport.height;
|
|
395
|
+
const sbWidth = innerAfter.width - viewport.width;
|
|
396
|
+
yield waitForSetRect(driver, width + deltaX + sbWidth, height + deltaY + sbHeight);
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
exports.setViewPortSize = setViewPortSize;
|
|
400
|
+
function getInheritedBackgroundColorsByJS(driver, nodelist) {
|
|
401
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
402
|
+
const colors = yield driver.executeScript(`
|
|
403
|
+
const list = ${nodelist};
|
|
404
|
+
function getDefaultBackground() {
|
|
405
|
+
var div = document.createElement("div")
|
|
406
|
+
document.head.appendChild(div)
|
|
407
|
+
var bg = getComputedStyle(div).backgroundColor
|
|
408
|
+
document.head.removeChild(div)
|
|
409
|
+
return bg
|
|
410
|
+
}
|
|
411
|
+
const defaultStyle = getDefaultBackground()
|
|
412
|
+
function getInheritedBackgroundColor(el) {
|
|
413
|
+
var backgroundColor = getComputedStyle(el).backgroundColor
|
|
414
|
+
if (backgroundColor != defaultStyle) return backgroundColor
|
|
415
|
+
if (!el.parentElement) return defaultStyle
|
|
416
|
+
return getInheritedBackgroundColor(el.parentElement)
|
|
417
|
+
}
|
|
418
|
+
const colors = []
|
|
419
|
+
for (let e of list) {
|
|
420
|
+
colors.push(getInheritedBackgroundColor(e));
|
|
421
|
+
}
|
|
422
|
+
return colors;
|
|
423
|
+
`);
|
|
424
|
+
return colors;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
exports.getInheritedBackgroundColorsByJS = getInheritedBackgroundColorsByJS;
|
|
428
|
+
function getInheritedColorsByJS(driver, nodelist) {
|
|
429
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
430
|
+
const colors = yield driver.executeScript(`
|
|
431
|
+
const list = ${nodelist};
|
|
432
|
+
function getDefaultColor() {
|
|
433
|
+
var div = document.createElement("div")
|
|
434
|
+
document.head.appendChild(div)
|
|
435
|
+
var bg = getComputedStyle(div).color
|
|
436
|
+
document.head.removeChild(div)
|
|
437
|
+
return bg
|
|
438
|
+
}
|
|
439
|
+
const defaultStyle = getDefaultColor()
|
|
440
|
+
function getInheritedColor(el) {
|
|
441
|
+
var color = getComputedStyle(el).color
|
|
442
|
+
if (color != defaultStyle) return color
|
|
443
|
+
if (!el.parentElement) return defaultStyle
|
|
444
|
+
return getInheritedColor(el.parentElement)
|
|
445
|
+
}
|
|
446
|
+
const colors = []
|
|
447
|
+
for (let e of list) {
|
|
448
|
+
colors.push(getInheritedColor(e));
|
|
449
|
+
}
|
|
450
|
+
return colors;
|
|
451
|
+
`);
|
|
452
|
+
return colors;
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
exports.getInheritedColorsByJS = getInheritedColorsByJS;
|
|
456
|
+
function rgb2hex(rgba) {
|
|
457
|
+
return "#" +
|
|
458
|
+
rgba.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+\.{0,1}\d*))?\)$/)
|
|
459
|
+
.slice(1)
|
|
460
|
+
.map((n, i) => (i === 3
|
|
461
|
+
? Math.round(parseFloat(n) * 255)
|
|
462
|
+
: parseFloat(n)).toString(16).padStart(2, '0').replace('NaN', ''))
|
|
463
|
+
.join('');
|
|
464
|
+
}
|
|
465
|
+
function getAllTextNodes(driver) {
|
|
466
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
467
|
+
const res = yield driver.executeScript(`
|
|
468
|
+
|
|
469
|
+
const TRANSPARENT = "rgba(0, 0, 0, 0)";
|
|
470
|
+
const all = [];
|
|
471
|
+
const view = document.defaultView;
|
|
472
|
+
function collect(e) {
|
|
473
|
+
const styles = view.getComputedStyle(e);
|
|
474
|
+
const pStyles = view.getComputedStyle(e.parentElement);
|
|
475
|
+
const childNodes = e.childNodes;
|
|
476
|
+
for (let i=0; i<childNodes.length; i++) {
|
|
477
|
+
const node = childNodes.item(i);
|
|
478
|
+
if (node instanceof Element) {
|
|
479
|
+
collect(node);
|
|
480
|
+
} else if (node instanceof Text && node.textContent.trim().length>0) {
|
|
481
|
+
all.push({
|
|
482
|
+
text: node.textContent.trim(),
|
|
483
|
+
color: styles?.color!==TRANSPARENT?styles?.color:pStyles?.color,
|
|
484
|
+
background: styles?.backgroundColor!==TRANSPARENT?styles?.backgroundColor:pStyles?.backgroundColor,
|
|
485
|
+
line: styles?.textDecorationLine==='none'?pStyles?.textDecorationLine:styles?.textDecorationLine
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
collect(document.body);
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
return all;
|
|
494
|
+
`);
|
|
495
|
+
res.forEach(e => {
|
|
496
|
+
e.color = rgb2hex(e.color);
|
|
497
|
+
e.background = rgb2hex(e.background);
|
|
498
|
+
});
|
|
499
|
+
return res;
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
exports.getAllTextNodes = getAllTextNodes;
|
|
503
|
+
function getButtonsAndHRefs(driver) {
|
|
504
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
505
|
+
const elements = yield execScript(driver, "execScripts/dom.js", "getButtonsAndHRefs");
|
|
506
|
+
return elements;
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
exports.getButtonsAndHRefs = getButtonsAndHRefs;
|
|
510
|
+
//# sourceMappingURL=seUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seUtils.js","sourceRoot":"","sources":["../src/seUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,uCAAyB;AACzB,wDAA0C;AAC1C,gDAAwB;AACxB,2DAAwE;AAExE,SAAsB,UAAU,CAAI,MAAiB,EAAE,UAAkB,EAAE,GAAW;;QAClF,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC;QACnE,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACpD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,GAAG;iBACnC,GAAG;KACf,CAAC,CAAC;QACH,OAAO,GAAQ,CAAC;IACpB,CAAC;CAAA;AAPD,gCAOC;AAUD,SAAgB,cAAc,CAAC,MAAc;IACzC,OAAO,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,GAAG,CAAA;AAC9E,CAAC;AAFD,wCAEC;AAED,SAAgB,OAAO,CAAC,MAAgB;IACpC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;QACpB,MAAM,CAAC,IAAI,CAAC;YACR,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;YACtB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;;;;;KA2BtC,CAAwE,CAAC;QAE1E,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YACZ,CAAC,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC,CAAC,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;QAGH,OAAO,GAAG,CAAC;IACf,CAAC;CAAA;AArCD,0CAqCC;AAED,SAAsB,kBAAkB,CAAC,MAAiB;;QACtD,MAAM,QAAQ,GAAiB,MAAM,UAAU,CAAC,MAAM,EAClD,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;QAChD,OAAO,QAAQ,CAAC;IACpB,CAAC;CAAA;AAJD,gDAIC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sefiutils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Utilities (and Jest tests) for Selenium Webdriver Tests and some React tools as well",
|
|
5
5
|
"author": "Jens von Pilgrim <jens.vonpilgrim@bht-berlin.de>",
|
|
6
6
|
"license": "EPL-2.0",
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://gitlab.bht-berlin.de/nodepackages/sefiutils.git"
|
|
11
11
|
},
|
|
12
|
+
"files": [
|
|
13
|
+
"lib/"
|
|
14
|
+
],
|
|
12
15
|
"scripts": {
|
|
13
16
|
"build": "tsc && copyfiles --up 1 -e ./src/**/*.ts ./src/**/*.* lib",
|
|
14
17
|
"clean": "rimraf lib",
|
package/.gitlab-ci.yml
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# Template for node see:
|
|
2
|
-
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Nodejs.gitlab-ci.yml
|
|
3
|
-
# Coverage see:
|
|
4
|
-
# https://gist.github.com/rishitells/3c4536131819cff4eba2c8ab5bbb4570
|
|
5
|
-
|
|
6
|
-
image: node:latest
|
|
7
|
-
|
|
8
|
-
stages:
|
|
9
|
-
- test
|
|
10
|
-
|
|
11
|
-
javascript:
|
|
12
|
-
stage: test
|
|
13
|
-
script:
|
|
14
|
-
- npm install
|
|
15
|
-
- npm run build
|
|
16
|
-
- npm run test
|
|
17
|
-
artifacts:
|
|
18
|
-
reports:
|
|
19
|
-
junit:
|
|
20
|
-
- junit.xml
|
package/jest.config.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
preset: 'ts-jest',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
collectCoverage: true,
|
|
6
|
-
collectCoverageFrom: ['<rootDir>/src/**/*.{ts,js,jsm,tsx,jsx,tsm}'],
|
|
7
|
-
coverageReporters: ["text", "clover"],
|
|
8
|
-
reporters: [ "default", ["jest-junit", { suiteNameTemplate: "{filename}" }], ],
|
|
9
|
-
testPathIgnorePatterns: ["<rootDir>/lib/", "<rootDir>/node_modules/"],
|
|
10
|
-
coveragePathIgnorePatterns: ["<rootDir>/lib/", "<rootDir>/node_modules/", "<rootDir>/tests/"]
|
|
11
|
-
};
|
package/logo.graffle
DELETED
|
Binary file
|
package/logo.png
DELETED
|
Binary file
|
package/src/fiberUtils.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { WebDriver } from "selenium-webdriver";
|
|
2
|
-
import { execScript } from "./seUtils";
|
|
3
|
-
|
|
4
|
-
export type ComponentType = "html" | "function" | "root" | "null" | "other";
|
|
5
|
-
|
|
6
|
-
export interface ComponentNode {
|
|
7
|
-
// parent: ComponentNode | undefined;
|
|
8
|
-
name: string
|
|
9
|
-
kind: ComponentType;
|
|
10
|
-
props?: string[]
|
|
11
|
-
children: ComponentNode[]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function getReactComponentTree(driver: WebDriver): Promise<ComponentNode> {
|
|
15
|
-
const cmpTree: ComponentNode = await execScript(driver,
|
|
16
|
-
"execScripts/fiber.js", "uniDirFunctionComponentsTree");
|
|
17
|
-
return cmpTree;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export function dumpComponentTree(node: ComponentNode) {
|
|
22
|
-
let out = "";
|
|
23
|
-
dump(node)
|
|
24
|
-
return out;
|
|
25
|
-
|
|
26
|
-
function dump(node: ComponentNode, indent: string = "") {
|
|
27
|
-
out += `${indent}${node.name} (${node.kind})${(node.props && node.props.length > 0) ? ": " + node.props.join(", ") : ""}\n`;
|
|
28
|
-
for (const child of node.children) {
|
|
29
|
-
dump(child, indent + " ");
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function findInComponentTree(node: ComponentNode, predicate: (node: ComponentNode) => boolean): ComponentNode | undefined {
|
|
35
|
-
if (predicate(node)) {
|
|
36
|
-
return node;
|
|
37
|
-
}
|
|
38
|
-
for (const child of node.children) {
|
|
39
|
-
const found = findInComponentTree(child, predicate);
|
|
40
|
-
if (found) {
|
|
41
|
-
return found;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
export function findAllInComponentTree(node: ComponentNode, predicate: (node: ComponentNode) => boolean) {
|
|
47
|
-
|
|
48
|
-
const res: ComponentNode[] = [];
|
|
49
|
-
findAll(node);
|
|
50
|
-
return res;
|
|
51
|
-
|
|
52
|
-
function findAll(node: ComponentNode) {
|
|
53
|
-
if (predicate(node)) {
|
|
54
|
-
return res.push(node);
|
|
55
|
-
}
|
|
56
|
-
for (const child of node.children) {
|
|
57
|
-
findAll(child);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|