system-testing 1.0.19 → 1.0.21
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "system-testing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"description": "System testing with Selenium and browsers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"system",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"htmlfy": "^1.0.0",
|
|
30
30
|
"mime": "^4.0.7",
|
|
31
31
|
"moment": "^2.30.1",
|
|
32
|
+
"scoundrel-remote-eval": "^1.0.6",
|
|
32
33
|
"ws": "^8.18.3"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import Client from "scoundrel-remote-eval/src/client/index.js"
|
|
2
|
+
import ClientWebSocket from "scoundrel-remote-eval/src/client/connections/web-socket/index.js"
|
|
1
3
|
import {digg} from "diggerize"
|
|
2
4
|
import EventEmitter from "events"
|
|
3
5
|
|
|
@@ -20,6 +22,38 @@ export default class SystemTestBrowserHelper {
|
|
|
20
22
|
this.events = new EventEmitter()
|
|
21
23
|
|
|
22
24
|
shared.systemTestBrowserHelper = this
|
|
25
|
+
|
|
26
|
+
this.startScoundrel()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async startScoundrel() {
|
|
30
|
+
this.scoundrelWs = new WebSocket("http://localhost:8090")
|
|
31
|
+
this.scoundrelClientWebSocket = new ClientWebSocket(this.scoundrelWs)
|
|
32
|
+
|
|
33
|
+
await this.scoundrelClientWebSocket.waitForOpened()
|
|
34
|
+
|
|
35
|
+
this.scoundrelClient = new Client(this.scoundrelClientWebSocket)
|
|
36
|
+
this.events.emit("scoundrelStarted")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
waitForScoundrelStarted() {
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
if (this.scoundrelClient) {
|
|
42
|
+
resolve()
|
|
43
|
+
} else {
|
|
44
|
+
this.events.once("scoundrelStarted", () => {
|
|
45
|
+
resolve()
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getScoundrel() {
|
|
52
|
+
if (!this.scoundrelClient) {
|
|
53
|
+
throw new Error("Scoundrel client is not started yet")
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return this.scoundrelClient
|
|
23
57
|
}
|
|
24
58
|
|
|
25
59
|
connectOnError() {
|
|
@@ -83,8 +117,8 @@ export default class SystemTestBrowserHelper {
|
|
|
83
117
|
this.overrideConsoleLog()
|
|
84
118
|
}
|
|
85
119
|
|
|
86
|
-
getEnabled
|
|
87
|
-
getEvents
|
|
120
|
+
getEnabled() { return this._enabled }
|
|
121
|
+
getEvents() { return this.events }
|
|
88
122
|
|
|
89
123
|
fakeConsoleError = (...args) => {
|
|
90
124
|
this.communicator.sendCommand({type: "console.error", value: this.consoleLogMessage(args)})
|
|
@@ -63,6 +63,12 @@ export default class SystemTestCommunicator {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Sends a command and returns a promise that resolves with the response.
|
|
68
|
+
*
|
|
69
|
+
* @param {Object} data - The command data to send.
|
|
70
|
+
* @returns {Promise} A promise that resolves with the response data.
|
|
71
|
+
*/
|
|
66
72
|
sendCommand(data) {
|
|
67
73
|
return new Promise((resolve, error) => {
|
|
68
74
|
const id = this._sendQueueCount
|
package/src/system-test.js
CHANGED
|
@@ -5,9 +5,11 @@ import fs from "node:fs/promises"
|
|
|
5
5
|
import logging from "selenium-webdriver/lib/logging.js"
|
|
6
6
|
import moment from "moment"
|
|
7
7
|
import {prettify} from "htmlfy"
|
|
8
|
+
import Server from "scoundrel-remote-eval/src/server/index.js"
|
|
9
|
+
import ServerWebSocket from "scoundrel-remote-eval/src/server/connections/web-socket/index.js"
|
|
8
10
|
import SystemTestCommunicator from "./system-test-communicator.js"
|
|
9
11
|
import SystemTestHttpServer from "./system-test-http-server.js"
|
|
10
|
-
import {waitFor} from "awaitery"
|
|
12
|
+
import {wait, waitFor} from "awaitery"
|
|
11
13
|
import {WebSocketServer} from "ws"
|
|
12
14
|
|
|
13
15
|
class ElementNotFoundError extends Error { }
|
|
@@ -62,11 +64,24 @@ export default class SystemTest {
|
|
|
62
64
|
throw new Error(`Unknown arguments: ${restArgsKeys.join(", ")}`)
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
this.communicator = new SystemTestCommunicator({onCommand: this.onCommandReceived})
|
|
66
67
|
this._host = host
|
|
67
68
|
this._port = port
|
|
68
69
|
this._responses = {}
|
|
69
70
|
this._sendCount = 0
|
|
71
|
+
this.startScoundrel()
|
|
72
|
+
this.communicator = new SystemTestCommunicator({onCommand: this.onCommandReceived})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Starts Scoundrel server which the browser connects to for remote evaluation in the browser */
|
|
76
|
+
startScoundrel() {
|
|
77
|
+
this.wss = new WebSocketServer({port: 8090})
|
|
78
|
+
this.serverWebSocket = new ServerWebSocket(this.wss)
|
|
79
|
+
this.server = new Server(this.serverWebSocket)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
stopScoundrel() {
|
|
83
|
+
this.server?.close()
|
|
84
|
+
this.wss?.close()
|
|
70
85
|
}
|
|
71
86
|
|
|
72
87
|
/**
|
|
@@ -104,6 +119,10 @@ export default class SystemTest {
|
|
|
104
119
|
* @param {import("selenium-webdriver").WebElement} element
|
|
105
120
|
**/
|
|
106
121
|
async click(element) {
|
|
122
|
+
if (typeof element == "string") {
|
|
123
|
+
element = await this.find(element)
|
|
124
|
+
}
|
|
125
|
+
|
|
107
126
|
const actions = this.driver.actions({async: true})
|
|
108
127
|
|
|
109
128
|
await actions.move({origin: element}).click().perform()
|
|
@@ -187,6 +206,10 @@ export default class SystemTest {
|
|
|
187
206
|
return browserLogs
|
|
188
207
|
}
|
|
189
208
|
|
|
209
|
+
async getCurrentUrl() {
|
|
210
|
+
return await this.driver.getCurrentUrl()
|
|
211
|
+
}
|
|
212
|
+
|
|
190
213
|
/**
|
|
191
214
|
* Interacts with an element by calling a method on it with the given arguments.
|
|
192
215
|
* Retrying on ElementNotInteractableError.
|
|
@@ -221,6 +244,8 @@ export default class SystemTest {
|
|
|
221
244
|
// Retry finding the element and interacting with it
|
|
222
245
|
if (tries >= 3) {
|
|
223
246
|
throw new Error(`${element.constructor.name} ${methodName} failed after ${tries} tries - ${error.constructor.name}: ${error.message}`)
|
|
247
|
+
} else {
|
|
248
|
+
await wait(100)
|
|
224
249
|
}
|
|
225
250
|
} else {
|
|
226
251
|
// Re-throw with un-corrupted stack trace
|
|
@@ -484,6 +509,7 @@ export default class SystemTest {
|
|
|
484
509
|
* Stops the system test
|
|
485
510
|
*/
|
|
486
511
|
async stop() {
|
|
512
|
+
this.stopScoundrel()
|
|
487
513
|
this.systemTestHttpServer?.close()
|
|
488
514
|
this.wss?.close()
|
|
489
515
|
await this.driver.quit()
|
|
@@ -521,6 +547,7 @@ export default class SystemTest {
|
|
|
521
547
|
await fs.writeFile(logsPath, logsText.join("\n"))
|
|
522
548
|
await fs.writeFile(screenshotPath, imageContent, "base64")
|
|
523
549
|
|
|
550
|
+
console.log("Current URL:", await this.getCurrentUrl())
|
|
524
551
|
console.log("Logs:", logsPath)
|
|
525
552
|
console.log("Screenshot:", screenshotPath)
|
|
526
553
|
console.log("HTML:", htmlPath)
|