sefiutils 1.0.51 → 1.0.54
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/README.md +7 -8
- package/lib/fiberUtils.js +8 -9
- package/lib/fiberUtils.js.map +1 -1
- package/lib/globalSetup.d.ts.map +1 -1
- package/lib/globalSetup.js +26 -10
- package/lib/globalSetup.js.map +1 -1
- package/lib/globalTeardown.js +1 -1
- package/lib/globalTeardown.js.map +1 -1
- package/lib/localSetup.d.ts +1 -1
- package/lib/localSetup.d.ts.map +1 -1
- package/lib/localSetup.js +37 -20
- package/lib/localSetup.js.map +1 -1
- package/lib/localTeardown.js +1 -2
- package/lib/localTeardown.js.map +1 -1
- package/lib/log.js +2 -3
- package/lib/log.js.map +1 -1
- package/lib/seUtils.d.ts +4 -0
- package/lib/seUtils.d.ts.map +1 -1
- package/lib/seUtils.js +74 -60
- package/lib/seUtils.js.map +1 -1
- package/package.json +8 -8
- package/src/globalSetup.ts +33 -17
- package/src/localSetup.ts +35 -17
- package/src/seUtils.ts +19 -9
- package/lib/execScripts/dom.js +0 -15
package/src/localSetup.ts
CHANGED
|
@@ -2,14 +2,17 @@ import dotenv from "dotenv";
|
|
|
2
2
|
dotenv.config() // read ".env"
|
|
3
3
|
|
|
4
4
|
import { Builder, Capabilities, WebDriver } from "selenium-webdriver";
|
|
5
|
-
import { getRemoteAddressAndPort, setBrowserWindowSize, setViewPortSize } from "./seUtils";
|
|
6
5
|
import { debug, verbose } from "./log";
|
|
6
|
+
import { getRemoteAddressAndPort, setBrowserWindowSize } from "./seUtils";
|
|
7
|
+
import { Options } from "selenium-webdriver/chrome";
|
|
7
8
|
|
|
8
|
-
export const LOCAL_SETUP_TIMEOUT = 20000;
|
|
9
|
+
export const LOCAL_SETUP_TIMEOUT = process.env.VSCODE_INSPECTOR_OPTIONS ? 999999 : 20000;
|
|
10
|
+
// console.log("LOCAL_SETUP_TIMEOUT: ", LOCAL_SETUP_TIMEOUT);
|
|
11
|
+
// console.log("VSCODE_INSPECTOR_OPTIONS: ", process.env.VSCODE_INSPECTOR_OPTIONS);
|
|
9
12
|
|
|
10
13
|
export async function localSetup(page: string, width = 500, height = 500, acceptUntrustedCertificates = true): Promise<WebDriver> {
|
|
11
14
|
debug(() => `localSetup("${page}", ${width}, ${height}, ${acceptUntrustedCertificates}), getWebDriver ...`);
|
|
12
|
-
const driver = await getWebDriver(acceptUntrustedCertificates);
|
|
15
|
+
const driver = await getWebDriver(acceptUntrustedCertificates, width, height);
|
|
13
16
|
verbose(() => `Driver started, load page: ${page}`);
|
|
14
17
|
await driver.get(page);
|
|
15
18
|
debug(() => `Page loaded, set browser window size: ${width}x${height}`);
|
|
@@ -27,37 +30,42 @@ export async function localSetup(page: string, width = 500, height = 500, accept
|
|
|
27
30
|
* ```
|
|
28
31
|
* are to be called.
|
|
29
32
|
*/
|
|
30
|
-
async function getWebDriver(acceptUntrustedCertificates: boolean) {
|
|
33
|
+
async function getWebDriver(acceptUntrustedCertificates: boolean, width?: number, height?: number) {
|
|
31
34
|
const browser = (process.env.SEFI_BROWSER as "chrome" | "firefox" | "remote") || "remote";
|
|
32
35
|
|
|
33
36
|
debug(() => `Use browser: ${browser}`);
|
|
34
37
|
try {
|
|
35
38
|
if (browser === "chrome") {
|
|
36
|
-
return await setUpWebDriverChrome(acceptUntrustedCertificates);
|
|
39
|
+
return await setUpWebDriverChrome(acceptUntrustedCertificates, width, height);
|
|
37
40
|
} else if (browser === "firefox") {
|
|
38
|
-
return await setUpWebDriverFirefox(acceptUntrustedCertificates);
|
|
41
|
+
return await setUpWebDriverFirefox(acceptUntrustedCertificates, width, height);
|
|
39
42
|
} else if (browser === "remote") {
|
|
40
|
-
return await setUpWebDriverInDocker(acceptUntrustedCertificates);
|
|
43
|
+
return await setUpWebDriverInDocker(acceptUntrustedCertificates, width, height);
|
|
41
44
|
} else {
|
|
42
45
|
throw new Error(`Unknown browser: ${browser}`);
|
|
43
46
|
}
|
|
44
47
|
} catch (err) {
|
|
45
|
-
console.error(`Error setting up driver: ${err}`);
|
|
48
|
+
console.error(`Error setting up driver for ${browser}: ${err}`);
|
|
46
49
|
throw err;
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
|
|
51
|
-
async function setUpWebDriverInDocker(acceptUntrustedCertificates: boolean) {
|
|
52
|
-
debug("Dynamic import of selenium-webdriver/firefox");
|
|
53
|
-
debug("Remote browser, load firefox webdriver");
|
|
54
|
+
async function setUpWebDriverInDocker(acceptUntrustedCertificates: boolean, width?: number, height?: number) {
|
|
55
|
+
debug("Dynamic import of selenium-webdriver/firefox for remote browser");
|
|
54
56
|
const firefox = await import('selenium-webdriver/firefox');
|
|
55
57
|
|
|
56
|
-
const { address } = getRemoteAddressAndPort();
|
|
58
|
+
const { address, port } = getRemoteAddressAndPort();
|
|
57
59
|
const start = Date.now();
|
|
58
60
|
|
|
59
61
|
const options = new firefox.Options().addArguments("-headless");
|
|
60
62
|
options.setAcceptInsecureCerts(acceptUntrustedCertificates);
|
|
63
|
+
if (width && height) { // cf. https://github.com/SeleniumHQ/selenium/pull/6075
|
|
64
|
+
options.addArguments("--width=" + width);
|
|
65
|
+
options.addArguments("--height=" + height);
|
|
66
|
+
process.env.MOZ_HEADLESS_WIDTH = String(width);
|
|
67
|
+
process.env.MOZ_HEADLESS_HEIGHT = String(height);
|
|
68
|
+
}
|
|
61
69
|
|
|
62
70
|
debug(() => `Start headless firefox, remote server at ${address}`)
|
|
63
71
|
const driver = await new Builder()
|
|
@@ -71,8 +79,8 @@ async function setUpWebDriverInDocker(acceptUntrustedCertificates: boolean) {
|
|
|
71
79
|
return `Driver resolved and connected, required ${duration}s.`
|
|
72
80
|
});
|
|
73
81
|
return driver;
|
|
74
|
-
}
|
|
75
82
|
|
|
83
|
+
}
|
|
76
84
|
|
|
77
85
|
/**
|
|
78
86
|
* To be called in the beforeAll() function of a test suite.
|
|
@@ -83,14 +91,17 @@ async function setUpWebDriverInDocker(acceptUntrustedCertificates: boolean) {
|
|
|
83
91
|
* ```
|
|
84
92
|
* are to be called.
|
|
85
93
|
*/
|
|
86
|
-
async function setUpWebDriverChrome(acceptUntrustedCertificates: boolean) {
|
|
94
|
+
async function setUpWebDriverChrome(acceptUntrustedCertificates: boolean, width?: number, height?: number) {
|
|
87
95
|
debug("Dynamic import of chromedriver and selenium-webdriver/chrome");
|
|
88
96
|
//@ts-ignore
|
|
89
97
|
await import('chromedriver');
|
|
90
98
|
const chrome = await import('selenium-webdriver/chrome');
|
|
91
99
|
|
|
92
|
-
const options = new chrome.Options().addArguments("--headless=new");
|
|
100
|
+
const options: Options = (new chrome.Options().addArguments("--headless=new")) as Options;
|
|
93
101
|
options.setAcceptInsecureCerts(acceptUntrustedCertificates);
|
|
102
|
+
if (width && height) { // cf. https://www.geeksforgeeks.org/how-to-set-browser-width-and-height-in-selenium-webdriver/
|
|
103
|
+
options.addArguments("--window-size=" + width + "," + height);
|
|
104
|
+
}
|
|
94
105
|
|
|
95
106
|
debug(() => `Start headless chrome`)
|
|
96
107
|
const driver = await new Builder()
|
|
@@ -109,13 +120,20 @@ async function setUpWebDriverChrome(acceptUntrustedCertificates: boolean) {
|
|
|
109
120
|
* ```
|
|
110
121
|
* are to be called.
|
|
111
122
|
*/
|
|
112
|
-
async function setUpWebDriverFirefox(acceptUntrustedCertificates: boolean) {
|
|
123
|
+
async function setUpWebDriverFirefox(acceptUntrustedCertificates: boolean, width?: number, height?: number) {
|
|
113
124
|
debug("Dynamic import of geckodriver and selenium-webdriver/firefox");
|
|
114
125
|
//@ts-ignore
|
|
115
126
|
await import('geckodriver'); // installed geckodriver will cause remote configuration to fail in docker...
|
|
116
127
|
const firefox = await import('selenium-webdriver/firefox');
|
|
117
128
|
|
|
118
|
-
const options = new firefox.Options()
|
|
129
|
+
const options = new firefox.Options();
|
|
130
|
+
options.addArguments("-headless");
|
|
131
|
+
if (width && height) { // cf. https://github.com/SeleniumHQ/selenium/pull/6075
|
|
132
|
+
options.addArguments("--width=" + width);
|
|
133
|
+
options.addArguments("--height=" + height);
|
|
134
|
+
process.env.MOZ_HEADLESS_WIDTH = String(width);
|
|
135
|
+
process.env.MOZ_HEADLESS_HEIGHT = String(height);
|
|
136
|
+
}
|
|
119
137
|
options.setAcceptInsecureCerts(acceptUntrustedCertificates);
|
|
120
138
|
|
|
121
139
|
debug(() => `Start headless firefox`)
|
package/src/seUtils.ts
CHANGED
|
@@ -407,16 +407,8 @@ export async function isInViewPort(driver: WebDriver, id: string) {
|
|
|
407
407
|
* Sets the window so that the {@link getViewPortSize} matches the given width and height.
|
|
408
408
|
*/
|
|
409
409
|
export async function setBrowserWindowSize(driver: WebDriver, width: number, height: number): Promise<void> {
|
|
410
|
-
// const rect = await driver.manage().window().getRect();
|
|
411
410
|
await waitForSetRect(driver, width, height);
|
|
412
|
-
|
|
413
|
-
// return waitFor(async () => {
|
|
414
|
-
// const rectAfter = await driver.manage().window().getRect();
|
|
415
|
-
|
|
416
|
-
// if (check && (rectAfter.width != width || rectAfter.height != height)) {
|
|
417
|
-
// 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}.`);
|
|
418
|
-
// }
|
|
419
|
-
// });
|
|
411
|
+
|
|
420
412
|
}
|
|
421
413
|
|
|
422
414
|
async function waitForSetRect(driver: WebDriver, width: number, height: number): Promise<void> {
|
|
@@ -900,3 +892,21 @@ export function editDistance(a: string, b: string, maxDistance: number) {
|
|
|
900
892
|
|
|
901
893
|
return d[a.length][b.length];
|
|
902
894
|
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Returns true if the two web elements are equal, i.e. have the same id or same tag, location, and size.
|
|
898
|
+
*/
|
|
899
|
+
export async function equalWebElements(a: WebElement|null|undefined, b: WebElement|null|undefined) {
|
|
900
|
+
if (a===b) return true;
|
|
901
|
+
if (!a || !b) return false;
|
|
902
|
+
const aId = await a.getId();
|
|
903
|
+
const bId = await b.getId();
|
|
904
|
+
if (aId) return aId === bId;
|
|
905
|
+
const aLocation = await a.getLocation();
|
|
906
|
+
const bLocation = await b.getLocation();
|
|
907
|
+
const aSize = await a.getSize();
|
|
908
|
+
const bSize = await b.getSize();
|
|
909
|
+
const aTag = await a.getTagName();
|
|
910
|
+
const bTag = await b.getTagName();
|
|
911
|
+
return aTag===bTag && aLocation.x === bLocation.x && aLocation.y === bLocation.y && aSize.width === bSize.width && aSize.height === bSize.height;
|
|
912
|
+
}
|
package/lib/execScripts/dom.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
function getButtonsAndHRefs() {
|
|
2
|
-
const clickable = [];
|
|
3
|
-
const elements = document.getElementsByTagName("*");
|
|
4
|
-
for (let i = 0; i < elements.length; i++) {
|
|
5
|
-
const e = elements[i];
|
|
6
|
-
if ( ((e.onclick || e.onClick) && !Object.keys(e).find(key => key.startsWith("__reactContainer$")))
|
|
7
|
-
|| (e.tagName==='A' && e.href)
|
|
8
|
-
|| (e.tagName==='BUTTON' && e.type!=='hidden')
|
|
9
|
-
|| (e.tagName==='INPUT' && ["button", "submit"].includes(e.type?.toLowerCase()))
|
|
10
|
-
) {
|
|
11
|
-
clickable.push(e);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return clickable;
|
|
15
|
-
}
|