system-testing 1.0.17 → 1.0.18

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/system-test.js +43 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "system-testing",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "System testing with Selenium and browsers.",
5
5
  "keywords": [
6
6
  "system",
@@ -26,7 +26,7 @@
26
26
  "dependencies": {
27
27
  "awaitery": "^1.0.1",
28
28
  "diggerize": "^1.0.9",
29
- "htmlfy": "^0.8.1",
29
+ "htmlfy": "^1.0.0",
30
30
  "mime": "^4.0.7",
31
31
  "moment": "^2.30.1",
32
32
  "ws": "^8.18.3"
@@ -187,6 +187,49 @@ export default class SystemTest {
187
187
  return browserLogs
188
188
  }
189
189
 
190
+ /**
191
+ * Interacts with an element by calling a method on it with the given arguments.
192
+ * Retrying on ElementNotInteractableError.
193
+ *
194
+ * @param {import("selenium-webdriver").WebElement|string} elementOrIdentifier - The element or a CSS selector to find the element.
195
+ * @param {string} methodName - The method name to call on the element.
196
+ * @param {...any} args - Arguments to pass to the method.
197
+ *
198
+ * @returns {Promise<any>}
199
+ */
200
+ async interact(elementOrIdentifier, methodName, ...args) {
201
+ let element
202
+ let tries = 0
203
+
204
+ while (true) {
205
+ tries++
206
+
207
+ if (typeof elementOrIdentifier == "string") {
208
+ element = await this.find(elementOrIdentifier)
209
+ } else {
210
+ element = elementOrIdentifier
211
+ }
212
+
213
+ if (!element[methodName]) {
214
+ // throw new Error(`${element.constructor.name} has no method named: ${methodName}`)
215
+ }
216
+
217
+ try {
218
+ return await element[methodName](...args)
219
+ } catch (error) {
220
+ if (error.constructor.name === "ElementNotInteractableError") {
221
+ // Retry finding the element and interacting with it
222
+ if (tries >= 3) {
223
+ throw new Error(`${element.constructor.name} ${methodName} failed after ${tries} tries: ${error.message}`)
224
+ }
225
+ } else {
226
+ // Re-throw with un-corrupted stack trace
227
+ throw new Error(`${element.constructor.name} ${methodName} failed: ${error.message}`)
228
+ }
229
+ }
230
+ }
231
+ }
232
+
190
233
  /**
191
234
  * Expects no element to be found by CSS selector
192
235
  *