wdio-ag-grid 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/CHANGELOG.md +21 -0
- package/README.md +84 -0
- package/docs/images/webdriverio-logo.png +0 -0
- package/package.json +41 -0
- package/src/index.d.ts +33 -0
- package/src/index.js +766 -0
- package/tests/ag-grid-animation-wait.v35.spec.js +65 -0
- package/tests/ag-grid-data.v33.spec.js +17 -0
- package/tests/ag-grid-data.v34.spec.js +17 -0
- package/tests/ag-grid-data.v35.spec.js +17 -0
- package/tests/ag-grid-elements.v33.spec.js +17 -0
- package/tests/ag-grid-elements.v34.spec.js +17 -0
- package/tests/ag-grid-elements.v35.spec.js +17 -0
- package/tests/server.mjs +48 -0
- package/tests/shared/compat.js +209 -0
- package/tests/shared/fixtures.js +109 -0
- package/tests/shared/run-ag-grid-data-suite.js +600 -0
- package/tests/shared/run-ag-grid-elements-suite.js +58 -0
- package/tests/shared/runtime.js +110 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import net from "node:net";
|
|
5
|
+
import { remote } from "webdriverio";
|
|
6
|
+
import * as chromedriver from "chromedriver";
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
const serverScriptPath = path.resolve(__dirname, "../server.mjs");
|
|
11
|
+
const chromedriverPath = chromedriver.path ?? chromedriver.default?.path;
|
|
12
|
+
|
|
13
|
+
function waitForPort(port, host = "127.0.0.1", timeoutMs = 15000) {
|
|
14
|
+
const start = Date.now();
|
|
15
|
+
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const attempt = () => {
|
|
18
|
+
const socket = net.createConnection({ host, port });
|
|
19
|
+
|
|
20
|
+
socket.once("connect", () => {
|
|
21
|
+
socket.end();
|
|
22
|
+
resolve();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
socket.once("error", () => {
|
|
26
|
+
socket.destroy();
|
|
27
|
+
|
|
28
|
+
if (Date.now() - start > timeoutMs) {
|
|
29
|
+
reject(new Error(`Timed out waiting for ${host}:${port}`));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setTimeout(attempt, 100);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
attempt();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getFreePort() {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const server = net.createServer();
|
|
44
|
+
server.listen(0, "127.0.0.1", () => {
|
|
45
|
+
const address = server.address();
|
|
46
|
+
server.close(() => {
|
|
47
|
+
if (typeof address === "object" && address?.port) {
|
|
48
|
+
resolve(address.port);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
reject(new Error("Unable to allocate a free port."));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
server.on("error", reject);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function startProcess(command, args, port) {
|
|
60
|
+
const child = spawn(command, args, { stdio: "inherit" });
|
|
61
|
+
await waitForPort(port);
|
|
62
|
+
return child;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function createWdioTestContext(options = {}) {
|
|
66
|
+
const serverPort = options.serverPort ?? await getFreePort();
|
|
67
|
+
const chromedriverPort = options.chromedriverPort ?? await getFreePort();
|
|
68
|
+
|
|
69
|
+
const serverProcess = await startProcess(
|
|
70
|
+
process.execPath,
|
|
71
|
+
[serverScriptPath, `--port=${serverPort}`],
|
|
72
|
+
serverPort
|
|
73
|
+
);
|
|
74
|
+
const driverProcess = await startProcess(
|
|
75
|
+
chromedriverPath,
|
|
76
|
+
[`--port=${chromedriverPort}`],
|
|
77
|
+
chromedriverPort
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const browser = await remote({
|
|
81
|
+
logLevel: "error",
|
|
82
|
+
hostname: "127.0.0.1",
|
|
83
|
+
port: chromedriverPort,
|
|
84
|
+
path: "/",
|
|
85
|
+
capabilities: {
|
|
86
|
+
browserName: "chrome",
|
|
87
|
+
"goog:chromeOptions": {
|
|
88
|
+
args: [
|
|
89
|
+
"--headless=new",
|
|
90
|
+
"--disable-gpu",
|
|
91
|
+
"--no-sandbox",
|
|
92
|
+
"--disable-dev-shm-usage",
|
|
93
|
+
"--window-size=1440,1200",
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
browser,
|
|
101
|
+
baseUrl: `http://127.0.0.1:${serverPort}`,
|
|
102
|
+
async close() {
|
|
103
|
+
if (browser.sessionId) {
|
|
104
|
+
await browser.deleteSession();
|
|
105
|
+
}
|
|
106
|
+
driverProcess.kill("SIGTERM");
|
|
107
|
+
serverProcess.kill("SIGTERM");
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|