sefiutils 1.0.0 → 1.0.2

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 CHANGED
@@ -9,6 +9,8 @@ It also adds some utilities for React Fiber in order to make it easier to test R
9
9
  however it has no dependency to React itself.
10
10
  Additionally setup and teardown functions for Jest are provided.
11
11
 
12
+ If you want to test your web app, you probably want to use other frameworks. This package is intended for use in teaching, in particular for grading student's projects. Thus it provides some utilities which are usually not available in other frameworks (as they are usually not required at all).
13
+
12
14
  ## Install
13
15
 
14
16
  Install with npm:
@@ -22,26 +24,22 @@ npm install --save-dev sefiutils
22
24
  In your jest.config.js file add the following lines:
23
25
 
24
26
  ```
25
- globalSetup: "<rootDir>/check/tests/swd/globalSetup.ts",
26
- globalTeardown: "<rootDir>/check/tests/swd/globalTeardown.ts",
27
+ globalSetup: "<rootDir>/node_modules/sefiutils/lib/globalSetup.js",
28
+ globalTeardown: "<rootDir>/node_modules/sefiutils/lib/globalTeardown.js"
27
29
  ```
28
30
 
29
31
  Depending on the environment variable `BROWSER` either a browser is started or a
30
32
  selenium server is started. The following values are supported:
31
33
 
32
- - `remote`: A selenium server is started. This requires the following additional packages to be installed in your project:
33
- - selenium-server-standalone-jar -- which needs Java as well!
34
- - `chrome`: A Chrome browser is started. This requires the following additional packages to be installed in your project:
35
- - chromedriver
36
- - selenium-webdriver
37
- - `firefox`: A Firefox browser is started. This requires the following additional packages to be installed in your project:
38
- - selenium-webdriver
34
+ - `remote`: A selenium server is started. This requires Java as well!
35
+ - `chrome`: A Chrome browser is started.
36
+ - `firefox`: A Firefox browser is started.
39
37
 
40
38
  In your tests, add the following lines (or similar) to setup and teardown the driver and load the page:
41
39
 
42
40
  ```
43
- import { localSetup, LOCAL_SETUP_TIMEOUT } from "seutils/lib/localSetup";
44
- import { localTeardown } from "seutils/lib/localTeardown";
41
+ import { LOCAL_SETUP_TIMEOUT, localSetup} from "sefiutils/lib/localSetup"
42
+ import { localTeardown} from "sefiutils/lib/localTeardown"
45
43
 
46
44
  const page = "http://localhost:3000/" // or any other page
47
45
  let driver: WebDriver;
@@ -61,6 +59,24 @@ afterAll(async () => {
61
59
 
62
60
  ## Utils for accessing information from the DOM via Selenium Webdriver injected JavaScript
63
61
 
62
+ Most utility functions are provided via module 'seUtils', e.g.
63
+
64
+ - `waitFor` -- similar to React Testing Library's waitFor
65
+ - `saveScreenshot` -- saves a screenshot to a file
66
+ - `getElementById`, `getElementByClass`, `getElementByTag` -- returns the (first) element with the given id, class or tag
67
+ - `getElementContainingText` -- returns the (first) element containing the given text
68
+ - `getBoundingClientRect`, `getBoundingClientRects` -- returns the bounding rectangle(s) of the given element(s)
69
+ - `getComputedStyle` -- returns the computed style of the given element
70
+ - `getInheritedBackgroundColorsByJS`, `getInheritedColorsByJS` -- returns the inherited (background) color of the given element
71
+ - `getInnerSizeOfWindow`, `getViewPortSize` -- returns the inner size of the window or the viewport size
72
+ - `setBrowserWindowSize` -- sets the size of the browser window (this is directly supported by newer Selenium webdriver versions and only required for older versions)
73
+ - `waitForSetRect` -- waits until the given element has the given bounding rectangle
74
+ - `setViewPortSize` -- sets the size of the viewport
75
+ - `getButtonsAndHRefs` -- returns all buttons and anchors with hrefs of the given element
76
+
77
+ Most of these functions are scripts executed in the browser via Selenium Webdriver's `executeScript` function.
78
+
79
+
64
80
 
65
81
 
66
82
  ## Utils for React Fiber
@@ -68,7 +84,8 @@ afterAll(async () => {
68
84
  If you want to test the React components hierarchy, you can use the following functions:
69
85
 
70
86
  ```
71
- import { getReactComponentTree, findInComponentTree, equalsIgnoreCase } from "seutils/fiberUtils";
87
+ import { ComponentNode, dumpComponentTree, findAllInComponentTree,
88
+ findInComponentTree, getReactComponentTree} from "sefiutils/lib/fiberUtils"
72
89
 
73
90
  await waitFor(async () => {
74
91
  cmpTree = await getReactComponentTree(driver);
@@ -83,6 +100,23 @@ For debugging, you can also dump the tree;
83
100
  console.log("Component Tree:\n" + dumpComponentTree(cmpTree));
84
101
  ```
85
102
 
103
+ ## Docker Hints
104
+
105
+ If you want to run your tests in a docker container on macos with M1 or M2 processor, you can use the following Dockerfile:
106
+
107
+ ```
108
+ FROM seleniarm/standalone-firefox:latest
109
+
110
+ # install Node 18 and NPM
111
+ RUN sudo apt update
112
+ RUN sudo apt install nodejs npm -y
113
+
114
+ CMD ["/bin/bash"]
115
+ ```
116
+
117
+ The default user ist "seluser", i.e. home folder is found in "/home/seluser".
118
+
119
+
86
120
  ## License
87
121
 
88
122
  This program and the accompanying materials are made available under the terms of the Eclipse Public License v. 2.0 which is available at https://www.eclipse.org/legal/epl-2.0.
@@ -0,0 +1,13 @@
1
+ import { WebDriver } from "selenium-webdriver";
2
+ export type ComponentType = "html" | "function" | "root" | "null" | "other";
3
+ export interface ComponentNode {
4
+ name: string;
5
+ kind: ComponentType;
6
+ props?: string[];
7
+ children: ComponentNode[];
8
+ }
9
+ export declare function getReactComponentTree(driver: WebDriver): Promise<ComponentNode>;
10
+ export declare function dumpComponentTree(node: ComponentNode): string;
11
+ export declare function findInComponentTree(node: ComponentNode, predicate: (node: ComponentNode) => boolean): ComponentNode | undefined;
12
+ export declare function findAllInComponentTree(node: ComponentNode, predicate: (node: ComponentNode) => boolean): ComponentNode[];
13
+ //# sourceMappingURL=fiberUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fiberUtils.d.ts","sourceRoot":"","sources":["../src/fiberUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE5E,MAAM,WAAW,aAAa;IAE1B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,QAAQ,EAAE,aAAa,EAAE,CAAA;CAC5B;AAED,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,CAIrF;AAGD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,aAAa,UAWpD;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,GAAG,aAAa,GAAG,SAAS,CAW/H;AACD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,mBActG"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.findAllInComponentTree = exports.findInComponentTree = exports.dumpComponentTree = exports.getReactComponentTree = void 0;
13
+ const seUtils_1 = require("./seUtils");
14
+ function getReactComponentTree(driver) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const cmpTree = yield (0, seUtils_1.execScript)(driver, "execScripts/fiber.js", "uniDirFunctionComponentsTree");
17
+ return cmpTree;
18
+ });
19
+ }
20
+ exports.getReactComponentTree = getReactComponentTree;
21
+ function dumpComponentTree(node) {
22
+ let out = "";
23
+ dump(node);
24
+ return out;
25
+ function dump(node, indent = "") {
26
+ out += `${indent}${node.name} (${node.kind})${(node.props && node.props.length > 0) ? ": " + node.props.join(", ") : ""}\n`;
27
+ for (const child of node.children) {
28
+ dump(child, indent + " ");
29
+ }
30
+ }
31
+ }
32
+ exports.dumpComponentTree = dumpComponentTree;
33
+ function findInComponentTree(node, predicate) {
34
+ if (predicate(node)) {
35
+ return node;
36
+ }
37
+ for (const child of node.children) {
38
+ const found = findInComponentTree(child, predicate);
39
+ if (found) {
40
+ return found;
41
+ }
42
+ }
43
+ return undefined;
44
+ }
45
+ exports.findInComponentTree = findInComponentTree;
46
+ function findAllInComponentTree(node, predicate) {
47
+ const res = [];
48
+ findAll(node);
49
+ return res;
50
+ function findAll(node) {
51
+ if (predicate(node)) {
52
+ return res.push(node);
53
+ }
54
+ for (const child of node.children) {
55
+ findAll(child);
56
+ }
57
+ }
58
+ }
59
+ exports.findAllInComponentTree = findAllInComponentTree;
60
+ //# sourceMappingURL=fiberUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fiberUtils.js","sourceRoot":"","sources":["../src/fiberUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,uCAAuC;AAYvC,SAAsB,qBAAqB,CAAC,MAAiB;;QACzD,MAAM,OAAO,GAAkB,MAAM,IAAA,oBAAU,EAAC,MAAM,EAClD,sBAAsB,EAAE,8BAA8B,CAAC,CAAC;QAC5D,OAAO,OAAO,CAAC;IACnB,CAAC;CAAA;AAJD,sDAIC;AAGD,SAAgB,iBAAiB,CAAC,IAAmB;IACjD,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,CAAC,IAAI,CAAC,CAAA;IACV,OAAO,GAAG,CAAC;IAEX,SAAS,IAAI,CAAC,IAAmB,EAAE,SAAiB,EAAE;QAClD,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;QAC5H,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE;YAC/B,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;SAC9B;IACL,CAAC;AACL,CAAC;AAXD,8CAWC;AAED,SAAgB,mBAAmB,CAAC,IAAmB,EAAE,SAA2C;IAChG,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE;QACjB,OAAO,IAAI,CAAC;KACf;IACD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE;QAC/B,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACpD,IAAI,KAAK,EAAE;YACP,OAAO,KAAK,CAAC;SAChB;KACJ;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAXD,kDAWC;AACD,SAAgB,sBAAsB,CAAC,IAAmB,EAAE,SAA2C;IAEnG,MAAM,GAAG,GAAoB,EAAE,CAAC;IAChC,OAAO,CAAC,IAAI,CAAC,CAAC;IACd,OAAO,GAAG,CAAC;IAEX,SAAS,OAAO,CAAC,IAAmB;QAChC,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE;YACjB,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACzB;QACD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE;YAC/B,OAAO,CAAC,KAAK,CAAC,CAAC;SAClB;IACL,CAAC;AACL,CAAC;AAdD,wDAcC"}
@@ -0,0 +1,22 @@
1
+ declare global {
2
+ var server: any;
3
+ }
4
+ /**
5
+ * This function is called by Jest once before all tests are executed.
6
+ * In order to get called, it must be referenced in the jest configuration file:
7
+ * ```
8
+ * "globalSetup": "<rootDir>/tests/globalSetup.ts"
9
+ * ```
10
+ *
11
+ * **Important Note**: "Any global variables that are defined through globalSetup can only be
12
+ * read in globalTeardown. You cannot retrieve globals defined here in your test suites."
13
+ * [Jest Documentation](https://jestjs.io/docs/configuration#globalsetup-string)
14
+ *
15
+ * We only start the selenium server here if we are running in remote mode, which is the default.
16
+ * The mode can configured by setting the environment variable BROWSER to "chrome", "firefox" or "remote".
17
+ *
18
+ * Do not forget a global teardown function, which is called after all tests are executed,
19
+ * cf. globalTeardown.ts
20
+ */
21
+ export default function setGlobalObjects(): Promise<void>;
22
+ //# sourceMappingURL=globalSetup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalSetup.d.ts","sourceRoot":"","sources":["../src/globalSetup.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACX,IAAI,MAAM,EAAE,GAAG,CAAC;CAEnB;AACD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAA8B,gBAAgB,kBAY7C"}
@@ -0,0 +1,88 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ /**
36
+ * This function is called by Jest once before all tests are executed.
37
+ * In order to get called, it must be referenced in the jest configuration file:
38
+ * ```
39
+ * "globalSetup": "<rootDir>/tests/globalSetup.ts"
40
+ * ```
41
+ *
42
+ * **Important Note**: "Any global variables that are defined through globalSetup can only be
43
+ * read in globalTeardown. You cannot retrieve globals defined here in your test suites."
44
+ * [Jest Documentation](https://jestjs.io/docs/configuration#globalsetup-string)
45
+ *
46
+ * We only start the selenium server here if we are running in remote mode, which is the default.
47
+ * The mode can configured by setting the environment variable BROWSER to "chrome", "firefox" or "remote".
48
+ *
49
+ * Do not forget a global teardown function, which is called after all tests are executed,
50
+ * cf. globalTeardown.ts
51
+ */
52
+ function setGlobalObjects() {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const browser = process.env.BROWSER || "remote";
55
+ // console.log(`Using browser: ${browser}`);
56
+ try {
57
+ if (browser === "remote") {
58
+ yield setUpSeleniumServer();
59
+ }
60
+ }
61
+ catch (err) {
62
+ console.error(`Error setting up server: ${err}`);
63
+ throw err;
64
+ }
65
+ });
66
+ }
67
+ exports.default = setGlobalObjects;
68
+ function setUpSeleniumServer() {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ const remote = yield Promise.resolve().then(() => __importStar(require("selenium-webdriver/remote")));
71
+ //@ts-ignore
72
+ const jar = yield Promise.resolve().then(() => __importStar(require('selenium-server-standalone-jar')));
73
+ if (globalThis.server) {
74
+ yield globalThis.server.kill();
75
+ console.log(`Server killed before starting again`);
76
+ }
77
+ // console.log(`Load selenium server from ${jar.path}`);
78
+ const s = new remote.SeleniumServer(jar.path, {
79
+ port: 4444,
80
+ env: Object.assign(Object.assign({}, process.env), { "SE_NODE_MAX_SESSIONS": "4", "SE_NODE_OVERRIDE_MAX_SESSIONS": "true" })
81
+ });
82
+ const address = yield s.start(3000);
83
+ globalThis.server = s;
84
+ // const address = await globalThis.server.address()
85
+ // console.log(`Selenium server started at address: ${address}`);
86
+ });
87
+ }
88
+ //# sourceMappingURL=globalSetup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalSetup.js","sourceRoot":"","sources":["../src/globalSetup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;;;;;;;;;;;;;;;GAgBG;AACH,SAA8B,gBAAgB;;QAC1C,MAAM,OAAO,GAAI,OAAO,CAAC,GAAG,CAAC,OAA2C,IAAI,QAAQ,CAAC;QAErF,4CAA4C;QAC5C,IAAI;YACA,IAAI,OAAO,KAAK,QAAQ,EAAE;gBACtB,MAAM,mBAAmB,EAAE,CAAC;aAC/B;SACJ;QAAC,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,4BAA4B,GAAG,EAAE,CAAC,CAAC;YACjD,MAAM,GAAG,CAAC;SACb;IACL,CAAC;CAAA;AAZD,mCAYC;AAGD,SAAe,mBAAmB;;QAE9B,MAAM,MAAM,GAAG,wDAAa,2BAA2B,GAAC,CAAC;QACzD,YAAY;QACZ,MAAM,GAAG,GAAG,wDAAa,gCAAgC,GAAC,CAAC;QAE3D,IAAI,UAAU,CAAC,MAAM,EAAE;YACnB,MAAM,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAC/B,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;SACtD;QAED,wDAAwD;QACxD,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE;YAC1C,IAAI,EAAE,IAAI;YACV,GAAG,kCACI,OAAO,CAAC,GAAG,KACd,sBAAsB,EAAE,GAAG,EAC3B,+BAA+B,EAAE,MAAM,GAE1C;SACJ,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;QACtB,oDAAoD;QACpD,iEAAiE;IACrE,CAAC;CAAA"}
@@ -1,21 +1,14 @@
1
-
2
1
  /**
3
- * This function is called by Jest once after tests have been executed.
2
+ * This function is called by Jest once after tests have been executed.
4
3
  * In order to get called, it must be referenced in the jest configuration file:
5
4
  * ```
6
5
  * "globalTeardown": "<rootDir>/tests/globalTeardown.ts"
7
6
  * ```
8
- * **Important Note**: "Any global variables that are defined through globalSetup can only be
7
+ * **Important Note**: "Any global variables that are defined through globalSetup can only be
9
8
  * read in globalTeardown. You cannot retrieve globals defined here in your test suites."
10
9
  * [Jest Documentation](https://jestjs.io/docs/configuration#globalsetup-string)
11
- *
10
+ *
12
11
  * Here, we stop the remote selenium server if it was started in globalSetup.ts.
13
12
  */
14
- export default async function killServer() {
15
- if (globalThis.server) {
16
- await server.kill();
17
- console.log(`Server killed`);
18
-
19
- }
20
- globalThis.server = undefined;
21
- }
13
+ export default function killServer(): Promise<void>;
14
+ //# sourceMappingURL=globalTeardown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalTeardown.d.ts","sourceRoot":"","sources":["../src/globalTeardown.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;GAWG;AACH,wBAA8B,UAAU,kBAOvC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ /**
13
+ * This function is called by Jest once after tests have been executed.
14
+ * In order to get called, it must be referenced in the jest configuration file:
15
+ * ```
16
+ * "globalTeardown": "<rootDir>/tests/globalTeardown.ts"
17
+ * ```
18
+ * **Important Note**: "Any global variables that are defined through globalSetup can only be
19
+ * read in globalTeardown. You cannot retrieve globals defined here in your test suites."
20
+ * [Jest Documentation](https://jestjs.io/docs/configuration#globalsetup-string)
21
+ *
22
+ * Here, we stop the remote selenium server if it was started in globalSetup.ts.
23
+ */
24
+ function killServer() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ if (globalThis.server) {
27
+ yield server.kill();
28
+ console.log(`Server killed`);
29
+ }
30
+ globalThis.server = undefined;
31
+ });
32
+ }
33
+ exports.default = killServer;
34
+ //# sourceMappingURL=globalTeardown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalTeardown.js","sourceRoot":"","sources":["../src/globalTeardown.ts"],"names":[],"mappings":";;;;;;;;;;;AACA;;;;;;;;;;;GAWG;AACH,SAA8B,UAAU;;QACpC,IAAI,UAAU,CAAC,MAAM,EAAE;YACnB,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;SAEhC;QACD,UAAU,CAAC,MAAM,GAAG,SAAS,CAAC;IAClC,CAAC;CAAA;AAPD,6BAOC"}
@@ -0,0 +1,4 @@
1
+ import { WebDriver } from "selenium-webdriver";
2
+ export declare const LOCAL_SETUP_TIMEOUT = 20000;
3
+ export declare function localSetup(page: string, width?: number, height?: number): Promise<WebDriver>;
4
+ //# sourceMappingURL=localSetup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localSetup.d.ts","sourceRoot":"","sources":["../src/localSetup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGtE,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAM,EAAE,MAAM,SAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAM5F"}
@@ -0,0 +1,139 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.localSetup = exports.LOCAL_SETUP_TIMEOUT = void 0;
36
+ const selenium_webdriver_1 = require("selenium-webdriver");
37
+ const seUtils_1 = require("./seUtils");
38
+ exports.LOCAL_SETUP_TIMEOUT = 20000;
39
+ function localSetup(page, width = 500, height = 500) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const driver = yield getWebDriver();
42
+ console.log(`Load page: ${page}`);
43
+ yield driver.get(page);
44
+ yield (0, seUtils_1.setBrowserWindowSize)(driver, width, height);
45
+ return driver;
46
+ });
47
+ }
48
+ exports.localSetup = localSetup;
49
+ /**
50
+ * To be configured in jest setup file via globalSetup as it needs to be run before any tests in all files.
51
+ * Additionally,
52
+ * ```
53
+ * await driver.get(page);
54
+ * await setViewPortSize(500, 500);
55
+ * ```
56
+ * are to be called.
57
+ */
58
+ function getWebDriver() {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const browser = process.env.BROWSER || "remote";
61
+ // console.log(`Using browser: ${browser}`);
62
+ try {
63
+ if (browser === "chrome") {
64
+ return yield setUpWebDriverChrome();
65
+ }
66
+ else if (browser === "firefox") {
67
+ return yield setUpWebDriverFirefox();
68
+ }
69
+ else if (browser === "remote") {
70
+ return yield setUpWebDriverInDocker();
71
+ }
72
+ else {
73
+ throw new Error(`Unknown browser: ${browser}`);
74
+ }
75
+ }
76
+ catch (err) {
77
+ console.error(`Error setting up driver: ${err}`);
78
+ throw err;
79
+ }
80
+ });
81
+ }
82
+ function setUpWebDriverInDocker() {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ const firefox = yield Promise.resolve().then(() => __importStar(require('selenium-webdriver/firefox')));
85
+ let address = "http://localhost:4444/wd/hub";
86
+ let start = Date.now();
87
+ const driver = yield new selenium_webdriver_1.Builder()
88
+ .usingServer(address)
89
+ .withCapabilities(selenium_webdriver_1.Capabilities.firefox())
90
+ .setFirefoxOptions(new firefox.Options().headless())
91
+ .build();
92
+ let duration = (Date.now() - start) / 1000;
93
+ // console.log(`Driver resolved and connected to ${address}, required ${duration}s.`);
94
+ return driver;
95
+ });
96
+ }
97
+ /**
98
+ * To be called in the beforeAll() function of a test suite.
99
+ * Additionally,
100
+ * ```
101
+ * await driver.get(page);
102
+ * await setViewPortSize(500, 500);
103
+ * ```
104
+ * are to be called.
105
+ */
106
+ function setUpWebDriverChrome() {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ //@ts-ignore
109
+ yield Promise.resolve().then(() => __importStar(require('chromedriver')));
110
+ const chrome = yield Promise.resolve().then(() => __importStar(require('selenium-webdriver/chrome')));
111
+ const driver = yield new selenium_webdriver_1.Builder()
112
+ .forBrowser('chrome')
113
+ .setChromeOptions(new chrome.Options().headless())
114
+ .build();
115
+ return driver;
116
+ });
117
+ }
118
+ /**
119
+ * To be called in the beforeAll() function of a test suite.
120
+ * Additionally,
121
+ * ```
122
+ * await driver.get(page);
123
+ * await setViewPortSize(500, 500);
124
+ * ```
125
+ * are to be called.
126
+ */
127
+ function setUpWebDriverFirefox() {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ //@ts-ignore
130
+ yield Promise.resolve().then(() => __importStar(require('geckodriver'))); // installed geckodriver will cause remote configuration to fail in docker...
131
+ const firefox = yield Promise.resolve().then(() => __importStar(require('selenium-webdriver/firefox')));
132
+ const driver = yield new selenium_webdriver_1.Builder()
133
+ .forBrowser('firefox')
134
+ .setFirefoxOptions(new firefox.Options().headless())
135
+ .build();
136
+ return driver;
137
+ });
138
+ }
139
+ //# sourceMappingURL=localSetup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localSetup.js","sourceRoot":"","sources":["../src/localSetup.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,6 @@
1
+ import { WebDriver } from "selenium-webdriver";
2
+ /**
3
+ * To be called in the afterAll() function of a test suite.
4
+ */
5
+ export declare function localTeardown(driver: WebDriver): Promise<void>;
6
+ //# sourceMappingURL=localTeardown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localTeardown.d.ts","sourceRoot":"","sources":["../src/localTeardown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;GAEG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,SAAS,iBAQpD"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.localTeardown = void 0;
13
+ /**
14
+ * To be called in the afterAll() function of a test suite.
15
+ */
16
+ function localTeardown(driver) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ if (driver) {
19
+ yield driver.quit();
20
+ // console.log(`Driver quit`);
21
+ }
22
+ else {
23
+ throw new Error("Driver not started yet");
24
+ }
25
+ });
26
+ }
27
+ exports.localTeardown = localTeardown;
28
+ //# sourceMappingURL=localTeardown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localTeardown.js","sourceRoot":"","sources":["../src/localTeardown.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA;;GAEG;AACH,SAAsB,aAAa,CAAC,MAAiB;;QACjD,IAAI,MAAM,EAAE;YACR,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YACpB,8BAA8B;SACjC;aAAM;YACH,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;SAE7C;IACL,CAAC;CAAA;AARD,sCAQC"}