testcafe 2.3.1-rc.2 → 2.4.0-rc.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/LICENSE +1 -1
  3. package/README.md +40 -46
  4. package/lib/api/test-controller/execution-context.js +4 -2
  5. package/lib/browser/connection/gateway.js +43 -1
  6. package/lib/browser/connection/index.js +24 -10
  7. package/lib/browser/connection/service-routes.js +3 -1
  8. package/lib/browser/provider/built-in/dedicated/chrome/index.js +19 -5
  9. package/lib/browser/provider/index.js +4 -1
  10. package/lib/client/automation/deps/hammerhead.js +24 -0
  11. package/lib/client/automation/deps/testcafe-core.js +24 -0
  12. package/lib/client/automation/index.js +251 -54
  13. package/lib/client/automation/index.min.js +1 -1
  14. package/lib/client/automation/playback/press/get-key-info.js +44 -0
  15. package/lib/client/automation/playback/press/utils.js +142 -0
  16. package/lib/client/automation/utils/get-key-code.js +15 -0
  17. package/lib/client/automation/utils/get-key-identifier.js +14 -0
  18. package/lib/client/automation/utils/is-letter.js +7 -0
  19. package/lib/client/automation/utils/key-identifier-maps.js +93 -0
  20. package/lib/client/browser/idle-page/index.js +7 -2
  21. package/lib/client/core/index.js +46 -3
  22. package/lib/client/core/index.min.js +1 -1
  23. package/lib/client/driver/index.js +45 -17
  24. package/lib/client/driver/index.min.js +1 -1
  25. package/lib/client/test-run/index.js.mustache +34 -30
  26. package/lib/client/ui/index.js +3230 -48
  27. package/lib/client/ui/index.min.js +1 -1
  28. package/lib/client/ui/sprite.svg +15 -0
  29. package/lib/client/ui/styles.css +183 -41
  30. package/lib/live/test-runner.js +4 -2
  31. package/lib/proxyless/api-base.js +3 -2
  32. package/lib/proxyless/client/event-descriptor.js +67 -0
  33. package/lib/proxyless/client/input.js +36 -0
  34. package/lib/proxyless/client/key-press/utils.js +31 -0
  35. package/lib/proxyless/client/types.js +1 -1
  36. package/lib/proxyless/client/utils.js +32 -2
  37. package/lib/proxyless/cookie-provider.js +31 -3
  38. package/lib/proxyless/errors.js +20 -0
  39. package/lib/proxyless/index.js +2 -10
  40. package/lib/proxyless/request-pipeline/index.js +32 -3
  41. package/lib/proxyless/resource-injector.js +5 -4
  42. package/lib/proxyless/types.js +3 -2
  43. package/lib/proxyless/utils/cdp.js +4 -3
  44. package/lib/reporter/index.js +2 -1
  45. package/lib/runner/bootstrapper.js +8 -1
  46. package/lib/runner/index.js +57 -44
  47. package/lib/shared/utils/is-file-protocol.js +2 -2
  48. package/lib/test-run/commands/actions.js +2 -2
  49. package/lib/test-run/cookies/base.js +4 -1
  50. package/lib/test-run/cookies/provider.js +9 -2
  51. package/lib/test-run/execute-js-expression/index.js +4 -2
  52. package/lib/test-run/index.js +17 -12
  53. package/lib/test-run/request/create-request-options.js +23 -12
  54. package/lib/test-run/request/send.js +2 -3
  55. package/lib/utils/check-is-vm.js +58 -0
  56. package/package.json +9 -6
  57. package/lib/proxyless/client/event-simulator.js +0 -40
@@ -7,20 +7,35 @@ window['%hammerhead%'].utils.removeInjectedScript();
7
7
  function initTestCafeUI(window) {
8
8
  var document = window.document;
9
9
 
10
- (function (hammerhead, testCafeCore, Promise$3) {
11
- var hammerhead__default = 'default' in hammerhead ? hammerhead['default'] : hammerhead;
10
+ (function (hammerhead$1, testCafeCore, Promise$3) {
11
+ var hammerhead$1__default = 'default' in hammerhead$1 ? hammerhead$1['default'] : hammerhead$1;
12
12
  var testCafeCore__default = 'default' in testCafeCore ? testCafeCore['default'] : testCafeCore;
13
13
  Promise$3 = Promise$3 && Object.prototype.hasOwnProperty.call(Promise$3, 'default') ? Promise$3['default'] : Promise$3;
14
14
 
15
+ var PANELS_CONTAINER_CLASS = 'panels-container';
15
16
  var uiRoot = {
16
17
  uiRoot: null,
18
+ container: null,
17
19
  element: function () {
18
20
  if (!this.uiRoot) {
19
21
  this.uiRoot = document.createElement('div');
20
- hammerhead.shadowUI.getRoot().appendChild(this.uiRoot);
22
+ hammerhead$1.shadowUI.getRoot().appendChild(this.uiRoot);
21
23
  }
22
24
  return this.uiRoot;
23
25
  },
26
+ panelsContainer: function () {
27
+ if (!this.container) {
28
+ this.container = document.createElement('div');
29
+ hammerhead$1.shadowUI.addClass(this.container, PANELS_CONTAINER_CLASS);
30
+ this.element().appendChild(this.container);
31
+ }
32
+ return this.container;
33
+ },
34
+ insertFirstChildToPanelsContainer: function (element) {
35
+ var panelsContainer = this.panelsContainer();
36
+ var firstChild = hammerhead$1.nativeMethods.nodeFirstChildGetter.call(panelsContainer);
37
+ panelsContainer.insertBefore(element, firstChild);
38
+ },
24
39
  hide: function () {
25
40
  if (!this.uiRoot)
26
41
  return;
@@ -32,19 +47,19 @@ window['%hammerhead%'].utils.removeInjectedScript();
32
47
  this.uiRoot.style.visibility = '';
33
48
  },
34
49
  remove: function () {
35
- var shadowRoot = hammerhead.shadowUI.getRoot();
36
- var parent = hammerhead.nativeMethods.nodeParentNodeGetter.call(shadowRoot);
50
+ var shadowRoot = hammerhead$1.shadowUI.getRoot();
51
+ var parent = hammerhead$1.nativeMethods.nodeParentNodeGetter.call(shadowRoot);
37
52
  parent.removeChild(shadowRoot);
38
53
  },
39
54
  };
40
55
 
41
56
  //NOTE: we can't manipulate (open/close option list) with a native select element during test running, so we
42
- var shadowUI = hammerhead__default.shadowUI;
43
- var browserUtils = hammerhead__default.utils.browser;
44
- var featureDetection = hammerhead__default.utils.featureDetection;
45
- var nativeMethods = hammerhead__default.nativeMethods;
46
- var eventSimulator = hammerhead__default.eventSandbox.eventSimulator;
47
- var listeners = hammerhead__default.eventSandbox.listeners;
57
+ var shadowUI = hammerhead$1__default.shadowUI;
58
+ var browserUtils = hammerhead$1__default.utils.browser;
59
+ var featureDetection = hammerhead$1__default.utils.featureDetection;
60
+ var nativeMethods = hammerhead$1__default.nativeMethods;
61
+ var eventSimulator = hammerhead$1__default.eventSandbox.eventSimulator;
62
+ var listeners = hammerhead$1__default.eventSandbox.listeners;
48
63
  var positionUtils = testCafeCore__default.positionUtils;
49
64
  var domUtils = testCafeCore__default.domUtils;
50
65
  var styleUtils = testCafeCore__default.styleUtils;
@@ -228,15 +243,15 @@ window['%hammerhead%'].utils.removeInjectedScript();
228
243
  var root = uiRoot.element();
229
244
  backgroundDiv = document.createElement('div');
230
245
  root.appendChild(backgroundDiv);
231
- hammerhead.shadowUI.addClass(backgroundDiv, BACKGROUND_CLASS);
246
+ hammerhead$1.shadowUI.addClass(backgroundDiv, BACKGROUND_CLASS);
232
247
  loadingTextDiv = document.createElement('div');
233
- hammerhead.nativeMethods.nodeTextContentSetter.call(loadingTextDiv, LOADING_TEXT);
248
+ hammerhead$1.nativeMethods.nodeTextContentSetter.call(loadingTextDiv, LOADING_TEXT);
234
249
  root.appendChild(loadingTextDiv);
235
- hammerhead.shadowUI.addClass(loadingTextDiv, LOADING_TEXT_CLASS);
250
+ hammerhead$1.shadowUI.addClass(loadingTextDiv, LOADING_TEXT_CLASS);
236
251
  loadingIconDiv = document.createElement('div');
237
252
  testCafeCore.styleUtils.set(loadingIconDiv, 'visibility', 'hidden');
238
253
  root.appendChild(loadingIconDiv);
239
- hammerhead.shadowUI.addClass(loadingIconDiv, LOADING_ICON_CLASS);
254
+ hammerhead$1.shadowUI.addClass(loadingIconDiv, LOADING_ICON_CLASS);
240
255
  }
241
256
  //Behavior
242
257
  function adjustLoadingTextPos() {
@@ -291,7 +306,7 @@ window['%hammerhead%'].utils.removeInjectedScript();
291
306
  if (document.body)
292
307
  initAndShow();
293
308
  else
294
- hammerhead.nativeMethods.setTimeout.call(window, tryShowBeforeReady, 0);
309
+ hammerhead$1.nativeMethods.setTimeout.call(window, tryShowBeforeReady, 0);
295
310
  }
296
311
  };
297
312
  tryShowBeforeReady();
@@ -331,7 +346,7 @@ window['%hammerhead%'].utils.removeInjectedScript();
331
346
  hideLoadingIcon: hideLoadingIcon
332
347
  });
333
348
 
334
- var shadowUI$1 = hammerhead__default.shadowUI;
349
+ var shadowUI$1 = hammerhead$1__default.shadowUI;
335
350
  var styleUtils$1 = testCafeCore__default.styleUtils;
336
351
  var CONTAINER_CLASS = 'progress-bar';
337
352
  var VALUE_CLASS = 'value';
@@ -358,8 +373,8 @@ window['%hammerhead%'].utils.removeInjectedScript();
358
373
  return ProgressBar;
359
374
  }());
360
375
 
361
- var shadowUI$2 = hammerhead__default.shadowUI;
362
- var nativeMethods$1 = hammerhead__default.nativeMethods;
376
+ var shadowUI$2 = hammerhead$1__default.shadowUI;
377
+ var nativeMethods$1 = hammerhead$1__default.nativeMethods;
363
378
  var eventUtils$1 = testCafeCore__default.eventUtils;
364
379
  var styleUtils$2 = testCafeCore__default.styleUtils;
365
380
  var PANEL_CLASS = 'progress-panel';
@@ -523,10 +538,98 @@ window['%hammerhead%'].utils.removeInjectedScript();
523
538
  extendStatics(d, b);
524
539
  function __() { this.constructor = d; }
525
540
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
541
+ }
542
+ function __awaiter(thisArg, _arguments, P, generator) {
543
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
544
+ return new (P || (P = Promise$3))(function (resolve, reject) {
545
+ function fulfilled(value) { try {
546
+ step(generator.next(value));
547
+ }
548
+ catch (e) {
549
+ reject(e);
550
+ } }
551
+ function rejected(value) { try {
552
+ step(generator["throw"](value));
553
+ }
554
+ catch (e) {
555
+ reject(e);
556
+ } }
557
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
558
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
559
+ });
560
+ }
561
+ function __generator(thisArg, body) {
562
+ var _ = { label: 0, sent: function () { if (t[0] & 1)
563
+ throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
564
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
565
+ function verb(n) { return function (v) { return step([n, v]); }; }
566
+ function step(op) {
567
+ if (f)
568
+ throw new TypeError("Generator is already executing.");
569
+ while (g && (g = 0, op[0] && (_ = 0)), _)
570
+ try {
571
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
572
+ return t;
573
+ if (y = 0, t)
574
+ op = [op[0] & 2, t.value];
575
+ switch (op[0]) {
576
+ case 0:
577
+ case 1:
578
+ t = op;
579
+ break;
580
+ case 4:
581
+ _.label++;
582
+ return { value: op[1], done: false };
583
+ case 5:
584
+ _.label++;
585
+ y = op[1];
586
+ op = [0];
587
+ continue;
588
+ case 7:
589
+ op = _.ops.pop();
590
+ _.trys.pop();
591
+ continue;
592
+ default:
593
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
594
+ _ = 0;
595
+ continue;
596
+ }
597
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
598
+ _.label = op[1];
599
+ break;
600
+ }
601
+ if (op[0] === 6 && _.label < t[1]) {
602
+ _.label = t[1];
603
+ t = op;
604
+ break;
605
+ }
606
+ if (t && _.label < t[2]) {
607
+ _.label = t[2];
608
+ _.ops.push(op);
609
+ break;
610
+ }
611
+ if (t[2])
612
+ _.ops.pop();
613
+ _.trys.pop();
614
+ continue;
615
+ }
616
+ op = body.call(thisArg, _);
617
+ }
618
+ catch (e) {
619
+ op = [6, e];
620
+ y = 0;
621
+ }
622
+ finally {
623
+ f = t = 0;
624
+ }
625
+ if (op[0] & 5)
626
+ throw op[1];
627
+ return { value: op[0] ? op[1] : void 0, done: true };
628
+ }
526
629
  }
527
630
 
528
- var shadowUI$3 = hammerhead__default.shadowUI;
529
- var nativeMethods$2 = hammerhead__default.nativeMethods;
631
+ var shadowUI$3 = hammerhead$1__default.shadowUI;
632
+ var nativeMethods$2 = hammerhead$1__default.nativeMethods;
530
633
  var styleUtils$3 = testCafeCore__default.styleUtils;
531
634
  var DETERMINATE_STYLE_CLASS = 'determinate';
532
635
  var ANIMATION_UPDATE_INTERVAL$1 = 10;
@@ -574,8 +677,8 @@ window['%hammerhead%'].utils.removeInjectedScript();
574
677
  return Math.round(equationSlope * x + equationYIntercept);
575
678
  }
576
679
 
577
- var shadowUI$4 = hammerhead__default.shadowUI;
578
- var nativeMethods$3 = hammerhead__default.nativeMethods;
680
+ var shadowUI$4 = hammerhead$1__default.shadowUI;
681
+ var nativeMethods$3 = hammerhead$1__default.nativeMethods;
579
682
  var styleUtils$4 = testCafeCore__default.styleUtils;
580
683
  var FIRST_VALUE_ANIMATION_OPTIONS = {
581
684
  time: 2800,
@@ -706,7 +809,7 @@ window['%hammerhead%'].utils.removeInjectedScript();
706
809
  return IndeterminateIndicator;
707
810
  }());
708
811
 
709
- var shadowUI$5 = hammerhead__default.shadowUI;
812
+ var shadowUI$5 = hammerhead$1__default.shadowUI;
710
813
  var styleUtils$5 = testCafeCore__default.styleUtils;
711
814
  var PROGRESS_BAR_CLASS = 'progress-bar';
712
815
  var CONTAINER_CLASS$1 = 'value-container';
@@ -761,13 +864,13 @@ window['%hammerhead%'].utils.removeInjectedScript();
761
864
  return window.top !== window;
762
865
  }
763
866
 
764
- var Promise = hammerhead__default.Promise;
765
- var shadowUI$6 = hammerhead__default.shadowUI;
766
- var nativeMethods$4 = hammerhead__default.nativeMethods;
767
- var messageSandbox = hammerhead__default.eventSandbox.message;
768
- var browserUtils$1 = hammerhead__default.utils.browser;
769
- var featureDetection$1 = hammerhead__default.utils.featureDetection;
770
- var listeners$1 = hammerhead__default.eventSandbox.listeners;
867
+ var Promise = hammerhead$1__default.Promise;
868
+ var shadowUI$6 = hammerhead$1__default.shadowUI;
869
+ var nativeMethods$4 = hammerhead$1__default.nativeMethods;
870
+ var messageSandbox = hammerhead$1__default.eventSandbox.message;
871
+ var browserUtils$1 = hammerhead$1__default.utils.browser;
872
+ var featureDetection$1 = hammerhead$1__default.utils.featureDetection;
873
+ var listeners$1 = hammerhead$1__default.eventSandbox.listeners;
771
874
  var styleUtils$6 = testCafeCore__default.styleUtils;
772
875
  var eventUtils$2 = testCafeCore__default.eventUtils;
773
876
  var domUtils$1 = testCafeCore__default.domUtils;
@@ -930,7 +1033,7 @@ window['%hammerhead%'].utils.removeInjectedScript();
930
1033
  this.progressBar = new ProgressBar$1(this.infoContainer);
931
1034
  this.progressBar.indeterminateIndicator.start();
932
1035
  this.progressBar.show();
933
- uiRoot.element().appendChild(this.statusBar);
1036
+ uiRoot.panelsContainer().appendChild(this.statusBar);
934
1037
  this._bindHandlers();
935
1038
  this.state.created = true;
936
1039
  };
@@ -1167,7 +1270,7 @@ window['%hammerhead%'].utils.removeInjectedScript();
1167
1270
  }(serviceUtils.EventEmitter));
1168
1271
 
1169
1272
  var sendRequestToFrame = testCafeCore__default.sendRequestToFrame;
1170
- var messageSandbox$1 = hammerhead__default.eventSandbox.message;
1273
+ var messageSandbox$1 = hammerhead$1__default.eventSandbox.message;
1171
1274
  var IframeStatusBar = /** @class */ (function (_super) {
1172
1275
  __extends(IframeStatusBar, _super);
1173
1276
  function IframeStatusBar() {
@@ -1202,11 +1305,11 @@ window['%hammerhead%'].utils.removeInjectedScript();
1202
1305
  buttonUpResponse: 'ui|cursor|buttonup|response',
1203
1306
  };
1204
1307
 
1205
- var Promise$1 = hammerhead__default.Promise;
1206
- var shadowUI$7 = hammerhead__default.shadowUI;
1207
- var browserUtils$2 = hammerhead__default.utils.browser;
1208
- var featureDetection$2 = hammerhead__default.utils.featureDetection;
1209
- var messageSandbox$2 = hammerhead__default.eventSandbox.message;
1308
+ var Promise$1 = hammerhead$1__default.Promise;
1309
+ var shadowUI$7 = hammerhead$1__default.shadowUI;
1310
+ var browserUtils$2 = hammerhead$1__default.utils.browser;
1311
+ var featureDetection$2 = hammerhead$1__default.utils.featureDetection;
1312
+ var messageSandbox$2 = hammerhead$1__default.eventSandbox.message;
1210
1313
  var styleUtils$7 = testCafeCore__default.styleUtils;
1211
1314
  var positionUtils$1 = testCafeCore__default.positionUtils;
1212
1315
  var CURSOR_CLASS = 'cursor';
@@ -1311,7 +1414,7 @@ window['%hammerhead%'].utils.removeInjectedScript();
1311
1414
  },
1312
1415
  };
1313
1416
 
1314
- var browserUtils$3 = hammerhead__default.utils.browser;
1417
+ var browserUtils$3 = hammerhead$1__default.utils.browser;
1315
1418
  // HACK: In most browsers, the iframe's getElementFromPoint function ignores elements
1316
1419
  // from the parent frame. But in IE it doesn't, and our cursor overlaps the target
1317
1420
  // element. So, we move the cursor to a position one pixel farther to avoid this.
@@ -1352,12 +1455,12 @@ window['%hammerhead%'].utils.removeInjectedScript();
1352
1455
  screenshotMark: null,
1353
1456
  _createMark: function () {
1354
1457
  this.screenshotMark = document.createElement('img');
1355
- hammerhead.shadowUI.addClass(this.screenshotMark, 'screenshot-mark');
1458
+ hammerhead$1.shadowUI.addClass(this.screenshotMark, 'screenshot-mark');
1356
1459
  this.screenshotMark.style.right = MARK_RIGHT_MARGIN / window.devicePixelRatio + 'px';
1357
1460
  this.screenshotMark.style.width = MARK_LENGTH / window.devicePixelRatio + 'px';
1358
1461
  this.screenshotMark.style.height = MARK_HEIGHT / window.devicePixelRatio + 'px';
1359
1462
  this.hide();
1360
- hammerhead.shadowUI.getRoot().appendChild(this.screenshotMark);
1463
+ hammerhead$1.shadowUI.getRoot().appendChild(this.screenshotMark);
1361
1464
  },
1362
1465
  hide: function () {
1363
1466
  if (!this.screenshotMark)
@@ -1367,13 +1470,3091 @@ window['%hammerhead%'].utils.removeInjectedScript();
1367
1470
  show: function (url) {
1368
1471
  if (!this.screenshotMark)
1369
1472
  this._createMark();
1370
- hammerhead.nativeMethods.imageSrcSetter.call(this.screenshotMark, url);
1473
+ hammerhead$1.nativeMethods.imageSrcSetter.call(this.screenshotMark, url);
1371
1474
  this.screenshotMark.style.visibility = '';
1372
1475
  },
1373
1476
  };
1374
1477
 
1375
- var Promise$2 = hammerhead__default.Promise;
1376
- var messageSandbox$3 = hammerhead__default.eventSandbox.message;
1478
+ var shadowUI$8 = hammerhead$1__default.shadowUI;
1479
+ var nativeMethods$5 = hammerhead$1__default.nativeMethods;
1480
+ function createElementFromDescriptor(descriptor) {
1481
+ // eslint-disable-next-line no-restricted-properties
1482
+ var _a = descriptor.tag, tag = _a === void 0 ? 'div' : _a, className = descriptor.class, src = descriptor.src, text = descriptor.text, type = descriptor.type, value = descriptor.value;
1483
+ var element = document.createElement(tag);
1484
+ if (type)
1485
+ nativeMethods$5.setAttribute.call(element, 'type', type);
1486
+ if (value)
1487
+ nativeMethods$5.inputValueSetter.call(element, value);
1488
+ if (src)
1489
+ nativeMethods$5.setAttribute.call(element, 'src', src);
1490
+ if (className)
1491
+ shadowUI$8.addClass(element, className);
1492
+ if (text)
1493
+ nativeMethods$5.nodeTextContentSetter.call(element, text);
1494
+ return element;
1495
+ }
1496
+
1497
+ /* eslint-disable no-restricted-properties */
1498
+ var styleUtils$8 = testCafeCore__default.styleUtils;
1499
+ function setStyles(element, styles) {
1500
+ for (var key in styles)
1501
+ styleUtils$8.set(element, key, styles[key]);
1502
+ }
1503
+
1504
+ var pickButton = {
1505
+ tag: 'input',
1506
+ type: 'button',
1507
+ value: 'Pick',
1508
+ class: 'pick-button',
1509
+ };
1510
+ var selectorInput = {
1511
+ tag: 'input',
1512
+ type: 'text',
1513
+ class: 'selector-input',
1514
+ };
1515
+ var matchIndicator = {
1516
+ class: 'match-indicator',
1517
+ text: 'No Matching Elements',
1518
+ };
1519
+ var expandSelectorsList = {
1520
+ class: 'expand-selector-list',
1521
+ };
1522
+ var selectorInputContainer = {
1523
+ class: 'selector-input-container',
1524
+ };
1525
+ var copyButton = {
1526
+ tag: 'input',
1527
+ type: 'button',
1528
+ value: 'Copy',
1529
+ };
1530
+ var selectorsList = {
1531
+ class: 'selectors-list',
1532
+ };
1533
+ var panel = {
1534
+ class: 'selector-inspector-panel',
1535
+ };
1536
+ var elementFrame = {
1537
+ class: 'element-frame',
1538
+ };
1539
+ var tooltip = {
1540
+ class: 'tooltip',
1541
+ };
1542
+ var arrow = {
1543
+ class: 'arrow',
1544
+ };
1545
+ var auxiliaryCopyInput = {
1546
+ tag: 'input',
1547
+ type: 'text',
1548
+ class: 'auxiliary-input',
1549
+ };
1550
+
1551
+ /* eslint-disable no-restricted-properties */
1552
+ function addToUiRoot(element) {
1553
+ if (!element.parentElement) {
1554
+ var panelsContainer = uiRoot.panelsContainer();
1555
+ uiRoot.element().insertBefore(element, panelsContainer);
1556
+ }
1557
+ }
1558
+ function removeFromUiRoot(element) {
1559
+ if (element.parentElement)
1560
+ uiRoot.element().removeChild(element);
1561
+ }
1562
+ function getChildren() {
1563
+ return uiRoot.element().children;
1564
+ }
1565
+
1566
+ var TESTCAFE_CORE = window['%testCafeCore%'];
1567
+
1568
+ function findIndex(array, predicate) {
1569
+ var length = array.length;
1570
+ for (var i = 0; i < length; i++) {
1571
+ if (predicate(array[i]))
1572
+ return i;
1573
+ }
1574
+ return -1;
1575
+ }
1576
+
1577
+ var SelectorRule = /** @class */ (function () {
1578
+ function SelectorRule(type, editable) {
1579
+ if (editable === void 0) { editable = false; }
1580
+ this.type = type;
1581
+ this.editable = editable;
1582
+ this.disabled = void 0;
1583
+ }
1584
+ return SelectorRule;
1585
+ }());
1586
+
1587
+ var CustomSelectorRule = /** @class */ (function (_super) {
1588
+ __extends(CustomSelectorRule, _super);
1589
+ function CustomSelectorRule(type) {
1590
+ return _super.call(this, type.toLowerCase(), true) || this;
1591
+ }
1592
+ return CustomSelectorRule;
1593
+ }(SelectorRule));
1594
+
1595
+ /* eslint-disable sort-keys */
1596
+ // TODO: users should be able to call a custom-attr 'text' for example
1597
+ // and the name 'class-dom' should not be considered as default compound rule but as custom attr.
1598
+ var RULE_TYPE = {
1599
+ edited: '$edited$',
1600
+ byTagName: '$tagName$',
1601
+ byId: 'id',
1602
+ byText: '$text$',
1603
+ byClassAttr: 'class',
1604
+ byAttr: '$attr$',
1605
+ byTagTree: '$dom$',
1606
+ };
1607
+
1608
+ var DEFAULT_SELECTOR_RULES = [
1609
+ new SelectorRule(RULE_TYPE.byTagName),
1610
+ new SelectorRule(RULE_TYPE.byId),
1611
+ new SelectorRule(RULE_TYPE.byText),
1612
+ new SelectorRule(RULE_TYPE.byClassAttr),
1613
+ new SelectorRule(RULE_TYPE.byAttr),
1614
+ new SelectorRule(RULE_TYPE.byTagTree),
1615
+ ];
1616
+
1617
+ var UNSWITCHABLE_RULE_TYPE = RULE_TYPE.byTagTree;
1618
+
1619
+ var RULES = /*#__PURE__*/Object.freeze({
1620
+ __proto__: null,
1621
+ CustomSelectorRule: CustomSelectorRule,
1622
+ DEFAULT_SELECTOR_RULES: DEFAULT_SELECTOR_RULES,
1623
+ RULE_TYPE: RULE_TYPE,
1624
+ SelectorRule: SelectorRule,
1625
+ UNSWITCHABLE_RULE_TYPE: UNSWITCHABLE_RULE_TYPE
1626
+ });
1627
+
1628
+ var FilterOption = /** @class */ (function () {
1629
+ function FilterOption(type, value) {
1630
+ this.type = type;
1631
+ this.filter = value;
1632
+ }
1633
+ FilterOption.prototype.concat = function (option) {
1634
+ if (option.type === this.type)
1635
+ return new FilterOption(this.type, this.filter.concat(' ', option.filter));
1636
+ return null;
1637
+ };
1638
+ return FilterOption;
1639
+ }());
1640
+
1641
+ var byText = 'text';
1642
+ var byIndex = 'index';
1643
+ var byTag = 'tag';
1644
+ var byAttr = 'attr';
1645
+
1646
+ var domUtils$2 = TESTCAFE_CORE.domUtils, arrayUtils$2 = TESTCAFE_CORE.arrayUtils;
1647
+ function getNthFilterOptions(el, parent) {
1648
+ var index = domUtils$2.getElementIndexInParent(parent, el);
1649
+ var tagFilterOption = new FilterOption(byTag, domUtils$2.getTagName(el));
1650
+ if (index === 0)
1651
+ return [tagFilterOption];
1652
+ var indexFilterOption = new FilterOption(byIndex, index);
1653
+ return [tagFilterOption, indexFilterOption];
1654
+ }
1655
+ function getParentsUntil(el, boundElement) {
1656
+ var parent = el.parentElement;
1657
+ var parents = [];
1658
+ while (parent) {
1659
+ if (parent === boundElement)
1660
+ return parents;
1661
+ parents.push(parent);
1662
+ parent = parent.parentElement;
1663
+ }
1664
+ return parents;
1665
+ }
1666
+ function getTagTreeFilterOptions(element, parents) {
1667
+ var filterOptions = arrayUtils$2.reverse(getNthFilterOptions(element, parents[0]));
1668
+ var parentLength = parents.length;
1669
+ for (var i = 0; i < parentLength - 1; i++) {
1670
+ var currentParent = parents[i];
1671
+ var parent_1 = parents[i + 1];
1672
+ var _a = getNthFilterOptions(currentParent, parent_1), tagOption = _a[0], indexOption = _a[1];
1673
+ if (indexOption)
1674
+ filterOptions.push(indexOption);
1675
+ filterOptions.push(tagOption);
1676
+ }
1677
+ return arrayUtils$2.reverse(filterOptions);
1678
+ }
1679
+ function isHtmlOrBodyElement(element) {
1680
+ return /html|body/.test(domUtils$2.getTagName(element).toLowerCase());
1681
+ }
1682
+
1683
+ var domUtils$3 = TESTCAFE_CORE.domUtils, arrayUtils$3 = TESTCAFE_CORE.arrayUtils;
1684
+ function optionsToStringArray(options) {
1685
+ var strings = [];
1686
+ for (var _i = 0, options_1 = options; _i < options_1.length; _i++) {
1687
+ var option = options_1[_i];
1688
+ if (arrayUtils$3.indexOf(options, option) === 0)
1689
+ strings.push("Selector('".concat(option.filter, "')"));
1690
+ else if (option.type === byText)
1691
+ strings.push(".withText('".concat(option.filter, "')"));
1692
+ else if (option.type === byIndex)
1693
+ strings.push(".nth(".concat(option.filter, ")"));
1694
+ else if (option.type === byTag)
1695
+ strings.push(".find('".concat(option.filter, "')"));
1696
+ else if (option.type === byAttr) {
1697
+ var attrValueString = option.filter.attrValueRe ? ", ".concat(option.filter.attrValueRe) : '';
1698
+ strings.push(".withAttribute('".concat(option.filter.attrName, "'").concat(attrValueString, ")"));
1699
+ }
1700
+ }
1701
+ return strings;
1702
+ }
1703
+ var SelectorDescriptor = /** @class */ (function () {
1704
+ function SelectorDescriptor(obj) {
1705
+ this.ruleType = obj.ruleType;
1706
+ this.isCustomRule = obj.isCustomRule;
1707
+ this.element = obj.element;
1708
+ this.ancestorSelectorDescriptor = obj.ancestorSelectorDescriptor;
1709
+ this.cssSelector = obj.cssSelector;
1710
+ this.filterOptions = arrayUtils$3.concat([], obj.filterOptions || []);
1711
+ this.filter = obj.filter;
1712
+ this.stringArray = this._getStringArrayRepresentation();
1713
+ }
1714
+ Object.defineProperty(SelectorDescriptor.prototype, "isCustom", {
1715
+ get: function () {
1716
+ return this.ancestorSelectorDescriptor ?
1717
+ this.isCustomRule || this.ancestorSelectorDescriptor.isCustomRule :
1718
+ this.isCustomRule;
1719
+ },
1720
+ enumerable: false,
1721
+ configurable: true
1722
+ });
1723
+ SelectorDescriptor.prototype._getStringArrayRepresentation = function () {
1724
+ return optionsToStringArray(this._concatFilterOptions());
1725
+ };
1726
+ SelectorDescriptor.prototype._addFilterByIndex = function (elements) {
1727
+ if (elements.length > 1) {
1728
+ var elementIndex = arrayUtils$3.indexOf(elements, this.element);
1729
+ if (elementIndex !== 0)
1730
+ this.filterOptions.push(new FilterOption(byIndex, elementIndex));
1731
+ }
1732
+ };
1733
+ SelectorDescriptor.prototype._concatFilterOptions = function () {
1734
+ var ancestorSelectorDescriptor = this.ancestorSelectorDescriptor;
1735
+ var initialOptions = [];
1736
+ if (ancestorSelectorDescriptor) {
1737
+ var ancestorOptions = ancestorSelectorDescriptor._concatFilterOptions();
1738
+ initialOptions = ancestorOptions;
1739
+ }
1740
+ if (this.cssSelector)
1741
+ initialOptions.push(new FilterOption(byTag, this.cssSelector));
1742
+ var concatenatedOpts = arrayUtils$3.concat(initialOptions, this.filterOptions);
1743
+ return arrayUtils$3.reduce(concatenatedOpts, function (options, option) {
1744
+ if (option.type === byTag && options.length) {
1745
+ var lastOption = options[options.length - 1];
1746
+ if (lastOption.type === byTag) {
1747
+ options[options.length - 1] = lastOption.concat(option);
1748
+ return options;
1749
+ }
1750
+ }
1751
+ options.push(option);
1752
+ return options;
1753
+ }, []);
1754
+ };
1755
+ SelectorDescriptor.prototype._getElements = function () {
1756
+ // NOTE: we should not check the receipt of an element for a selector
1757
+ // composed by tag tree because it cannot returns wrong result
1758
+ if (this.ruleType === RULE_TYPE.byTagTree)
1759
+ return [this.element];
1760
+ var ancestor = this.ancestorSelectorDescriptor ? this.ancestorSelectorDescriptor.element : domUtils$3.findDocument(this.element);
1761
+ var elements = null;
1762
+ if (this.cssSelector) {
1763
+ // NOTE: querySelectorAll method can raise error in case of invalid markup
1764
+ // (e.g. id attribute starts with number)
1765
+ try {
1766
+ /* eslint-disable no-eval */
1767
+ var evaluatedString = window.eval("(function(){return '".concat(this.cssSelector, "';})();"));
1768
+ /* eslint-enable no-eval */
1769
+ elements = arrayUtils$3.from(ancestor.querySelectorAll(evaluatedString));
1770
+ }
1771
+ catch (err) {
1772
+ return null;
1773
+ }
1774
+ }
1775
+ else
1776
+ elements = [ancestor];
1777
+ elements = elements.length && this.filter ? this.filter(elements) : elements;
1778
+ if (elements.length === 0 || arrayUtils$3.indexOf(elements, this.element) === -1)
1779
+ return [];
1780
+ return elements;
1781
+ };
1782
+ SelectorDescriptor.createFromInstance = function (descriptor, ancestorSelectorDescriptor) {
1783
+ return new SelectorDescriptor({
1784
+ ancestorSelectorDescriptor: ancestorSelectorDescriptor,
1785
+ cssSelector: descriptor.cssSelector,
1786
+ element: descriptor.element,
1787
+ filter: descriptor.filter,
1788
+ filterOptions: [].concat(descriptor.filterOptions || []),
1789
+ isCustomRule: descriptor.isCustomRule,
1790
+ ruleType: descriptor.ruleType,
1791
+ });
1792
+ };
1793
+ SelectorDescriptor.prototype.makeUnique = function () {
1794
+ var ancestorSelectorDescriptor = this.ancestorSelectorDescriptor;
1795
+ var ancestorElements = ancestorSelectorDescriptor ? ancestorSelectorDescriptor._getElements() : [];
1796
+ var elements = !ancestorSelectorDescriptor || ancestorElements ? this._getElements() : null;
1797
+ if (elements) {
1798
+ if (ancestorSelectorDescriptor)
1799
+ ancestorSelectorDescriptor._addFilterByIndex(ancestorElements);
1800
+ this._addFilterByIndex(elements);
1801
+ this.stringArray = this._getStringArrayRepresentation();
1802
+ }
1803
+ };
1804
+ return SelectorDescriptor;
1805
+ }());
1806
+
1807
+ /* eslint-disable no-empty-function, class-methods-use-this */
1808
+ var BaseCreator = /** @class */ (function () {
1809
+ function BaseCreator(type) {
1810
+ this.type = type;
1811
+ this.element = null;
1812
+ }
1813
+ BaseCreator.prototype._init = function () {
1814
+ };
1815
+ BaseCreator.prototype._shouldCreate = function () {
1816
+ throw new Error('Not implemented');
1817
+ };
1818
+ BaseCreator.prototype._getDescriptor = function ( /*ancestorSelectorDescriptor*/) {
1819
+ throw new Error('Not implemented');
1820
+ };
1821
+ BaseCreator.prototype.create = function (el, ancestorSelectorDescriptor) {
1822
+ this.element = el;
1823
+ this._init();
1824
+ if (this._shouldCreate(ancestorSelectorDescriptor))
1825
+ return this._getDescriptor(ancestorSelectorDescriptor);
1826
+ return null;
1827
+ };
1828
+ return BaseCreator;
1829
+ }());
1830
+
1831
+ var domUtils$4 = TESTCAFE_CORE.domUtils;
1832
+ var TOP_LEVEL_TAGS_RE = /html|body/;
1833
+ var UNIQUE_TAGS_RE = /header|footer|main/;
1834
+ var TagNameSelectorCreator = /** @class */ (function (_super) {
1835
+ __extends(TagNameSelectorCreator, _super);
1836
+ function TagNameSelectorCreator(useTopLevelTags) {
1837
+ if (useTopLevelTags === void 0) { useTopLevelTags = true; }
1838
+ var _this = _super.call(this, RULE_TYPE.byTagName) || this;
1839
+ _this.tagName = '';
1840
+ _this.useTopLevelParents = useTopLevelTags;
1841
+ return _this;
1842
+ }
1843
+ TagNameSelectorCreator.prototype._init = function () {
1844
+ this.tagName = domUtils$4.getTagName(this.element);
1845
+ };
1846
+ TagNameSelectorCreator.prototype._shouldCreate = function () {
1847
+ return this.useTopLevelParents && TOP_LEVEL_TAGS_RE.test(this.tagName) || UNIQUE_TAGS_RE.test(this.tagName);
1848
+ };
1849
+ TagNameSelectorCreator.prototype._getDescriptor = function () {
1850
+ return new SelectorDescriptor({
1851
+ ruleType: this.type,
1852
+ element: this.element,
1853
+ cssSelector: this.tagName,
1854
+ });
1855
+ };
1856
+ return TagNameSelectorCreator;
1857
+ }(BaseCreator));
1858
+
1859
+ /* eslint-disable no-useless-escape */
1860
+ function escapeAttrValue(text) {
1861
+ return text
1862
+ .replace(/\\/g, '\\\\\\$&')
1863
+ .replace(/'/g, '\\\\\\$&')
1864
+ .replace(/"/g, '\\\\$&');
1865
+ }
1866
+ function escapeSpecifiedSymbols(text) {
1867
+ return text
1868
+ .replace(/\\/g, '\\\\\\$&')
1869
+ .replace(/'/g, '\\\\\\$&')
1870
+ .replace(/(\!|#|"|\$|%|&|\(|\||\)|\*|\+|,|\.|\/|:|;|<|=|>|\?|@|\[|\]|\^|`|{|\||}|~)/g, '\\\\$&');
1871
+ }
1872
+ function escapeIdValue(idValue) {
1873
+ return escapeSpecifiedSymbols(idValue).replace(/\s/g, '\\\\ ');
1874
+ }
1875
+ function escapeValueForSelectorWithRegExp(text) {
1876
+ return text
1877
+ .replace(/'|"|\\|\||\-|\*|\?|\+|\^|\$|\[|\]/g, '\\$&')
1878
+ .replace(/\(|\)/g, '\\S');
1879
+ }
1880
+
1881
+ var hammerhead = window['%hammerhead%'];
1882
+
1883
+ // NOTE: taken from hammerhead i.e. https://github.com/benjamingr/RegExp.escape
1884
+ var SYMBOLS_TO_ESCAPE_RE = /[\\^$*+?.()|[\]{}]/g;
1885
+ function escapeRe(str) {
1886
+ return str.replace(SYMBOLS_TO_ESCAPE_RE, '\\$&');
1887
+ }
1888
+
1889
+ var selectorAttributeFilter = TESTCAFE_CORE.selectorAttributeFilter, arrayUtils$4 = TESTCAFE_CORE.arrayUtils;
1890
+ var nativeMethods$6 = hammerhead.nativeMethods;
1891
+ function makeRegExp(str) {
1892
+ return typeof str === 'string' ? new RegExp(escapeRe(str)) : str;
1893
+ }
1894
+ function getTextFilter(text) {
1895
+ return function (elements) {
1896
+ return arrayUtils$4.filter(elements, function (el) {
1897
+ var elementText = nativeMethods$6.htmlElementInnerTextGetter.call(el) ||
1898
+ nativeMethods$6.nodeTextContentGetter.call(el);
1899
+ return elementText.indexOf(text) > -1;
1900
+ });
1901
+ };
1902
+ }
1903
+ function getAttributeRegExpFilter(_a) {
1904
+ var attrName = _a.attrName, attrValueRe = _a.attrValueRe;
1905
+ return function (elements) {
1906
+ return arrayUtils$4.filter(elements, function (el) { return selectorAttributeFilter(el, 0, void 0, makeRegExp(attrName), makeRegExp(attrValueRe)); });
1907
+ };
1908
+ }
1909
+
1910
+ var domUtils$5 = TESTCAFE_CORE.domUtils, arrayUtils$5 = TESTCAFE_CORE.arrayUtils;
1911
+ var ASP_AUTOGENERATED_ATTR_RE = /\$ctl\d+|ctl\d+\$|_ctl\d+|ctl\d+_|^ctl\d+$/g;
1912
+ var SEPARATOR_CONST = '!!!!!separator!!!!!';
1913
+ var ANY_NUMBER_CONST = '!!!!!anyNumber!!!!!';
1914
+ var SEPARATOR_RE = new RegExp(SEPARATOR_CONST, 'g');
1915
+ var ANY_NUMBER_RE = new RegExp(ANY_NUMBER_CONST, 'g');
1916
+ var SOME_SPACES_RE = /\s{2,}/g;
1917
+ var MAX_TEXT_LENGTH_IN_SELECTOR = 50;
1918
+ var CLASS_ATTRIBUTE_NAME = 'class';
1919
+ // eslint-disable-next-line max-params
1920
+ function getRegExpAttributesDescriptor(ruleType, el, cssSelector, filterRegExpValue, ancestorSelectorDescriptor) {
1921
+ return new SelectorDescriptor({
1922
+ ancestorSelectorDescriptor: ancestorSelectorDescriptor,
1923
+ cssSelector: cssSelector,
1924
+ element: el,
1925
+ filter: getAttributeRegExpFilter(filterRegExpValue),
1926
+ filterOptions: new FilterOption(byAttr, filterRegExpValue),
1927
+ ruleType: ruleType,
1928
+ });
1929
+ }
1930
+ // eslint-disable-next-line max-lines-per-function, max-params
1931
+ function getAttributesDescriptor(ruleType, el, attributes, ancestorSelectorDescriptor) {
1932
+ var tagName = domUtils$5.getTagName(el);
1933
+ var cssSelector = '';
1934
+ var attrRegExpObject = null;
1935
+ arrayUtils$5.forEach(attributes, function (_a) {
1936
+ var name = _a.name, value = _a.value;
1937
+ var valueWasCut = false;
1938
+ var shouldUseRegExp = false;
1939
+ if (value.replace(SOME_SPACES_RE, ' ').length > MAX_TEXT_LENGTH_IN_SELECTOR) {
1940
+ value = value.substr(0, MAX_TEXT_LENGTH_IN_SELECTOR);
1941
+ valueWasCut = true;
1942
+ }
1943
+ if (ASP_AUTOGENERATED_ATTR_RE.test(value)) {
1944
+ shouldUseRegExp = true;
1945
+ value = value.replace(ASP_AUTOGENERATED_ATTR_RE, function (substr) { return substr.replace(/\d+/, ANY_NUMBER_CONST); });
1946
+ }
1947
+ if (SOME_SPACES_RE.test(value)) {
1948
+ shouldUseRegExp = true;
1949
+ value = value.replace(SOME_SPACES_RE, SEPARATOR_CONST);
1950
+ }
1951
+ if (shouldUseRegExp) {
1952
+ if (!attrRegExpObject) {
1953
+ value = escapeValueForSelectorWithRegExp(value);
1954
+ value = value.replace(ANY_NUMBER_RE, '\\d+').replace(SEPARATOR_RE, '\\s+');
1955
+ attrRegExpObject = { attrName: name, attrValueRe: new RegExp(value) };
1956
+ }
1957
+ }
1958
+ else {
1959
+ value = name === CLASS_ATTRIBUTE_NAME ? escapeSpecifiedSymbols(value).trimEnd() : escapeAttrValue(value);
1960
+ if (name === CLASS_ATTRIBUTE_NAME && !valueWasCut)
1961
+ cssSelector += (' ' + value).replace(/\s+/g, '.');
1962
+ else
1963
+ cssSelector += "[".concat(name).concat(valueWasCut ? '^' : '').concat(value ? "=\"".concat(value, "\"") : '', "]");
1964
+ }
1965
+ });
1966
+ if (attrRegExpObject) {
1967
+ var selector = cssSelector || tagName;
1968
+ return getRegExpAttributesDescriptor(ruleType, el, selector, attrRegExpObject, ancestorSelectorDescriptor);
1969
+ }
1970
+ return new SelectorDescriptor({
1971
+ ruleType: ruleType,
1972
+ element: el,
1973
+ ancestorSelectorDescriptor: ancestorSelectorDescriptor,
1974
+ cssSelector: cssSelector,
1975
+ });
1976
+ }
1977
+
1978
+ var domUtils$6 = TESTCAFE_CORE.domUtils;
1979
+ var ASP_AUTOGENERATED_ID_PART_RE = /_ctl\d+|ctl\d+_|^ctl\d+$/g;
1980
+ var IdSelectorCreator = /** @class */ (function (_super) {
1981
+ __extends(IdSelectorCreator, _super);
1982
+ function IdSelectorCreator() {
1983
+ var _this = _super.call(this, RULE_TYPE.byId) || this;
1984
+ _this.idAttr = null;
1985
+ return _this;
1986
+ }
1987
+ IdSelectorCreator.prototype._init = function () {
1988
+ this.idAttr = this.element.getAttribute('id');
1989
+ };
1990
+ IdSelectorCreator.prototype._shouldCreate = function () {
1991
+ return !!this.idAttr;
1992
+ };
1993
+ IdSelectorCreator.prototype._getDescriptor = function () {
1994
+ if (ASP_AUTOGENERATED_ID_PART_RE.test(this.idAttr)) {
1995
+ var idRegExp = escapeValueForSelectorWithRegExp(this.idAttr);
1996
+ idRegExp = idRegExp.replace(ASP_AUTOGENERATED_ID_PART_RE, function (substr) { return substr.replace(/\d+/, '\\d+'); });
1997
+ var tagName = domUtils$6.getTagName(this.element);
1998
+ var filterValue = { attrName: 'id', attrValueRe: new RegExp(idRegExp) };
1999
+ return getRegExpAttributesDescriptor(RULE_TYPE.byId, this.element, tagName, filterValue);
2000
+ }
2001
+ return new SelectorDescriptor({
2002
+ ruleType: RULE_TYPE.byId,
2003
+ element: this.element,
2004
+ cssSelector: '#' + escapeIdValue(this.idAttr),
2005
+ });
2006
+ };
2007
+ return IdSelectorCreator;
2008
+ }(BaseCreator));
2009
+
2010
+ var domUtils$7 = TESTCAFE_CORE.domUtils;
2011
+ var trim = hammerhead.utils.trim;
2012
+ var nativeMethods$7 = hammerhead.nativeMethods;
2013
+ var ELEMENTS_WITH_TEXT_RE = /^i$|^b$|^big$|^small$|^em$|^strong$|^dfn$|^code$|^samp$|^kbd$|^var$|^cite$|^abbr$|^acronym$|^sub$|^sup$|span$|^bdo$|^address$|^div$|^a$|^object$|^p$|^h\d$|^pre$|^q$|^ins$|^del$|^dt$|^dd$|^li$|^label$|^option$|^fieldset$|^legend$|^button$|^caption$|^td$|^th$|^title$/;
2014
+ var MAX_TEXT_LENGTH_IN_SELECTOR$1 = 50;
2015
+ var SYMBOLS_TO_ESCAPE_RE$1 = /['"\\]/g;
2016
+ var PROHIBITED_TEXT_SYMBOL_RE = /\r?\n|\r/i;
2017
+ function getTextPart(text) {
2018
+ text = text.trim().replace(SYMBOLS_TO_ESCAPE_RE$1, '\\$&');
2019
+ var endMatch = PROHIBITED_TEXT_SYMBOL_RE.exec(text);
2020
+ var endIndex = endMatch ? endMatch.index : text.length;
2021
+ return trim(text.substring(0, Math.min(endIndex, MAX_TEXT_LENGTH_IN_SELECTOR$1)));
2022
+ }
2023
+ function hasOwnTextForSelector(el, elementText) {
2024
+ if (!ELEMENTS_WITH_TEXT_RE.test(domUtils$7.getTagName(el)))
2025
+ return '';
2026
+ elementText = trim(elementText.replace(/\s+/g, ' '));
2027
+ return /\S/.test(elementText);
2028
+ }
2029
+ function getOwnTextForSelector(el) {
2030
+ /*eslint-disable-next-line no-restricted-properties*/
2031
+ var text = domUtils$7.isHtmlElement(el) ? nativeMethods$7.htmlElementInnerTextGetter.call(el) : el.innerText;
2032
+ if (text)
2033
+ return getTextPart(text);
2034
+ if (domUtils$7.isOptionElement(el)) {
2035
+ var optionText = nativeMethods$7.nodeTextContentGetter.call(el);
2036
+ return optionText ? getTextPart(optionText) : '';
2037
+ }
2038
+ return '';
2039
+ }
2040
+
2041
+ var domUtils$8 = TESTCAFE_CORE.domUtils;
2042
+ var TextSelectorCreator = /** @class */ (function (_super) {
2043
+ __extends(TextSelectorCreator, _super);
2044
+ function TextSelectorCreator() {
2045
+ var _this = _super.call(this, RULE_TYPE.byText) || this;
2046
+ _this.elementText = '';
2047
+ return _this;
2048
+ }
2049
+ TextSelectorCreator.prototype._init = function () {
2050
+ this.elementText = getOwnTextForSelector(this.element);
2051
+ };
2052
+ TextSelectorCreator.prototype._shouldCreate = function () {
2053
+ return hasOwnTextForSelector(this.element, this.elementText);
2054
+ };
2055
+ TextSelectorCreator.prototype._getDescriptor = function () {
2056
+ return new SelectorDescriptor({
2057
+ ruleType: this.type,
2058
+ element: this.element,
2059
+ cssSelector: domUtils$8.getTagName(this.element),
2060
+ filterOptions: new FilterOption(byText, this.elementText),
2061
+ filter: getTextFilter(this.elementText),
2062
+ });
2063
+ };
2064
+ return TextSelectorCreator;
2065
+ }(BaseCreator));
2066
+
2067
+ var domUtils$9 = TESTCAFE_CORE.domUtils, arrayUtils$6 = TESTCAFE_CORE.arrayUtils;
2068
+ var nativeMethods$8 = hammerhead.nativeMethods;
2069
+ var STORED_ATTRIBUTES_PROPERTY = '%testcafe-stored-attributes%';
2070
+ var CUSTOM_STORED_ATTRIBUTES_PROPERTY = '%testcafe-custom-stored-attributes%';
2071
+ var ALLOWED_ATTRIBUTE_NAMES_RE = /(^alt$|^name$|^class$|^title$|^data-\S+)/;
2072
+ var GOOGLE_ANALYTICS_ATTRIBUTE_RE = /^data-ga\S+/;
2073
+ function isAttributeAcceptableForSelector(attribute, customAttrNames) {
2074
+ if (customAttrNames === void 0) { customAttrNames = []; }
2075
+ var name = attribute.nodeName;
2076
+ var value = attribute.nodeValue;
2077
+ if (!value)
2078
+ return false;
2079
+ // NOTE: we don't take into account attributes added by TestCafe
2080
+ return ALLOWED_ATTRIBUTE_NAMES_RE.test(name) &&
2081
+ arrayUtils$6.indexOf(customAttrNames, name) === -1 &&
2082
+ !GOOGLE_ANALYTICS_ATTRIBUTE_RE.test(name) &&
2083
+ !domUtils$9.isHammerheadAttr(name);
2084
+ }
2085
+ function getAttributesForSelector(element, customAttrNames) {
2086
+ if (customAttrNames === void 0) { customAttrNames = []; }
2087
+ var storedAttributes = element[STORED_ATTRIBUTES_PROPERTY];
2088
+ // NOTE: we don't take class into account because we have a separate rule for it
2089
+ if (storedAttributes)
2090
+ return arrayUtils$6.filter(storedAttributes, function (attr) { return attr.name !== CLASS_ATTRIBUTE_NAME; });
2091
+ var attributes = nativeMethods$8.elementAttributesGetter.call(element);
2092
+ var attributesForSelector = [];
2093
+ var attribute = null;
2094
+ for (var i = 0; i < attributes.length; i++) {
2095
+ attribute = attributes[i];
2096
+ if (attribute.nodeName !== CLASS_ATTRIBUTE_NAME && isAttributeAcceptableForSelector(attribute, customAttrNames))
2097
+ attributesForSelector.push({ name: attribute.nodeName, value: attribute.nodeValue });
2098
+ }
2099
+ return attributesForSelector;
2100
+ }
2101
+ function getAttributeValue(element, attrName) {
2102
+ var attributes = element[STORED_ATTRIBUTES_PROPERTY] || nativeMethods$8.elementAttributesGetter.call(element);
2103
+ var attribute = null;
2104
+ for (var i = 0; i < attributes.length; i++) {
2105
+ attribute = attributes[i];
2106
+ /*eslint-disable no-restricted-properties*/
2107
+ if (attribute.name === attrName && attribute.value)
2108
+ return attribute.value;
2109
+ /*eslint-enable*/
2110
+ }
2111
+ return null;
2112
+ }
2113
+ function getCustomAttributeForSelector(el, customAttrName) {
2114
+ var customStoredAttributes = el[CUSTOM_STORED_ATTRIBUTES_PROPERTY];
2115
+ if (customStoredAttributes) {
2116
+ var storedAttr = arrayUtils$6.find(customStoredAttributes, function (attr) { return attr.name === customAttrName; });
2117
+ return storedAttr ? storedAttr : null;
2118
+ }
2119
+ return el.hasAttribute(customAttrName) ?
2120
+ { name: customAttrName, value: el.getAttribute(customAttrName) } : null;
2121
+ }
2122
+
2123
+ var AttrSelectorCreator = /** @class */ (function (_super) {
2124
+ __extends(AttrSelectorCreator, _super);
2125
+ function AttrSelectorCreator(customAttrNames) {
2126
+ if (customAttrNames === void 0) { customAttrNames = []; }
2127
+ var _this = _super.call(this, RULE_TYPE.byAttr) || this;
2128
+ _this.customAttrNames = customAttrNames;
2129
+ _this.elementAttributes = [];
2130
+ return _this;
2131
+ }
2132
+ AttrSelectorCreator.prototype._init = function () {
2133
+ this.elementAttributes = getAttributesForSelector(this.element, this.customAttrNames);
2134
+ };
2135
+ AttrSelectorCreator.prototype._shouldCreate = function () {
2136
+ return !!this.elementAttributes.length;
2137
+ };
2138
+ AttrSelectorCreator.prototype._getDescriptor = function () {
2139
+ return getAttributesDescriptor(this.type, this.element, this.elementAttributes);
2140
+ };
2141
+ return AttrSelectorCreator;
2142
+ }(BaseCreator));
2143
+
2144
+ var ClassSelectorCreator = /** @class */ (function (_super) {
2145
+ __extends(ClassSelectorCreator, _super);
2146
+ function ClassSelectorCreator() {
2147
+ var _this = _super.call(this, RULE_TYPE.byClassAttr) || this;
2148
+ _this.className = '';
2149
+ return _this;
2150
+ }
2151
+ ClassSelectorCreator.prototype._init = function () {
2152
+ this.className = getAttributeValue(this.element, CLASS_ATTRIBUTE_NAME);
2153
+ };
2154
+ ClassSelectorCreator.prototype._shouldCreate = function () {
2155
+ return !!this.className;
2156
+ };
2157
+ ClassSelectorCreator.prototype._getDescriptor = function () {
2158
+ return getAttributesDescriptor(this.type, this.element, [{
2159
+ name: CLASS_ATTRIBUTE_NAME,
2160
+ value: this.className,
2161
+ }]);
2162
+ };
2163
+ return ClassSelectorCreator;
2164
+ }(BaseCreator));
2165
+
2166
+ var domUtils$a = TESTCAFE_CORE.domUtils, arrayUtils$7 = TESTCAFE_CORE.arrayUtils;
2167
+ var TagTreeSelectorCreator = /** @class */ (function (_super) {
2168
+ __extends(TagTreeSelectorCreator, _super);
2169
+ function TagTreeSelectorCreator() {
2170
+ var _this = _super.call(this, RULE_TYPE.byTagTree) || this;
2171
+ _this.parents = [];
2172
+ return _this;
2173
+ }
2174
+ TagTreeSelectorCreator.prototype._shouldCreate = function (ancestorSelectorDescriptor) {
2175
+ var ancestor = ancestorSelectorDescriptor ?
2176
+ ancestorSelectorDescriptor.element : domUtils$a.findDocument(this.element).body;
2177
+ this.parents = getParentsUntil(this.element, ancestor);
2178
+ this.parents.push(ancestor);
2179
+ // NOTE: in some cases 'parentElement' is undefined for 'svg' element in IE
2180
+ return this.parents.length;
2181
+ };
2182
+ TagTreeSelectorCreator.prototype._getDescriptor = function (ancestorSelectorDescriptor) {
2183
+ var cssSelector = '';
2184
+ var filterOptions = [];
2185
+ if (isHtmlOrBodyElement(this.element))
2186
+ filterOptions.push(new FilterOption(byTag, domUtils$a.getTagName(this.element)));
2187
+ else
2188
+ filterOptions = getTagTreeFilterOptions(this.element, this.parents);
2189
+ if (ancestorSelectorDescriptor) {
2190
+ return new SelectorDescriptor({
2191
+ ruleType: this.type,
2192
+ element: this.element,
2193
+ ancestorSelectorDescriptor: ancestorSelectorDescriptor,
2194
+ filterOptions: filterOptions,
2195
+ });
2196
+ }
2197
+ if (filterOptions.length) {
2198
+ cssSelector = filterOptions[0].filter;
2199
+ arrayUtils$7.splice(filterOptions, 0, 1);
2200
+ }
2201
+ return new SelectorDescriptor({
2202
+ ruleType: this.type,
2203
+ element: this.element,
2204
+ cssSelector: cssSelector,
2205
+ filterOptions: filterOptions,
2206
+ });
2207
+ };
2208
+ return TagTreeSelectorCreator;
2209
+ }(BaseCreator));
2210
+
2211
+ var _a;
2212
+ var SELECTOR_CREATORS = (_a = {},
2213
+ _a[RULE_TYPE.byTagName] = new TagNameSelectorCreator(),
2214
+ _a[RULE_TYPE.byId] = new IdSelectorCreator(),
2215
+ _a[RULE_TYPE.byText] = new TextSelectorCreator(),
2216
+ _a[RULE_TYPE.byClassAttr] = new ClassSelectorCreator(),
2217
+ _a[RULE_TYPE.byAttr] = new AttrSelectorCreator(),
2218
+ _a[RULE_TYPE.byTagTree] = new TagTreeSelectorCreator(),
2219
+ _a);
2220
+
2221
+ var CustomAttrSelectorCreator = /** @class */ (function (_super) {
2222
+ __extends(CustomAttrSelectorCreator, _super);
2223
+ function CustomAttrSelectorCreator(attrName) {
2224
+ var _this = _super.call(this, attrName) || this;
2225
+ _this.attrName = attrName;
2226
+ _this.elementAttributes = [];
2227
+ return _this;
2228
+ }
2229
+ CustomAttrSelectorCreator.prototype._init = function () {
2230
+ var attr = getCustomAttributeForSelector(this.element, this.attrName);
2231
+ this.elementAttributes = attr ? [attr] : [];
2232
+ };
2233
+ CustomAttrSelectorCreator.prototype._shouldCreate = function () {
2234
+ return !!this.elementAttributes.length;
2235
+ };
2236
+ CustomAttrSelectorCreator.prototype._getDescriptor = function () {
2237
+ var descriptor = getAttributesDescriptor(this.type, this.element, this.elementAttributes);
2238
+ descriptor.isCustomRule = true;
2239
+ return descriptor;
2240
+ };
2241
+ return CustomAttrSelectorCreator;
2242
+ }(BaseCreator));
2243
+
2244
+ var arrayUtils$8 = TESTCAFE_CORE.arrayUtils;
2245
+ var COMPOUNDABLE_ANCESTOR_RULE_TYPES = [
2246
+ RULE_TYPE.byTagName,
2247
+ RULE_TYPE.byId,
2248
+ RULE_TYPE.byClassAttr,
2249
+ RULE_TYPE.byAttr,
2250
+ ];
2251
+ var COMPOUNDABLE_CHILD_RULE_TYPES = [
2252
+ RULE_TYPE.byText,
2253
+ RULE_TYPE.byClassAttr,
2254
+ RULE_TYPE.byAttr,
2255
+ RULE_TYPE.byTagTree,
2256
+ ];
2257
+ function isSelectorDescriptorCompoundable(selectorDescriptor) {
2258
+ return selectorDescriptor.isCustomRule ||
2259
+ arrayUtils$8.indexOf(COMPOUNDABLE_CHILD_RULE_TYPES, selectorDescriptor.ruleType) !== -1 &&
2260
+ selectorDescriptor.ruleType !== RULE_TYPE.byTagTree;
2261
+ }
2262
+ function isChildRuleCompoundable(rule) {
2263
+ return rule.editable || arrayUtils$8.indexOf(COMPOUNDABLE_CHILD_RULE_TYPES, rule.type) !== -1;
2264
+ }
2265
+ function isAncestorRuleCompoundable(rule) {
2266
+ return rule.editable || arrayUtils$8.indexOf(COMPOUNDABLE_ANCESTOR_RULE_TYPES, rule.type) !== -1;
2267
+ }
2268
+
2269
+ var PARENT_CHILD_RULES_SEPARATOR = ' > ';
2270
+ // NOTE: prior to introducing the selector prioritization,
2271
+ // selectors only were able to have ruleType (parent-child).
2272
+ // Currently selector has ruleType and ancestorRuleType.
2273
+ function getSelectorType(elementRuleType, ancestorRuleType) {
2274
+ return ancestorRuleType ?
2275
+ ancestorRuleType + PARENT_CHILD_RULES_SEPARATOR + elementRuleType :
2276
+ elementRuleType;
2277
+ }
2278
+
2279
+ var DEFAULT_PRIORITY = 1;
2280
+ function calculateRulesPriority(rules) {
2281
+ var priority = {};
2282
+ var rulePriority = DEFAULT_PRIORITY;
2283
+ for (var _i = 0, rules_1 = rules; _i < rules_1.length; _i++) {
2284
+ var ancestorRule = rules_1[_i];
2285
+ priority[ancestorRule.type] = rulePriority++;
2286
+ if (isAncestorRuleCompoundable(ancestorRule)) {
2287
+ for (var _a = 0, rules_2 = rules; _a < rules_2.length; _a++) {
2288
+ var childRule = rules_2[_a];
2289
+ if (isChildRuleCompoundable(childRule)) {
2290
+ var resultRuleType = getSelectorType(childRule.type, ancestorRule.type);
2291
+ priority[resultRuleType] = rulePriority++;
2292
+ }
2293
+ }
2294
+ }
2295
+ }
2296
+ return priority;
2297
+ }
2298
+
2299
+ var domUtils$b = TESTCAFE_CORE.domUtils, arrayUtils$9 = TESTCAFE_CORE.arrayUtils;
2300
+ var MAX_DEFAULT_SELECTOR_COUNT = 10;
2301
+ function generateSelectorDescriptorsByCreators(el, selectorCreators, ancestorSelectorDescriptor) {
2302
+ var selectorDescriptors = [];
2303
+ for (var _i = 0, selectorCreators_1 = selectorCreators; _i < selectorCreators_1.length; _i++) {
2304
+ var creator = selectorCreators_1[_i];
2305
+ var selectorDescriptor = creator.create(el, ancestorSelectorDescriptor);
2306
+ if (selectorDescriptor)
2307
+ selectorDescriptors.push(selectorDescriptor);
2308
+ }
2309
+ return selectorDescriptors;
2310
+ }
2311
+ function getAncestorSelectorDescriptor(ancestors, ancestorSelectorCreator) {
2312
+ for (var _i = 0, ancestors_1 = ancestors; _i < ancestors_1.length; _i++) {
2313
+ var ancestor = ancestors_1[_i];
2314
+ var ancestorSelectorDescriptor = ancestorSelectorCreator.create(ancestor);
2315
+ if (ancestorSelectorDescriptor)
2316
+ return ancestorSelectorDescriptor;
2317
+ }
2318
+ return null;
2319
+ }
2320
+ function generateAncestorSelectorDescriptorsByCreators(ancestors, selectorCreators) {
2321
+ var selectorDescriptors = [];
2322
+ for (var _i = 0, selectorCreators_2 = selectorCreators; _i < selectorCreators_2.length; _i++) {
2323
+ var creator = selectorCreators_2[_i];
2324
+ var selectorDescriptor = getAncestorSelectorDescriptor(ancestors, creator);
2325
+ if (selectorDescriptor)
2326
+ selectorDescriptors.push(selectorDescriptor);
2327
+ }
2328
+ return selectorDescriptors;
2329
+ }
2330
+ function removeRepetitiveSelectorDescriptors(selectorDescriptors) {
2331
+ var resultSelectorDescriptors = [];
2332
+ var repetitiveStringIndex = function (descriptor) { return findIndex(resultSelectorDescriptors, function (desc) {
2333
+ return arrayUtils$9.join(desc.stringArray, '') === arrayUtils$9.join(descriptor.stringArray, '');
2334
+ }); };
2335
+ for (var _i = 0, selectorDescriptors_1 = selectorDescriptors; _i < selectorDescriptors_1.length; _i++) {
2336
+ var descriptor = selectorDescriptors_1[_i];
2337
+ var index = repetitiveStringIndex(descriptor);
2338
+ if (index === -1)
2339
+ resultSelectorDescriptors.push(descriptor);
2340
+ else if (resultSelectorDescriptors[index].priority > descriptor.priority)
2341
+ arrayUtils$9.splice(resultSelectorDescriptors, index, 1, descriptor);
2342
+ }
2343
+ return resultSelectorDescriptors;
2344
+ }
2345
+ function removeRedundantCompoundSelectorDescriptors(selectorDescriptors) {
2346
+ var defaultRuleSelectors = arrayUtils$9.filter(selectorDescriptors, function (descriptor) { return !descriptor.isCustom; });
2347
+ var defaultCompoundRuleSelectors = arrayUtils$9.filter(defaultRuleSelectors, function (descriptor) { return descriptor.ancestorSelectorDescriptor; });
2348
+ var compoundSelectorCount = defaultCompoundRuleSelectors.length;
2349
+ var elementSelectorCount = defaultRuleSelectors.length - compoundSelectorCount;
2350
+ var expectedCompoundRuleCount = MAX_DEFAULT_SELECTOR_COUNT - elementSelectorCount;
2351
+ var getAncestorType = function (descriptor) {
2352
+ return descriptor && descriptor.ancestorSelectorDescriptor ?
2353
+ descriptor.ancestorSelectorDescriptor.ruleType : null;
2354
+ };
2355
+ var currentIndex = compoundSelectorCount - 1;
2356
+ while (compoundSelectorCount > expectedCompoundRuleCount) {
2357
+ var descriptor = defaultCompoundRuleSelectors[currentIndex];
2358
+ var ancestorRuleType = getAncestorType(descriptor);
2359
+ while (getAncestorType(defaultCompoundRuleSelectors[currentIndex - 1]) === ancestorRuleType) {
2360
+ arrayUtils$9.remove(selectorDescriptors, defaultCompoundRuleSelectors[currentIndex]);
2361
+ compoundSelectorCount--;
2362
+ if (compoundSelectorCount <= expectedCompoundRuleCount)
2363
+ break;
2364
+ currentIndex--;
2365
+ }
2366
+ currentIndex--;
2367
+ }
2368
+ }
2369
+ var SelectorGenerator = /** @class */ (function () {
2370
+ function SelectorGenerator(rules) {
2371
+ if (rules === void 0) { rules = DEFAULT_SELECTOR_RULES; }
2372
+ this.rules = arrayUtils$9.filter(rules, function (rule) { return !rule.disabled; });
2373
+ var _a = SelectorGenerator._processRules(this.rules), customRules = _a.customRules, defaultRules = _a.defaultRules;
2374
+ this.customRules = customRules;
2375
+ this.defaultRules = defaultRules;
2376
+ this.customAttrNames = [];
2377
+ this.customSelectorCreators = [];
2378
+ this.elementSelectorCreators = [];
2379
+ this.ancestorSelectorCreators = [];
2380
+ this._createCustomSelectorCreators();
2381
+ this._createElementSelectorCreators();
2382
+ this._createAncestorSelectorCreators();
2383
+ this.rulePriority = calculateRulesPriority(this.rules);
2384
+ }
2385
+ SelectorGenerator._priorityComparator = function (first, second) {
2386
+ return first.priority - second.priority;
2387
+ };
2388
+ SelectorGenerator._getSelectorType = function (selectorDescriptor) {
2389
+ var ancestorSelectorDescriptor = selectorDescriptor.ancestorSelectorDescriptor;
2390
+ var ancestorSelectorType = ancestorSelectorDescriptor ? ancestorSelectorDescriptor.ruleType : '';
2391
+ return getSelectorType(selectorDescriptor.ruleType, ancestorSelectorType);
2392
+ };
2393
+ SelectorGenerator._processRules = function (rules) {
2394
+ var defaultRules = [];
2395
+ var customRules = [];
2396
+ arrayUtils$9.filter(rules, function (rule) {
2397
+ if (rule.editable)
2398
+ customRules.push(rule);
2399
+ else
2400
+ defaultRules.push(rule);
2401
+ });
2402
+ return { customRules: customRules, defaultRules: defaultRules };
2403
+ };
2404
+ SelectorGenerator.prototype._createCustomSelectorCreators = function () {
2405
+ var _this = this;
2406
+ arrayUtils$9.forEach(this.customRules, function (rule) {
2407
+ _this.customAttrNames.push(rule.type);
2408
+ _this.customSelectorCreators.push(new CustomAttrSelectorCreator(rule.type));
2409
+ });
2410
+ };
2411
+ SelectorGenerator.prototype._createElementSelectorCreators = function () {
2412
+ var _this = this;
2413
+ var defaultCreators = [];
2414
+ arrayUtils$9.forEach(this.defaultRules, function (rule) {
2415
+ var creator = rule.type === RULE_TYPE.byAttr ?
2416
+ new AttrSelectorCreator(_this.customAttrNames) :
2417
+ SELECTOR_CREATORS[rule.type];
2418
+ defaultCreators.push(creator);
2419
+ });
2420
+ this.elementSelectorCreators = arrayUtils$9.concat(defaultCreators, this.customSelectorCreators);
2421
+ };
2422
+ SelectorGenerator.prototype._createAncestorSelectorCreators = function () {
2423
+ for (var _i = 0, _a = this.customRules; _i < _a.length; _i++) {
2424
+ var rule = _a[_i];
2425
+ this.ancestorSelectorCreators.push(new CustomAttrSelectorCreator(rule.type));
2426
+ }
2427
+ for (var _b = 0, _c = this.defaultRules; _b < _c.length; _b++) {
2428
+ var rule = _c[_b];
2429
+ if (isAncestorRuleCompoundable(rule)) {
2430
+ if (rule.type === RULE_TYPE.byTagName)
2431
+ this.ancestorSelectorCreators.push(new TagNameSelectorCreator(false));
2432
+ else
2433
+ this.ancestorSelectorCreators.push(SELECTOR_CREATORS[rule.type]);
2434
+ }
2435
+ }
2436
+ };
2437
+ SelectorGenerator.prototype._generateCompoundSelectorDescriptor = function (el, ancestors, elementSelectorDescriptors) {
2438
+ var compoundSelectorDescriptors = arrayUtils$9.filter(elementSelectorDescriptors, isSelectorDescriptorCompoundable);
2439
+ var ancestorSelectorDescriptors = generateAncestorSelectorDescriptorsByCreators(ancestors, this.ancestorSelectorCreators);
2440
+ var selectorDescriptors = [];
2441
+ var descriptor = null;
2442
+ var ancestorDescriptor = null;
2443
+ for (var _i = 0, ancestorSelectorDescriptors_1 = ancestorSelectorDescriptors; _i < ancestorSelectorDescriptors_1.length; _i++) {
2444
+ var ancestorSelectorDescriptor = ancestorSelectorDescriptors_1[_i];
2445
+ for (var _a = 0, compoundSelectorDescriptors_1 = compoundSelectorDescriptors; _a < compoundSelectorDescriptors_1.length; _a++) {
2446
+ var elementSelectorDescriptor = compoundSelectorDescriptors_1[_a];
2447
+ ancestorDescriptor = SelectorDescriptor.createFromInstance(ancestorSelectorDescriptor);
2448
+ descriptor = SelectorDescriptor.createFromInstance(elementSelectorDescriptor, ancestorDescriptor);
2449
+ selectorDescriptors.push(descriptor);
2450
+ }
2451
+ //TODO: check ancestorDescriptor and ancestorSelectorDescriptor
2452
+ ancestorDescriptor = SelectorDescriptor.createFromInstance(ancestorSelectorDescriptor);
2453
+ descriptor = generateSelectorDescriptorsByCreators(el, [SELECTOR_CREATORS[RULE_TYPE.byTagTree]], ancestorSelectorDescriptor);
2454
+ selectorDescriptors = arrayUtils$9.concat(selectorDescriptors, descriptor);
2455
+ }
2456
+ return selectorDescriptors;
2457
+ };
2458
+ SelectorGenerator.prototype._cleanAndSortDescriptors = function (selectorDescriptors) {
2459
+ var result = [];
2460
+ for (var _i = 0, selectorDescriptors_2 = selectorDescriptors; _i < selectorDescriptors_2.length; _i++) {
2461
+ var descriptor = selectorDescriptors_2[_i];
2462
+ descriptor.makeUnique();
2463
+ var selectorType = SelectorGenerator._getSelectorType(descriptor);
2464
+ var priority = this.rulePriority[selectorType];
2465
+ if (priority !== null) {
2466
+ descriptor.priority = priority;
2467
+ result.push(descriptor);
2468
+ }
2469
+ }
2470
+ result = removeRepetitiveSelectorDescriptors(result);
2471
+ result = result.sort(SelectorGenerator._priorityComparator);
2472
+ removeRedundantCompoundSelectorDescriptors(result);
2473
+ return result;
2474
+ };
2475
+ SelectorGenerator.prototype._generateDescriptors = function (el) {
2476
+ var elementSelectorDescriptors = generateSelectorDescriptorsByCreators(el, this.elementSelectorCreators);
2477
+ var ancestors = getParentsUntil(el, domUtils$b.findDocument(el).body);
2478
+ var compoundSelectorDescriptors = this._generateCompoundSelectorDescriptor(el, ancestors, elementSelectorDescriptors);
2479
+ var selectorDescriptors = arrayUtils$9.concat(elementSelectorDescriptors, compoundSelectorDescriptors);
2480
+ return this._cleanAndSortDescriptors(selectorDescriptors);
2481
+ };
2482
+ SelectorGenerator.prototype.generate = function (element) {
2483
+ var selectorDescriptors = this._generateDescriptors(element);
2484
+ return arrayUtils$9.map(selectorDescriptors, function (selectorDescriptor) {
2485
+ var stringArray = selectorDescriptor.stringArray, ruleType = selectorDescriptor.ruleType, ancestorSelectorDescriptor = selectorDescriptor.ancestorSelectorDescriptor;
2486
+ var selector = {
2487
+ value: arrayUtils$9.join(stringArray, ''),
2488
+ rules: [ruleType],
2489
+ };
2490
+ if (ancestorSelectorDescriptor)
2491
+ selector.rules.push(ancestorSelectorDescriptor.ruleType);
2492
+ return selector;
2493
+ });
2494
+ };
2495
+ SelectorGenerator.RULES = RULES;
2496
+ return SelectorGenerator;
2497
+ }());
2498
+
2499
+ var selectorGenerator = new SelectorGenerator();
2500
+
2501
+ function getRectInAbsoluteCoordinates(element) {
2502
+ var rect = element.getBoundingClientRect();
2503
+ var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
2504
+ var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
2505
+ return {
2506
+ top: rect.top + scrollTop,
2507
+ left: rect.left + scrollLeft,
2508
+ height: rect.height,
2509
+ width: rect.width,
2510
+ bottom: rect.bottom + scrollTop,
2511
+ right: rect.right + scrollLeft,
2512
+ };
2513
+ }
2514
+
2515
+ var Higthlighter = /** @class */ (function () {
2516
+ function Higthlighter() {
2517
+ this.targets = new Map();
2518
+ }
2519
+ Higthlighter.prototype._remove = function (target, frame) {
2520
+ this.targets.delete(target);
2521
+ removeFromUiRoot(frame);
2522
+ };
2523
+ Higthlighter.prototype._setPosition = function (target, frame) {
2524
+ var rect = getRectInAbsoluteCoordinates(target);
2525
+ var styles = {};
2526
+ for (var _i = 0, _a = ['top', 'left', 'width', 'height']; _i < _a.length; _i++) {
2527
+ var key = _a[_i];
2528
+ styles[key] = rect[key] + 'px';
2529
+ }
2530
+ setStyles(frame, styles);
2531
+ };
2532
+ Higthlighter.prototype.highlight = function (target) {
2533
+ if (!target || this.targets.has(target))
2534
+ return;
2535
+ var frame = createElementFromDescriptor(elementFrame);
2536
+ this.targets.set(target, frame);
2537
+ this._setPosition(target, frame);
2538
+ addToUiRoot(frame);
2539
+ };
2540
+ Higthlighter.prototype.stopHighlighting = function () {
2541
+ var _this = this;
2542
+ this.targets.forEach(function (frame, target) { return _this._remove(target, frame); });
2543
+ };
2544
+ return Higthlighter;
2545
+ }());
2546
+ var highlighter = new Higthlighter();
2547
+
2548
+ /* eslint-disable no-restricted-properties */
2549
+ var nativeMethods$9 = hammerhead$1__default.nativeMethods;
2550
+ var ARROW_OFFSET_LEFT = 12;
2551
+ function getViewportRect() {
2552
+ return {
2553
+ width: document.documentElement.clientWidth,
2554
+ height: document.documentElement.clientHeight,
2555
+ };
2556
+ }
2557
+ var Tooltip = /** @class */ (function () {
2558
+ function Tooltip() {
2559
+ this._createElements();
2560
+ }
2561
+ Tooltip.prototype._createElements = function () {
2562
+ this.tooltip = createElementFromDescriptor(tooltip);
2563
+ this.arrow = createElementFromDescriptor(arrow);
2564
+ };
2565
+ Tooltip.prototype._setTooltipText = function (selector) {
2566
+ nativeMethods$9.nodeTextContentSetter.call(this.tooltip, selector);
2567
+ };
2568
+ Tooltip.prototype._getTooltipLeft = function (tooltipWidth, targetLeft, viewportWidth, scrollLeft) {
2569
+ if (tooltipWidth >= viewportWidth)
2570
+ return scrollLeft;
2571
+ if (tooltipWidth >= viewportWidth - targetLeft)
2572
+ return viewportWidth + scrollLeft - tooltipWidth;
2573
+ return targetLeft + scrollLeft;
2574
+ };
2575
+ Tooltip.prototype._getArrowLeft = function (arrowWidth, targetLeft, viewportWidth, scrollLeft) {
2576
+ if (arrowWidth + ARROW_OFFSET_LEFT >= viewportWidth - targetLeft)
2577
+ return viewportWidth + scrollLeft - arrowWidth;
2578
+ return targetLeft + scrollLeft + ARROW_OFFSET_LEFT;
2579
+ };
2580
+ Tooltip.prototype._getVerticalPostionStyles = function (tooltipRect, arrowRect, targetRect, viewportRect) {
2581
+ var tooltip = {};
2582
+ var arrow = {};
2583
+ var scrollTop = document.documentElement.scrollTop;
2584
+ var elementsHeight = tooltipRect.height + arrowRect.height;
2585
+ if (targetRect.top >= elementsHeight) {
2586
+ tooltip.top = targetRect.top + scrollTop - elementsHeight + 'px';
2587
+ arrow.top = targetRect.top + scrollTop - arrowRect.height + 'px';
2588
+ arrow.transform = 'none';
2589
+ arrow.visibility = 'visible';
2590
+ }
2591
+ else if (viewportRect.height - targetRect.bottom >= elementsHeight) {
2592
+ tooltip.top = targetRect.bottom + scrollTop + arrowRect.height + 'px';
2593
+ arrow.top = targetRect.bottom + scrollTop + 'px';
2594
+ arrow.transform = 'rotate(180deg)';
2595
+ arrow.visibility = 'visible';
2596
+ }
2597
+ else {
2598
+ tooltip.top = viewportRect.height + scrollTop - tooltipRect.height + 'px';
2599
+ arrow.top = scrollTop + 'px';
2600
+ arrow.transform = 'node';
2601
+ arrow.visibility = 'hidden';
2602
+ }
2603
+ return { tooltip: tooltip, arrow: arrow };
2604
+ };
2605
+ Tooltip.prototype._getElementsStyles = function (target) {
2606
+ var tooltipRect = this.tooltip.getBoundingClientRect();
2607
+ var arrowRect = this.arrow.getBoundingClientRect();
2608
+ var targetRect = target.getBoundingClientRect();
2609
+ var viewportRect = getViewportRect();
2610
+ var styles = this._getVerticalPostionStyles(tooltipRect, arrowRect, targetRect, viewportRect);
2611
+ var scrollLeft = document.documentElement.scrollLeft;
2612
+ styles.tooltip.left = this._getTooltipLeft(tooltipRect.width, targetRect.left, viewportRect.width, scrollLeft) + 'px';
2613
+ styles.arrow.left = this._getArrowLeft(arrowRect.width, targetRect.left, viewportRect.width, scrollLeft) + 'px';
2614
+ return styles;
2615
+ };
2616
+ Tooltip.prototype._placeElements = function (target) {
2617
+ var styles = this._getElementsStyles(target);
2618
+ setStyles(this.tooltip, styles.tooltip);
2619
+ setStyles(this.arrow, styles.arrow);
2620
+ };
2621
+ Tooltip.prototype.show = function (selector, target) {
2622
+ this._setTooltipText(selector);
2623
+ this._placeElements(target);
2624
+ addToUiRoot(this.tooltip);
2625
+ addToUiRoot(this.arrow);
2626
+ };
2627
+ Tooltip.prototype.hide = function () {
2628
+ removeFromUiRoot(this.tooltip);
2629
+ removeFromUiRoot(this.arrow);
2630
+ };
2631
+ return Tooltip;
2632
+ }());
2633
+ var tooltip$1 = new Tooltip();
2634
+
2635
+ var listeners$2 = hammerhead$1__default.eventSandbox.listeners;
2636
+ var styleUtils$9 = testCafeCore__default.styleUtils;
2637
+ var serviceUtils$1 = testCafeCore__default.serviceUtils;
2638
+ var ELEMENT_PICKED = 'element-piked';
2639
+ var ElementPicker = /** @class */ (function (_super) {
2640
+ __extends(ElementPicker, _super);
2641
+ function ElementPicker() {
2642
+ var _this = _super.call(this) || this;
2643
+ _this.hiddenTestCafeElements = new Map();
2644
+ _this.handlers = {
2645
+ onClick: _this._getClickHandler(),
2646
+ onMouseMove: _this._getMouseMoveHandler(),
2647
+ };
2648
+ return _this;
2649
+ }
2650
+ ElementPicker.prototype._hideTestCafeElements = function () {
2651
+ var children = getChildren();
2652
+ for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
2653
+ var element = children_1[_i];
2654
+ var visibilityValue = styleUtils$9.get(element, 'visibility');
2655
+ this.hiddenTestCafeElements.set(element, visibilityValue);
2656
+ styleUtils$9.set(element, 'visibility', 'hidden');
2657
+ }
2658
+ };
2659
+ ElementPicker.prototype._showTestCafeElements = function () {
2660
+ this.hiddenTestCafeElements.forEach(function (visibilityValue, element) {
2661
+ styleUtils$9.set(element, 'visibility', visibilityValue);
2662
+ });
2663
+ this.hiddenTestCafeElements.clear();
2664
+ };
2665
+ ElementPicker.prototype._getClickHandler = function () {
2666
+ var _this = this;
2667
+ return function () {
2668
+ _this._showTestCafeElements();
2669
+ listeners$2.removeInternalEventBeforeListener(window, ['mousemove'], _this.handlers.onMouseMove);
2670
+ listeners$2.removeInternalEventBeforeListener(window, ['click'], _this.handlers.onClick);
2671
+ _this.emit(ELEMENT_PICKED, _this.actualSelectors);
2672
+ tooltip$1.hide();
2673
+ };
2674
+ };
2675
+ ElementPicker.prototype._getMouseMoveHandler = function () {
2676
+ var _this = this;
2677
+ return function (event) {
2678
+ var x = event.clientX;
2679
+ var y = event.clientY;
2680
+ var target = document.elementFromPoint(x, y);
2681
+ if (!target || target === _this.actualTarget)
2682
+ return;
2683
+ _this.actualTarget = target;
2684
+ _this.actualSelectors = selectorGenerator.generate(target);
2685
+ highlighter.stopHighlighting();
2686
+ highlighter.highlight(target);
2687
+ // eslint-disable-next-line no-restricted-properties
2688
+ tooltip$1.show(_this.actualSelectors[0].value, target);
2689
+ };
2690
+ };
2691
+ ElementPicker.prototype.start = function (startEvent) {
2692
+ this._hideTestCafeElements();
2693
+ listeners$2.initElementListening(window, ['mousemove', 'click']);
2694
+ listeners$2.addFirstInternalEventBeforeListener(window, ['mousemove'], this.handlers.onMouseMove);
2695
+ listeners$2.addFirstInternalEventBeforeListener(window, ['click'], this.handlers.onClick);
2696
+ this.handlers.onMouseMove(startEvent);
2697
+ };
2698
+ return ElementPicker;
2699
+ }(serviceUtils$1.EventEmitter));
2700
+ var elementPicker = new ElementPicker();
2701
+
2702
+ var eventUtils$3 = testCafeCore__default.eventUtils;
2703
+ var PickButton = /** @class */ (function () {
2704
+ function PickButton() {
2705
+ this.element = createElementFromDescriptor(pickButton);
2706
+ eventUtils$3.bind(this.element, 'click', function (event) { return elementPicker.start(event); });
2707
+ }
2708
+ return PickButton;
2709
+ }());
2710
+
2711
+ function createCommonjsModule(fn, module) {
2712
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
2713
+ }
2714
+
2715
+ var replicator = createCommonjsModule(function (module) {
2716
+ // Const
2717
+ var TRANSFORMED_TYPE_KEY = '@t';
2718
+ var CIRCULAR_REF_KEY = '@r';
2719
+ var KEY_REQUIRE_ESCAPING_RE = /^#*@(t|r)$/;
2720
+ var GLOBAL = (function getGlobal() {
2721
+ // NOTE: see http://www.ecma-international.org/ecma-262/6.0/index.html#sec-performeval step 10
2722
+ var savedEval = eval;
2723
+ return savedEval('this');
2724
+ })();
2725
+ var TYPED_ARRAY_CTORS = {
2726
+ 'Int8Array': typeof Int8Array === 'function' ? Int8Array : void 0,
2727
+ 'Uint8Array': typeof Uint8Array === 'function' ? Uint8Array : void 0,
2728
+ 'Uint8ClampedArray': typeof Uint8ClampedArray === 'function' ? Uint8ClampedArray : void 0,
2729
+ 'Int16Array': typeof Int16Array === 'function' ? Int16Array : void 0,
2730
+ 'Uint16Array': typeof Uint16Array === 'function' ? Uint16Array : void 0,
2731
+ 'Int32Array': typeof Int32Array === 'function' ? Int32Array : void 0,
2732
+ 'Uint32Array': typeof Uint32Array === 'function' ? Uint32Array : void 0,
2733
+ 'Float32Array': typeof Float32Array === 'function' ? Float32Array : void 0,
2734
+ 'Float64Array': typeof Float64Array === 'function' ? Float64Array : void 0
2735
+ };
2736
+ var ARRAY_BUFFER_SUPPORTED = typeof ArrayBuffer === 'function';
2737
+ var MAP_SUPPORTED = typeof Map === 'function';
2738
+ var SET_SUPPORTED = typeof Set === 'function';
2739
+ var BUFFER_FROM_SUPPORTED = typeof Buffer === 'function';
2740
+ var TYPED_ARRAY_SUPPORTED = function (typeName) {
2741
+ return !!TYPED_ARRAY_CTORS[typeName];
2742
+ };
2743
+ // Saved proto functions
2744
+ var arrSlice = Array.prototype.slice;
2745
+ // Default serializer
2746
+ var JSONSerializer = {
2747
+ serialize: function (val) {
2748
+ return JSON.stringify(val);
2749
+ },
2750
+ deserialize: function (val) {
2751
+ return JSON.parse(val);
2752
+ }
2753
+ };
2754
+ // EncodingTransformer
2755
+ var EncodingTransformer = function (val, transforms) {
2756
+ this.references = val;
2757
+ this.transforms = transforms;
2758
+ this.circularCandidates = [];
2759
+ this.circularCandidatesDescrs = [];
2760
+ this.circularRefCount = 0;
2761
+ };
2762
+ EncodingTransformer._createRefMark = function (idx) {
2763
+ var obj = Object.create(null);
2764
+ obj[CIRCULAR_REF_KEY] = idx;
2765
+ return obj;
2766
+ };
2767
+ EncodingTransformer.prototype._createCircularCandidate = function (val, parent, key) {
2768
+ this.circularCandidates.push(val);
2769
+ this.circularCandidatesDescrs.push({ parent: parent, key: key, refIdx: -1 });
2770
+ };
2771
+ EncodingTransformer.prototype._applyTransform = function (val, parent, key, transform) {
2772
+ var result = Object.create(null);
2773
+ var serializableVal = transform.toSerializable(val);
2774
+ if (typeof serializableVal === 'object')
2775
+ this._createCircularCandidate(val, parent, key);
2776
+ result[TRANSFORMED_TYPE_KEY] = transform.type;
2777
+ result.data = this._handleValue(serializableVal, parent, key);
2778
+ return result;
2779
+ };
2780
+ EncodingTransformer.prototype._handleArray = function (arr) {
2781
+ var result = [];
2782
+ for (var i = 0; i < arr.length; i++)
2783
+ result[i] = this._handleValue(arr[i], result, i);
2784
+ return result;
2785
+ };
2786
+ EncodingTransformer.prototype._handlePlainObject = function (obj) {
2787
+ var replicator = this;
2788
+ var result = Object.create(null);
2789
+ var ownPropertyNames = Object.getOwnPropertyNames(obj);
2790
+ ownPropertyNames.forEach(function (key) {
2791
+ var resultKey = KEY_REQUIRE_ESCAPING_RE.test(key) ? '#' + key : key;
2792
+ result[resultKey] = replicator._handleValue(obj[key], result, resultKey);
2793
+ });
2794
+ return result;
2795
+ };
2796
+ EncodingTransformer.prototype._handleObject = function (obj, parent, key) {
2797
+ this._createCircularCandidate(obj, parent, key);
2798
+ return Array.isArray(obj) ? this._handleArray(obj) : this._handlePlainObject(obj);
2799
+ };
2800
+ EncodingTransformer.prototype._ensureCircularReference = function (obj) {
2801
+ var circularCandidateIdx = this.circularCandidates.indexOf(obj);
2802
+ if (circularCandidateIdx > -1) {
2803
+ var descr = this.circularCandidatesDescrs[circularCandidateIdx];
2804
+ if (descr.refIdx === -1)
2805
+ descr.refIdx = descr.parent ? ++this.circularRefCount : 0;
2806
+ return EncodingTransformer._createRefMark(descr.refIdx);
2807
+ }
2808
+ return null;
2809
+ };
2810
+ EncodingTransformer.prototype._handleValue = function (val, parent, key) {
2811
+ var type = typeof val;
2812
+ var isObject = type === 'object' && val !== null;
2813
+ if (isObject) {
2814
+ var refMark = this._ensureCircularReference(val);
2815
+ if (refMark)
2816
+ return refMark;
2817
+ }
2818
+ for (var i = 0; i < this.transforms.length; i++) {
2819
+ var transform = this.transforms[i];
2820
+ if (transform.shouldTransform(type, val))
2821
+ return this._applyTransform(val, parent, key, transform);
2822
+ }
2823
+ if (isObject)
2824
+ return this._handleObject(val, parent, key);
2825
+ return val;
2826
+ };
2827
+ EncodingTransformer.prototype.transform = function () {
2828
+ var references = [this._handleValue(this.references, null, null)];
2829
+ for (var i = 0; i < this.circularCandidatesDescrs.length; i++) {
2830
+ var descr = this.circularCandidatesDescrs[i];
2831
+ if (descr.refIdx > 0) {
2832
+ references[descr.refIdx] = descr.parent[descr.key];
2833
+ descr.parent[descr.key] = EncodingTransformer._createRefMark(descr.refIdx);
2834
+ }
2835
+ }
2836
+ return references;
2837
+ };
2838
+ // DecodingTransform
2839
+ var DecodingTransformer = function (references, transformsMap) {
2840
+ this.references = references;
2841
+ this.transformMap = transformsMap;
2842
+ this.activeTransformsStack = [];
2843
+ this.visitedRefs = Object.create(null);
2844
+ };
2845
+ DecodingTransformer.prototype._handlePlainObject = function (obj) {
2846
+ var replicator = this;
2847
+ var unescaped = Object.create(null);
2848
+ var ownPropertyNames = Object.getOwnPropertyNames(obj);
2849
+ ownPropertyNames.forEach(function (key) {
2850
+ replicator._handleValue(obj[key], obj, key);
2851
+ if (KEY_REQUIRE_ESCAPING_RE.test(key)) {
2852
+ // NOTE: use intermediate object to avoid unescaped and escaped keys interference
2853
+ // E.g. unescaped "##@t" will be "#@t" which can overwrite escaped "#@t".
2854
+ unescaped[key.substring(1)] = obj[key];
2855
+ delete obj[key];
2856
+ }
2857
+ });
2858
+ for (var unsecapedKey in unescaped)
2859
+ obj[unsecapedKey] = unescaped[unsecapedKey];
2860
+ };
2861
+ DecodingTransformer.prototype._handleTransformedObject = function (obj, parent, key) {
2862
+ var transformType = obj[TRANSFORMED_TYPE_KEY];
2863
+ var transform = this.transformMap[transformType];
2864
+ if (!transform)
2865
+ throw new Error('Can\'t find transform for "' + transformType + '" type.');
2866
+ this.activeTransformsStack.push(obj);
2867
+ this._handleValue(obj.data, obj, 'data');
2868
+ this.activeTransformsStack.pop();
2869
+ parent[key] = transform.fromSerializable(obj.data);
2870
+ };
2871
+ DecodingTransformer.prototype._handleCircularSelfRefDuringTransform = function (refIdx, parent, key) {
2872
+ // NOTE: we've hit a hard case: object reference itself during transformation.
2873
+ // We can't dereference it since we don't have resulting object yet. And we'll
2874
+ // not be able to restore reference lately because we will need to traverse
2875
+ // transformed object again and reference might be unreachable or new object contain
2876
+ // new circular references. As a workaround we create getter, so once transformation
2877
+ // complete, dereferenced property will point to correct transformed object.
2878
+ var references = this.references;
2879
+ var val = void 0;
2880
+ Object.defineProperty(parent, key, {
2881
+ configurable: true,
2882
+ enumerable: true,
2883
+ get: function () {
2884
+ if (val === void 0)
2885
+ val = references[refIdx];
2886
+ return val;
2887
+ },
2888
+ set: function (value) {
2889
+ val = value;
2890
+ return val;
2891
+ }
2892
+ });
2893
+ };
2894
+ DecodingTransformer.prototype._handleCircularRef = function (refIdx, parent, key) {
2895
+ if (this.activeTransformsStack.indexOf(this.references[refIdx]) > -1)
2896
+ this._handleCircularSelfRefDuringTransform(refIdx, parent, key);
2897
+ else {
2898
+ if (!this.visitedRefs[refIdx]) {
2899
+ this.visitedRefs[refIdx] = true;
2900
+ this._handleValue(this.references[refIdx], this.references, refIdx);
2901
+ }
2902
+ parent[key] = this.references[refIdx];
2903
+ }
2904
+ };
2905
+ DecodingTransformer.prototype._handleValue = function (val, parent, key) {
2906
+ if (typeof val !== 'object' || val === null)
2907
+ return;
2908
+ var refIdx = val[CIRCULAR_REF_KEY];
2909
+ if (refIdx !== void 0)
2910
+ this._handleCircularRef(refIdx, parent, key);
2911
+ else if (val[TRANSFORMED_TYPE_KEY])
2912
+ this._handleTransformedObject(val, parent, key);
2913
+ else if (Array.isArray(val)) {
2914
+ for (var i = 0; i < val.length; i++)
2915
+ this._handleValue(val[i], val, i);
2916
+ }
2917
+ else
2918
+ this._handlePlainObject(val);
2919
+ };
2920
+ DecodingTransformer.prototype.transform = function () {
2921
+ this.visitedRefs[0] = true;
2922
+ this._handleValue(this.references[0], this.references, 0);
2923
+ return this.references[0];
2924
+ };
2925
+ // Transforms
2926
+ var builtInTransforms = [
2927
+ {
2928
+ type: '[[NaN]]',
2929
+ shouldTransform: function (type, val) {
2930
+ return type === 'number' && isNaN(val);
2931
+ },
2932
+ toSerializable: function () {
2933
+ return '';
2934
+ },
2935
+ fromSerializable: function () {
2936
+ return NaN;
2937
+ }
2938
+ },
2939
+ {
2940
+ type: '[[undefined]]',
2941
+ shouldTransform: function (type) {
2942
+ return type === 'undefined';
2943
+ },
2944
+ toSerializable: function () {
2945
+ return '';
2946
+ },
2947
+ fromSerializable: function () {
2948
+ return void 0;
2949
+ }
2950
+ },
2951
+ {
2952
+ type: '[[Date]]',
2953
+ shouldTransform: function (type, val) {
2954
+ return val instanceof Date;
2955
+ },
2956
+ toSerializable: function (date) {
2957
+ return date.getTime();
2958
+ },
2959
+ fromSerializable: function (val) {
2960
+ var date = new Date();
2961
+ date.setTime(val);
2962
+ return date;
2963
+ }
2964
+ },
2965
+ {
2966
+ type: '[[RegExp]]',
2967
+ shouldTransform: function (type, val) {
2968
+ return val instanceof RegExp;
2969
+ },
2970
+ toSerializable: function (re) {
2971
+ var result = {
2972
+ src: re.source,
2973
+ flags: ''
2974
+ };
2975
+ if (re.global)
2976
+ result.flags += 'g';
2977
+ if (re.ignoreCase)
2978
+ result.flags += 'i';
2979
+ if (re.multiline)
2980
+ result.flags += 'm';
2981
+ return result;
2982
+ },
2983
+ fromSerializable: function (val) {
2984
+ return new RegExp(val.src, val.flags);
2985
+ }
2986
+ },
2987
+ {
2988
+ type: '[[Error]]',
2989
+ shouldTransform: function (type, val) {
2990
+ return val instanceof Error;
2991
+ },
2992
+ toSerializable: function (err) {
2993
+ return {
2994
+ name: err.name,
2995
+ message: err.message,
2996
+ stack: err.stack
2997
+ };
2998
+ },
2999
+ fromSerializable: function (val) {
3000
+ var Ctor = GLOBAL[val.name] || Error;
3001
+ var err = new Ctor(val.message);
3002
+ err.stack = val.stack;
3003
+ return err;
3004
+ }
3005
+ },
3006
+ {
3007
+ type: '[[ArrayBuffer]]',
3008
+ shouldTransform: function (type, val) {
3009
+ return ARRAY_BUFFER_SUPPORTED && val instanceof ArrayBuffer;
3010
+ },
3011
+ toSerializable: function (buffer) {
3012
+ var view = new Int8Array(buffer);
3013
+ return arrSlice.call(view);
3014
+ },
3015
+ fromSerializable: function (val) {
3016
+ if (ARRAY_BUFFER_SUPPORTED) {
3017
+ var buffer = new ArrayBuffer(val.length);
3018
+ var view = new Int8Array(buffer);
3019
+ view.set(val);
3020
+ return buffer;
3021
+ }
3022
+ return val;
3023
+ }
3024
+ },
3025
+ {
3026
+ type: '[[Buffer]]',
3027
+ shouldTransform: function (type, val) {
3028
+ return BUFFER_FROM_SUPPORTED && val instanceof Buffer;
3029
+ },
3030
+ toSerializable: function (buffer) {
3031
+ return arrSlice.call(buffer);
3032
+ },
3033
+ fromSerializable: function (val) {
3034
+ if (BUFFER_FROM_SUPPORTED)
3035
+ return Buffer.from(val);
3036
+ return val;
3037
+ }
3038
+ },
3039
+ {
3040
+ type: '[[TypedArray]]',
3041
+ shouldTransform: function (type, val) {
3042
+ return Object.keys(TYPED_ARRAY_CTORS).some(function (ctorName) {
3043
+ return TYPED_ARRAY_SUPPORTED(ctorName) && val instanceof TYPED_ARRAY_CTORS[ctorName];
3044
+ });
3045
+ },
3046
+ toSerializable: function (arr) {
3047
+ return {
3048
+ ctorName: arr.constructor.name,
3049
+ arr: arrSlice.call(arr)
3050
+ };
3051
+ },
3052
+ fromSerializable: function (val) {
3053
+ return TYPED_ARRAY_SUPPORTED(val.ctorName) ? new TYPED_ARRAY_CTORS[val.ctorName](val.arr) : val.arr;
3054
+ }
3055
+ },
3056
+ {
3057
+ type: '[[Map]]',
3058
+ shouldTransform: function (type, val) {
3059
+ return MAP_SUPPORTED && val instanceof Map;
3060
+ },
3061
+ toSerializable: function (map) {
3062
+ var flattenedKVArr = [];
3063
+ map.forEach(function (val, key) {
3064
+ flattenedKVArr.push(key);
3065
+ flattenedKVArr.push(val);
3066
+ });
3067
+ return flattenedKVArr;
3068
+ },
3069
+ fromSerializable: function (val) {
3070
+ if (MAP_SUPPORTED) {
3071
+ // NOTE: new Map(iterable) is not supported by all browsers
3072
+ var map = new Map();
3073
+ for (var i = 0; i < val.length; i += 2)
3074
+ map.set(val[i], val[i + 1]);
3075
+ return map;
3076
+ }
3077
+ var kvArr = [];
3078
+ for (var j = 0; j < val.length; j += 2)
3079
+ kvArr.push([val[i], val[i + 1]]);
3080
+ return kvArr;
3081
+ }
3082
+ },
3083
+ {
3084
+ type: '[[Set]]',
3085
+ shouldTransform: function (type, val) {
3086
+ return SET_SUPPORTED && val instanceof Set;
3087
+ },
3088
+ toSerializable: function (set) {
3089
+ var arr = [];
3090
+ set.forEach(function (val) {
3091
+ arr.push(val);
3092
+ });
3093
+ return arr;
3094
+ },
3095
+ fromSerializable: function (val) {
3096
+ if (SET_SUPPORTED) {
3097
+ // NOTE: new Set(iterable) is not supported by all browsers
3098
+ var set = new Set();
3099
+ for (var i = 0; i < val.length; i++)
3100
+ set.add(val[i]);
3101
+ return set;
3102
+ }
3103
+ return val;
3104
+ }
3105
+ }
3106
+ ];
3107
+ // Replicator
3108
+ var Replicator = module.exports = function (serializer) {
3109
+ this.transforms = [];
3110
+ this.transformsMap = Object.create(null);
3111
+ this.serializer = serializer || JSONSerializer;
3112
+ this.addTransforms(builtInTransforms);
3113
+ };
3114
+ // Manage transforms
3115
+ Replicator.prototype.addTransforms = function (transforms) {
3116
+ transforms = Array.isArray(transforms) ? transforms : [transforms];
3117
+ for (var i = 0; i < transforms.length; i++) {
3118
+ var transform = transforms[i];
3119
+ if (this.transformsMap[transform.type])
3120
+ throw new Error('Transform with type "' + transform.type + '" was already added.');
3121
+ this.transforms.push(transform);
3122
+ this.transformsMap[transform.type] = transform;
3123
+ }
3124
+ return this;
3125
+ };
3126
+ Replicator.prototype.removeTransforms = function (transforms) {
3127
+ transforms = Array.isArray(transforms) ? transforms : [transforms];
3128
+ for (var i = 0; i < transforms.length; i++) {
3129
+ var transform = transforms[i];
3130
+ var idx = this.transforms.indexOf(transform);
3131
+ if (idx > -1)
3132
+ this.transforms.splice(idx, 1);
3133
+ delete this.transformsMap[transform.type];
3134
+ }
3135
+ return this;
3136
+ };
3137
+ Replicator.prototype.encode = function (val) {
3138
+ var transformer = new EncodingTransformer(val, this.transforms);
3139
+ var references = transformer.transform();
3140
+ return this.serializer.serialize(references);
3141
+ };
3142
+ Replicator.prototype.decode = function (val) {
3143
+ var references = this.serializer.deserialize(val);
3144
+ var transformer = new DecodingTransformer(references, this.transformsMap);
3145
+ return transformer.transform();
3146
+ };
3147
+ });
3148
+
3149
+ var identity = function (val) { return val; };
3150
+ function createReplicator(transforms) {
3151
+ // NOTE: we will serialize replicator results
3152
+ // to JSON with a command or command result.
3153
+ // Therefore there is no need to do additional job here,
3154
+ // so we use identity functions for serialization.
3155
+ var replicator$1 = new replicator({
3156
+ serialize: identity,
3157
+ deserialize: identity,
3158
+ });
3159
+ return replicator$1.addTransforms(transforms);
3160
+ }
3161
+
3162
+ // -------------------------------------------------------------
3163
+ // WARNING: this file is used by both the client and the server.
3164
+ // Do not use any browser or node-specific API!
3165
+ // -------------------------------------------------------------
3166
+ var TEST_RUN_ERRORS = {
3167
+ uncaughtErrorOnPage: 'E1',
3168
+ uncaughtErrorInTestCode: 'E2',
3169
+ uncaughtNonErrorObjectInTestCode: 'E3',
3170
+ uncaughtErrorInClientFunctionCode: 'E4',
3171
+ uncaughtErrorInCustomDOMPropertyCode: 'E5',
3172
+ unhandledPromiseRejection: 'E6',
3173
+ uncaughtException: 'E7',
3174
+ missingAwaitError: 'E8',
3175
+ actionIntegerOptionError: 'E9',
3176
+ actionPositiveIntegerOptionError: 'E10',
3177
+ actionBooleanOptionError: 'E11',
3178
+ actionSpeedOptionError: 'E12',
3179
+ actionOptionsTypeError: 'E14',
3180
+ actionBooleanArgumentError: 'E15',
3181
+ actionStringArgumentError: 'E16',
3182
+ actionNullableStringArgumentError: 'E17',
3183
+ actionStringOrStringArrayArgumentError: 'E18',
3184
+ actionStringArrayElementError: 'E19',
3185
+ actionIntegerArgumentError: 'E20',
3186
+ actionRoleArgumentError: 'E21',
3187
+ actionPositiveIntegerArgumentError: 'E22',
3188
+ actionSelectorError: 'E23',
3189
+ actionElementNotFoundError: 'E24',
3190
+ actionElementIsInvisibleError: 'E26',
3191
+ actionSelectorMatchesWrongNodeTypeError: 'E27',
3192
+ actionAdditionalElementNotFoundError: 'E28',
3193
+ actionAdditionalElementIsInvisibleError: 'E29',
3194
+ actionAdditionalSelectorMatchesWrongNodeTypeError: 'E30',
3195
+ actionElementNonEditableError: 'E31',
3196
+ actionElementNotTextAreaError: 'E32',
3197
+ actionElementNonContentEditableError: 'E33',
3198
+ actionElementIsNotFileInputError: 'E34',
3199
+ actionRootContainerNotFoundError: 'E35',
3200
+ actionIncorrectKeysError: 'E36',
3201
+ actionCannotFindFileToUploadError: 'E37',
3202
+ actionUnsupportedDeviceTypeError: 'E38',
3203
+ actionIframeIsNotLoadedError: 'E39',
3204
+ actionElementNotIframeError: 'E40',
3205
+ actionInvalidScrollTargetError: 'E41',
3206
+ currentIframeIsNotLoadedError: 'E42',
3207
+ currentIframeNotFoundError: 'E43',
3208
+ currentIframeIsInvisibleError: 'E44',
3209
+ nativeDialogNotHandledError: 'E45',
3210
+ uncaughtErrorInNativeDialogHandler: 'E46',
3211
+ setTestSpeedArgumentError: 'E47',
3212
+ setNativeDialogHandlerCodeWrongTypeError: 'E48',
3213
+ clientFunctionExecutionInterruptionError: 'E49',
3214
+ domNodeClientFunctionResultError: 'E50',
3215
+ invalidSelectorResultError: 'E51',
3216
+ cannotObtainInfoForElementSpecifiedBySelectorError: 'E52',
3217
+ externalAssertionLibraryError: 'E53',
3218
+ pageLoadError: 'E54',
3219
+ windowDimensionsOverflowError: 'E55',
3220
+ forbiddenCharactersInScreenshotPathError: 'E56',
3221
+ invalidElementScreenshotDimensionsError: 'E57',
3222
+ roleSwitchInRoleInitializerError: 'E58',
3223
+ assertionExecutableArgumentError: 'E59',
3224
+ assertionWithoutMethodCallError: 'E60',
3225
+ assertionUnawaitedPromiseError: 'E61',
3226
+ requestHookNotImplementedError: 'E62',
3227
+ requestHookUnhandledError: 'E63',
3228
+ uncaughtErrorInCustomClientScriptCode: 'E64',
3229
+ uncaughtErrorInCustomClientScriptCodeLoadedFromModule: 'E65',
3230
+ uncaughtErrorInCustomScript: 'E66',
3231
+ uncaughtTestCafeErrorInCustomScript: 'E67',
3232
+ childWindowIsNotLoadedError: 'E68',
3233
+ childWindowNotFoundError: 'E69',
3234
+ cannotSwitchToWindowError: 'E70',
3235
+ closeChildWindowError: 'E71',
3236
+ childWindowClosedBeforeSwitchingError: 'E72',
3237
+ cannotCloseWindowWithChildrenError: 'E73',
3238
+ targetWindowNotFoundError: 'E74',
3239
+ parentWindowNotFoundError: 'E76',
3240
+ previousWindowNotFoundError: 'E77',
3241
+ switchToWindowPredicateError: 'E78',
3242
+ actionFunctionArgumentError: 'E79',
3243
+ multipleWindowsModeIsDisabledError: 'E80',
3244
+ multipleWindowsModeIsNotSupportedInRemoteBrowserError: 'E81',
3245
+ cannotCloseWindowWithoutParent: 'E82',
3246
+ cannotRestoreChildWindowError: 'E83',
3247
+ executionTimeoutExceeded: 'E84',
3248
+ actionRequiredCookieArguments: 'E85',
3249
+ actionCookieArgumentError: 'E86',
3250
+ actionCookieArgumentsError: 'E87',
3251
+ actionUrlCookieArgumentError: 'E88',
3252
+ actionUrlsCookieArgumentError: 'E89',
3253
+ actionStringOptionError: 'E90',
3254
+ actionDateOptionError: 'E91',
3255
+ actionNumberOptionError: 'E92',
3256
+ actionUrlOptionError: 'E93',
3257
+ actionUrlSearchParamsOptionError: 'E94',
3258
+ actionObjectOptionError: 'E95',
3259
+ actionUrlArgumentError: 'E96',
3260
+ actionStringOrRegexOptionError: 'E97',
3261
+ actionSkipJsErrorsArgumentError: 'E98',
3262
+ actionFunctionOptionError: 'E99',
3263
+ actionInvalidObjectPropertyError: 'E100',
3264
+ actionElementIsNotTargetError: 'E101',
3265
+ };
3266
+
3267
+ // Base
3268
+ //--------------------------------------------------------------------
3269
+ var TestRunErrorBase = /** @class */ (function () {
3270
+ function TestRunErrorBase(code, callsite) {
3271
+ this.code = code;
3272
+ this.isTestCafeError = true;
3273
+ this.callsite = callsite || null;
3274
+ }
3275
+ return TestRunErrorBase;
3276
+ }());
3277
+ var ActionOptionErrorBase = /** @class */ (function (_super) {
3278
+ __extends(ActionOptionErrorBase, _super);
3279
+ function ActionOptionErrorBase(code, optionName, actualValue) {
3280
+ var _this = _super.call(this, code) || this;
3281
+ _this.optionName = optionName;
3282
+ _this.actualValue = actualValue;
3283
+ return _this;
3284
+ }
3285
+ return ActionOptionErrorBase;
3286
+ }(TestRunErrorBase));
3287
+ // Client function errors
3288
+ //--------------------------------------------------------------------
3289
+ var ClientFunctionExecutionInterruptionError = /** @class */ (function (_super) {
3290
+ __extends(ClientFunctionExecutionInterruptionError, _super);
3291
+ function ClientFunctionExecutionInterruptionError(instantiationCallsiteName, callsite) {
3292
+ var _this = _super.call(this, TEST_RUN_ERRORS.clientFunctionExecutionInterruptionError, callsite) || this;
3293
+ _this.instantiationCallsiteName = instantiationCallsiteName;
3294
+ return _this;
3295
+ }
3296
+ return ClientFunctionExecutionInterruptionError;
3297
+ }(TestRunErrorBase));
3298
+ var DomNodeClientFunctionResultError = /** @class */ (function (_super) {
3299
+ __extends(DomNodeClientFunctionResultError, _super);
3300
+ function DomNodeClientFunctionResultError(instantiationCallsiteName, callsite) {
3301
+ var _this = _super.call(this, TEST_RUN_ERRORS.domNodeClientFunctionResultError, callsite) || this;
3302
+ _this.instantiationCallsiteName = instantiationCallsiteName;
3303
+ return _this;
3304
+ }
3305
+ return DomNodeClientFunctionResultError;
3306
+ }(TestRunErrorBase));
3307
+ // Selector errors
3308
+ //--------------------------------------------------------------------
3309
+ var SelectorErrorBase = /** @class */ (function (_super) {
3310
+ __extends(SelectorErrorBase, _super);
3311
+ function SelectorErrorBase(code, _a, callsite) {
3312
+ var _b = _a === void 0 ? {} : _a, apiFnChain = _b.apiFnChain, apiFnIndex = _b.apiFnIndex, reason = _b.reason;
3313
+ var _this = _super.call(this, code, callsite) || this;
3314
+ _this.apiFnChain = apiFnChain;
3315
+ _this.apiFnIndex = apiFnIndex;
3316
+ _this.reason = reason;
3317
+ return _this;
3318
+ }
3319
+ return SelectorErrorBase;
3320
+ }(TestRunErrorBase));
3321
+ var InvalidSelectorResultError = /** @class */ (function (_super) {
3322
+ __extends(InvalidSelectorResultError, _super);
3323
+ function InvalidSelectorResultError(callsite) {
3324
+ return _super.call(this, TEST_RUN_ERRORS.invalidSelectorResultError, callsite) || this;
3325
+ }
3326
+ return InvalidSelectorResultError;
3327
+ }(TestRunErrorBase));
3328
+ var CannotObtainInfoForElementSpecifiedBySelectorError = /** @class */ (function (_super) {
3329
+ __extends(CannotObtainInfoForElementSpecifiedBySelectorError, _super);
3330
+ function CannotObtainInfoForElementSpecifiedBySelectorError(callsite, apiFnArgs) {
3331
+ return _super.call(this, TEST_RUN_ERRORS.cannotObtainInfoForElementSpecifiedBySelectorError, apiFnArgs, callsite) || this;
3332
+ }
3333
+ return CannotObtainInfoForElementSpecifiedBySelectorError;
3334
+ }(SelectorErrorBase));
3335
+ // Uncaught errors
3336
+ //--------------------------------------------------------------------
3337
+ var UncaughtErrorOnPage = /** @class */ (function (_super) {
3338
+ __extends(UncaughtErrorOnPage, _super);
3339
+ function UncaughtErrorOnPage(errStack, pageDestUrl) {
3340
+ var _this = _super.call(this, TEST_RUN_ERRORS.uncaughtErrorOnPage) || this;
3341
+ _this.errStack = errStack;
3342
+ _this.pageDestUrl = pageDestUrl;
3343
+ return _this;
3344
+ }
3345
+ return UncaughtErrorOnPage;
3346
+ }(TestRunErrorBase));
3347
+ var UncaughtErrorInClientFunctionCode = /** @class */ (function (_super) {
3348
+ __extends(UncaughtErrorInClientFunctionCode, _super);
3349
+ function UncaughtErrorInClientFunctionCode(instantiationCallsiteName, err, callsite) {
3350
+ var _this = _super.call(this, TEST_RUN_ERRORS.uncaughtErrorInClientFunctionCode, callsite) || this;
3351
+ _this.errMsg = String(err);
3352
+ _this.instantiationCallsiteName = instantiationCallsiteName;
3353
+ return _this;
3354
+ }
3355
+ return UncaughtErrorInClientFunctionCode;
3356
+ }(TestRunErrorBase));
3357
+ var UncaughtErrorInCustomDOMPropertyCode = /** @class */ (function (_super) {
3358
+ __extends(UncaughtErrorInCustomDOMPropertyCode, _super);
3359
+ function UncaughtErrorInCustomDOMPropertyCode(instantiationCallsiteName, err, prop, callsite) {
3360
+ var _this = _super.call(this, TEST_RUN_ERRORS.uncaughtErrorInCustomDOMPropertyCode, callsite) || this;
3361
+ _this.errMsg = String(err);
3362
+ _this.property = prop;
3363
+ _this.instantiationCallsiteName = instantiationCallsiteName;
3364
+ return _this;
3365
+ }
3366
+ return UncaughtErrorInCustomDOMPropertyCode;
3367
+ }(TestRunErrorBase));
3368
+ var UncaughtErrorInCustomClientScriptCode = /** @class */ (function (_super) {
3369
+ __extends(UncaughtErrorInCustomClientScriptCode, _super);
3370
+ function UncaughtErrorInCustomClientScriptCode(err) {
3371
+ var _this = _super.call(this, TEST_RUN_ERRORS.uncaughtErrorInCustomClientScriptCode) || this;
3372
+ _this.errMsg = String(err);
3373
+ return _this;
3374
+ }
3375
+ return UncaughtErrorInCustomClientScriptCode;
3376
+ }(TestRunErrorBase));
3377
+ var UncaughtErrorInCustomClientScriptLoadedFromModule = /** @class */ (function (_super) {
3378
+ __extends(UncaughtErrorInCustomClientScriptLoadedFromModule, _super);
3379
+ function UncaughtErrorInCustomClientScriptLoadedFromModule(err, moduleName) {
3380
+ var _this = _super.call(this, TEST_RUN_ERRORS.uncaughtErrorInCustomClientScriptCodeLoadedFromModule) || this;
3381
+ _this.errMsg = String(err);
3382
+ _this.moduleName = moduleName;
3383
+ return _this;
3384
+ }
3385
+ return UncaughtErrorInCustomClientScriptLoadedFromModule;
3386
+ }(TestRunErrorBase));
3387
+ // Action parameters errors
3388
+ //--------------------------------------------------------------------
3389
+ // Options errors
3390
+ //--------------------------------------------------------------------
3391
+ var ActionIntegerOptionError = /** @class */ (function (_super) {
3392
+ __extends(ActionIntegerOptionError, _super);
3393
+ function ActionIntegerOptionError(optionName, actualValue) {
3394
+ return _super.call(this, TEST_RUN_ERRORS.actionIntegerOptionError, optionName, actualValue) || this;
3395
+ }
3396
+ return ActionIntegerOptionError;
3397
+ }(ActionOptionErrorBase));
3398
+ var ActionPositiveIntegerOptionError = /** @class */ (function (_super) {
3399
+ __extends(ActionPositiveIntegerOptionError, _super);
3400
+ function ActionPositiveIntegerOptionError(optionName, actualValue) {
3401
+ return _super.call(this, TEST_RUN_ERRORS.actionPositiveIntegerOptionError, optionName, actualValue) || this;
3402
+ }
3403
+ return ActionPositiveIntegerOptionError;
3404
+ }(ActionOptionErrorBase));
3405
+ var ActionBooleanOptionError = /** @class */ (function (_super) {
3406
+ __extends(ActionBooleanOptionError, _super);
3407
+ function ActionBooleanOptionError(optionName, actualValue) {
3408
+ return _super.call(this, TEST_RUN_ERRORS.actionBooleanOptionError, optionName, actualValue) || this;
3409
+ }
3410
+ return ActionBooleanOptionError;
3411
+ }(ActionOptionErrorBase));
3412
+ var ActionSpeedOptionError = /** @class */ (function (_super) {
3413
+ __extends(ActionSpeedOptionError, _super);
3414
+ function ActionSpeedOptionError(optionName, actualValue) {
3415
+ return _super.call(this, TEST_RUN_ERRORS.actionSpeedOptionError, optionName, actualValue) || this;
3416
+ }
3417
+ return ActionSpeedOptionError;
3418
+ }(ActionOptionErrorBase));
3419
+ var ActionStringOptionError = /** @class */ (function (_super) {
3420
+ __extends(ActionStringOptionError, _super);
3421
+ function ActionStringOptionError(optionName, actualValue) {
3422
+ return _super.call(this, TEST_RUN_ERRORS.actionStringOptionError, optionName, actualValue) || this;
3423
+ }
3424
+ return ActionStringOptionError;
3425
+ }(ActionOptionErrorBase));
3426
+ var ActionStringOrRegexOptionError = /** @class */ (function (_super) {
3427
+ __extends(ActionStringOrRegexOptionError, _super);
3428
+ function ActionStringOrRegexOptionError(optionName, actualValue) {
3429
+ return _super.call(this, TEST_RUN_ERRORS.actionStringOrRegexOptionError, optionName, actualValue) || this;
3430
+ }
3431
+ return ActionStringOrRegexOptionError;
3432
+ }(ActionOptionErrorBase));
3433
+ var ActionDateOptionError = /** @class */ (function (_super) {
3434
+ __extends(ActionDateOptionError, _super);
3435
+ function ActionDateOptionError(optionName, actualValue) {
3436
+ return _super.call(this, TEST_RUN_ERRORS.actionDateOptionError, optionName, actualValue) || this;
3437
+ }
3438
+ return ActionDateOptionError;
3439
+ }(ActionOptionErrorBase));
3440
+ var ActionNumberOptionError = /** @class */ (function (_super) {
3441
+ __extends(ActionNumberOptionError, _super);
3442
+ function ActionNumberOptionError(optionName, actualValue) {
3443
+ return _super.call(this, TEST_RUN_ERRORS.actionNumberOptionError, optionName, actualValue) || this;
3444
+ }
3445
+ return ActionNumberOptionError;
3446
+ }(ActionOptionErrorBase));
3447
+ var ActionUrlOptionError = /** @class */ (function (_super) {
3448
+ __extends(ActionUrlOptionError, _super);
3449
+ function ActionUrlOptionError(optionName, actualValue) {
3450
+ return _super.call(this, TEST_RUN_ERRORS.actionUrlOptionError, optionName, actualValue) || this;
3451
+ }
3452
+ return ActionUrlOptionError;
3453
+ }(ActionOptionErrorBase));
3454
+ var ActionUrlSearchParamsOptionError = /** @class */ (function (_super) {
3455
+ __extends(ActionUrlSearchParamsOptionError, _super);
3456
+ function ActionUrlSearchParamsOptionError(optionName, actualValue) {
3457
+ return _super.call(this, TEST_RUN_ERRORS.actionUrlSearchParamsOptionError, optionName, actualValue) || this;
3458
+ }
3459
+ return ActionUrlSearchParamsOptionError;
3460
+ }(ActionOptionErrorBase));
3461
+ var ActionObjectOptionError = /** @class */ (function (_super) {
3462
+ __extends(ActionObjectOptionError, _super);
3463
+ function ActionObjectOptionError(optionName, actualValue) {
3464
+ return _super.call(this, TEST_RUN_ERRORS.actionObjectOptionError, optionName, actualValue) || this;
3465
+ }
3466
+ return ActionObjectOptionError;
3467
+ }(ActionOptionErrorBase));
3468
+ var ActionFunctionOptionError = /** @class */ (function (_super) {
3469
+ __extends(ActionFunctionOptionError, _super);
3470
+ function ActionFunctionOptionError(optionName, actualValue) {
3471
+ return _super.call(this, TEST_RUN_ERRORS.actionFunctionOptionError, optionName, actualValue) || this;
3472
+ }
3473
+ return ActionFunctionOptionError;
3474
+ }(ActionOptionErrorBase));
3475
+ var ActionInvalidObjectPropertyError = /** @class */ (function (_super) {
3476
+ __extends(ActionInvalidObjectPropertyError, _super);
3477
+ function ActionInvalidObjectPropertyError(objectName, propertyName, availableProperties) {
3478
+ var _this = _super.call(this, TEST_RUN_ERRORS.actionInvalidObjectPropertyError) || this;
3479
+ _this.objectName = objectName;
3480
+ _this.propertyName = propertyName;
3481
+ _this.availableProperties = availableProperties;
3482
+ return _this;
3483
+ }
3484
+ return ActionInvalidObjectPropertyError;
3485
+ }(TestRunErrorBase));
3486
+ // Action execution errors
3487
+ //--------------------------------------------------------------------
3488
+ var ActionElementNotFoundError = /** @class */ (function (_super) {
3489
+ __extends(ActionElementNotFoundError, _super);
3490
+ function ActionElementNotFoundError(callsite, apiFnArgs) {
3491
+ return _super.call(this, TEST_RUN_ERRORS.actionElementNotFoundError, apiFnArgs, callsite) || this;
3492
+ }
3493
+ return ActionElementNotFoundError;
3494
+ }(SelectorErrorBase));
3495
+ var ActionElementIsInvisibleError = /** @class */ (function (_super) {
3496
+ __extends(ActionElementIsInvisibleError, _super);
3497
+ function ActionElementIsInvisibleError(callsite, apiFnArgs) {
3498
+ return _super.call(this, TEST_RUN_ERRORS.actionElementIsInvisibleError, apiFnArgs, callsite) || this;
3499
+ }
3500
+ return ActionElementIsInvisibleError;
3501
+ }(SelectorErrorBase));
3502
+ var ActionSelectorMatchesWrongNodeTypeError = /** @class */ (function (_super) {
3503
+ __extends(ActionSelectorMatchesWrongNodeTypeError, _super);
3504
+ function ActionSelectorMatchesWrongNodeTypeError(nodeDescription) {
3505
+ var _this = _super.call(this, TEST_RUN_ERRORS.actionSelectorMatchesWrongNodeTypeError) || this;
3506
+ _this.nodeDescription = nodeDescription;
3507
+ return _this;
3508
+ }
3509
+ return ActionSelectorMatchesWrongNodeTypeError;
3510
+ }(TestRunErrorBase));
3511
+ var ActionAdditionalElementNotFoundError = /** @class */ (function (_super) {
3512
+ __extends(ActionAdditionalElementNotFoundError, _super);
3513
+ function ActionAdditionalElementNotFoundError(argumentName, apiFnArgs) {
3514
+ var _this = _super.call(this, TEST_RUN_ERRORS.actionAdditionalElementNotFoundError, apiFnArgs) || this;
3515
+ _this.argumentName = argumentName;
3516
+ return _this;
3517
+ }
3518
+ return ActionAdditionalElementNotFoundError;
3519
+ }(SelectorErrorBase));
3520
+ var ActionElementIsNotTargetError = /** @class */ (function (_super) {
3521
+ __extends(ActionElementIsNotTargetError, _super);
3522
+ function ActionElementIsNotTargetError(callsite) {
3523
+ return _super.call(this, TEST_RUN_ERRORS.actionElementIsNotTargetError, callsite) || this;
3524
+ }
3525
+ return ActionElementIsNotTargetError;
3526
+ }(TestRunErrorBase));
3527
+ var ActionAdditionalElementIsInvisibleError = /** @class */ (function (_super) {
3528
+ __extends(ActionAdditionalElementIsInvisibleError, _super);
3529
+ function ActionAdditionalElementIsInvisibleError(argumentName, apiFnArgs) {
3530
+ var _this = _super.call(this, TEST_RUN_ERRORS.actionAdditionalElementIsInvisibleError, apiFnArgs) || this;
3531
+ _this.argumentName = argumentName;
3532
+ return _this;
3533
+ }
3534
+ return ActionAdditionalElementIsInvisibleError;
3535
+ }(SelectorErrorBase));
3536
+ var ActionAdditionalSelectorMatchesWrongNodeTypeError = /** @class */ (function (_super) {
3537
+ __extends(ActionAdditionalSelectorMatchesWrongNodeTypeError, _super);
3538
+ function ActionAdditionalSelectorMatchesWrongNodeTypeError(argumentName, nodeDescription) {
3539
+ var _this = _super.call(this, TEST_RUN_ERRORS.actionAdditionalSelectorMatchesWrongNodeTypeError) || this;
3540
+ _this.argumentName = argumentName;
3541
+ _this.nodeDescription = nodeDescription;
3542
+ return _this;
3543
+ }
3544
+ return ActionAdditionalSelectorMatchesWrongNodeTypeError;
3545
+ }(TestRunErrorBase));
3546
+ var ActionElementNonEditableError = /** @class */ (function (_super) {
3547
+ __extends(ActionElementNonEditableError, _super);
3548
+ function ActionElementNonEditableError() {
3549
+ return _super.call(this, TEST_RUN_ERRORS.actionElementNonEditableError) || this;
3550
+ }
3551
+ return ActionElementNonEditableError;
3552
+ }(TestRunErrorBase));
3553
+ var ActionElementNotTextAreaError = /** @class */ (function (_super) {
3554
+ __extends(ActionElementNotTextAreaError, _super);
3555
+ function ActionElementNotTextAreaError() {
3556
+ return _super.call(this, TEST_RUN_ERRORS.actionElementNotTextAreaError) || this;
3557
+ }
3558
+ return ActionElementNotTextAreaError;
3559
+ }(TestRunErrorBase));
3560
+ var ActionElementNonContentEditableError = /** @class */ (function (_super) {
3561
+ __extends(ActionElementNonContentEditableError, _super);
3562
+ function ActionElementNonContentEditableError(argumentName) {
3563
+ var _this = _super.call(this, TEST_RUN_ERRORS.actionElementNonContentEditableError) || this;
3564
+ _this.argumentName = argumentName;
3565
+ return _this;
3566
+ }
3567
+ return ActionElementNonContentEditableError;
3568
+ }(TestRunErrorBase));
3569
+ var ActionRootContainerNotFoundError = /** @class */ (function (_super) {
3570
+ __extends(ActionRootContainerNotFoundError, _super);
3571
+ function ActionRootContainerNotFoundError() {
3572
+ return _super.call(this, TEST_RUN_ERRORS.actionRootContainerNotFoundError) || this;
3573
+ }
3574
+ return ActionRootContainerNotFoundError;
3575
+ }(TestRunErrorBase));
3576
+ var ActionIncorrectKeysError = /** @class */ (function (_super) {
3577
+ __extends(ActionIncorrectKeysError, _super);
3578
+ function ActionIncorrectKeysError(argumentName) {
3579
+ var _this = _super.call(this, TEST_RUN_ERRORS.actionIncorrectKeysError) || this;
3580
+ _this.argumentName = argumentName;
3581
+ return _this;
3582
+ }
3583
+ return ActionIncorrectKeysError;
3584
+ }(TestRunErrorBase));
3585
+ var ActionCannotFindFileToUploadError = /** @class */ (function (_super) {
3586
+ __extends(ActionCannotFindFileToUploadError, _super);
3587
+ function ActionCannotFindFileToUploadError(filePaths, scannedFilePaths) {
3588
+ var _this = _super.call(this, TEST_RUN_ERRORS.actionCannotFindFileToUploadError) || this;
3589
+ _this.filePaths = filePaths;
3590
+ _this.scannedFilePaths = scannedFilePaths;
3591
+ return _this;
3592
+ }
3593
+ return ActionCannotFindFileToUploadError;
3594
+ }(TestRunErrorBase));
3595
+ var ActionElementIsNotFileInputError = /** @class */ (function (_super) {
3596
+ __extends(ActionElementIsNotFileInputError, _super);
3597
+ function ActionElementIsNotFileInputError() {
3598
+ return _super.call(this, TEST_RUN_ERRORS.actionElementIsNotFileInputError) || this;
3599
+ }
3600
+ return ActionElementIsNotFileInputError;
3601
+ }(TestRunErrorBase));
3602
+ var ActionInvalidScrollTargetError = /** @class */ (function (_super) {
3603
+ __extends(ActionInvalidScrollTargetError, _super);
3604
+ function ActionInvalidScrollTargetError(scrollTargetXValid, scrollTargetYValid) {
3605
+ var _this = _super.call(this, TEST_RUN_ERRORS.actionInvalidScrollTargetError) || this;
3606
+ if (!scrollTargetXValid) {
3607
+ if (!scrollTargetYValid)
3608
+ _this.properties = 'scrollTargetX and scrollTargetY properties';
3609
+ else
3610
+ _this.properties = 'scrollTargetX property';
3611
+ }
3612
+ else
3613
+ _this.properties = 'scrollTargetY property';
3614
+ return _this;
3615
+ }
3616
+ return ActionInvalidScrollTargetError;
3617
+ }(TestRunErrorBase));
3618
+ var InvalidElementScreenshotDimensionsError = /** @class */ (function (_super) {
3619
+ __extends(InvalidElementScreenshotDimensionsError, _super);
3620
+ function InvalidElementScreenshotDimensionsError(width, height) {
3621
+ var _this = _super.call(this, TEST_RUN_ERRORS.invalidElementScreenshotDimensionsError) || this;
3622
+ var widthIsInvalid = width <= 0;
3623
+ var heightIsInvalid = height <= 0;
3624
+ if (widthIsInvalid) {
3625
+ if (heightIsInvalid) {
3626
+ _this.verb = 'are';
3627
+ _this.dimensions = 'width and height';
3628
+ }
3629
+ else {
3630
+ _this.verb = 'is';
3631
+ _this.dimensions = 'width';
3632
+ }
3633
+ }
3634
+ else {
3635
+ _this.verb = 'is';
3636
+ _this.dimensions = 'height';
3637
+ }
3638
+ return _this;
3639
+ }
3640
+ return InvalidElementScreenshotDimensionsError;
3641
+ }(TestRunErrorBase));
3642
+ // Iframe errors
3643
+ //--------------------------------------------------------------------
3644
+ var ActionElementNotIframeError = /** @class */ (function (_super) {
3645
+ __extends(ActionElementNotIframeError, _super);
3646
+ function ActionElementNotIframeError(callsite) {
3647
+ return _super.call(this, TEST_RUN_ERRORS.actionElementNotIframeError, callsite) || this;
3648
+ }
3649
+ return ActionElementNotIframeError;
3650
+ }(TestRunErrorBase));
3651
+ var ActionIframeIsNotLoadedError = /** @class */ (function (_super) {
3652
+ __extends(ActionIframeIsNotLoadedError, _super);
3653
+ function ActionIframeIsNotLoadedError() {
3654
+ return _super.call(this, TEST_RUN_ERRORS.actionIframeIsNotLoadedError) || this;
3655
+ }
3656
+ return ActionIframeIsNotLoadedError;
3657
+ }(TestRunErrorBase));
3658
+ var CurrentIframeIsNotLoadedError = /** @class */ (function (_super) {
3659
+ __extends(CurrentIframeIsNotLoadedError, _super);
3660
+ function CurrentIframeIsNotLoadedError() {
3661
+ return _super.call(this, TEST_RUN_ERRORS.currentIframeIsNotLoadedError) || this;
3662
+ }
3663
+ return CurrentIframeIsNotLoadedError;
3664
+ }(TestRunErrorBase));
3665
+ var ChildWindowNotFoundError = /** @class */ (function (_super) {
3666
+ __extends(ChildWindowNotFoundError, _super);
3667
+ function ChildWindowNotFoundError() {
3668
+ return _super.call(this, TEST_RUN_ERRORS.childWindowNotFoundError) || this;
3669
+ }
3670
+ return ChildWindowNotFoundError;
3671
+ }(TestRunErrorBase));
3672
+ var ChildWindowIsNotLoadedError = /** @class */ (function (_super) {
3673
+ __extends(ChildWindowIsNotLoadedError, _super);
3674
+ function ChildWindowIsNotLoadedError() {
3675
+ return _super.call(this, TEST_RUN_ERRORS.childWindowIsNotLoadedError) || this;
3676
+ }
3677
+ return ChildWindowIsNotLoadedError;
3678
+ }(TestRunErrorBase));
3679
+ var CannotSwitchToWindowError = /** @class */ (function (_super) {
3680
+ __extends(CannotSwitchToWindowError, _super);
3681
+ function CannotSwitchToWindowError() {
3682
+ return _super.call(this, TEST_RUN_ERRORS.cannotSwitchToWindowError) || this;
3683
+ }
3684
+ return CannotSwitchToWindowError;
3685
+ }(TestRunErrorBase));
3686
+ var CloseChildWindowError = /** @class */ (function (_super) {
3687
+ __extends(CloseChildWindowError, _super);
3688
+ function CloseChildWindowError() {
3689
+ return _super.call(this, TEST_RUN_ERRORS.closeChildWindowError) || this;
3690
+ }
3691
+ return CloseChildWindowError;
3692
+ }(TestRunErrorBase));
3693
+ var CannotCloseWindowWithChildrenError = /** @class */ (function (_super) {
3694
+ __extends(CannotCloseWindowWithChildrenError, _super);
3695
+ function CannotCloseWindowWithChildrenError() {
3696
+ return _super.call(this, TEST_RUN_ERRORS.cannotCloseWindowWithChildrenError) || this;
3697
+ }
3698
+ return CannotCloseWindowWithChildrenError;
3699
+ }(TestRunErrorBase));
3700
+ var CannotCloseWindowWithoutParentError = /** @class */ (function (_super) {
3701
+ __extends(CannotCloseWindowWithoutParentError, _super);
3702
+ function CannotCloseWindowWithoutParentError() {
3703
+ return _super.call(this, TEST_RUN_ERRORS.cannotCloseWindowWithoutParent) || this;
3704
+ }
3705
+ return CannotCloseWindowWithoutParentError;
3706
+ }(TestRunErrorBase));
3707
+ var SwitchToWindowPredicateError = /** @class */ (function (_super) {
3708
+ __extends(SwitchToWindowPredicateError, _super);
3709
+ function SwitchToWindowPredicateError(errMsg) {
3710
+ var _this = _super.call(this, TEST_RUN_ERRORS.switchToWindowPredicateError) || this;
3711
+ _this.errMsg = errMsg;
3712
+ return _this;
3713
+ }
3714
+ return SwitchToWindowPredicateError;
3715
+ }(TestRunErrorBase));
3716
+ var WindowNotFoundError = /** @class */ (function (_super) {
3717
+ __extends(WindowNotFoundError, _super);
3718
+ function WindowNotFoundError() {
3719
+ return _super.call(this, TEST_RUN_ERRORS.targetWindowNotFoundError) || this;
3720
+ }
3721
+ return WindowNotFoundError;
3722
+ }(TestRunErrorBase));
3723
+ var ParentWindowNotFoundError = /** @class */ (function (_super) {
3724
+ __extends(ParentWindowNotFoundError, _super);
3725
+ function ParentWindowNotFoundError() {
3726
+ return _super.call(this, TEST_RUN_ERRORS.parentWindowNotFoundError) || this;
3727
+ }
3728
+ return ParentWindowNotFoundError;
3729
+ }(TestRunErrorBase));
3730
+ var PreviousWindowNotFoundError = /** @class */ (function (_super) {
3731
+ __extends(PreviousWindowNotFoundError, _super);
3732
+ function PreviousWindowNotFoundError() {
3733
+ return _super.call(this, TEST_RUN_ERRORS.previousWindowNotFoundError) || this;
3734
+ }
3735
+ return PreviousWindowNotFoundError;
3736
+ }(TestRunErrorBase));
3737
+ var ChildWindowClosedBeforeSwitchingError = /** @class */ (function (_super) {
3738
+ __extends(ChildWindowClosedBeforeSwitchingError, _super);
3739
+ function ChildWindowClosedBeforeSwitchingError() {
3740
+ return _super.call(this, TEST_RUN_ERRORS.childWindowClosedBeforeSwitchingError) || this;
3741
+ }
3742
+ return ChildWindowClosedBeforeSwitchingError;
3743
+ }(TestRunErrorBase));
3744
+ var CannotRestoreChildWindowError = /** @class */ (function (_super) {
3745
+ __extends(CannotRestoreChildWindowError, _super);
3746
+ function CannotRestoreChildWindowError() {
3747
+ return _super.call(this, TEST_RUN_ERRORS.cannotRestoreChildWindowError) || this;
3748
+ }
3749
+ return CannotRestoreChildWindowError;
3750
+ }(TestRunErrorBase));
3751
+ var CurrentIframeNotFoundError = /** @class */ (function (_super) {
3752
+ __extends(CurrentIframeNotFoundError, _super);
3753
+ function CurrentIframeNotFoundError() {
3754
+ return _super.call(this, TEST_RUN_ERRORS.currentIframeNotFoundError) || this;
3755
+ }
3756
+ return CurrentIframeNotFoundError;
3757
+ }(TestRunErrorBase));
3758
+ var CurrentIframeIsInvisibleError = /** @class */ (function (_super) {
3759
+ __extends(CurrentIframeIsInvisibleError, _super);
3760
+ function CurrentIframeIsInvisibleError() {
3761
+ return _super.call(this, TEST_RUN_ERRORS.currentIframeIsInvisibleError) || this;
3762
+ }
3763
+ return CurrentIframeIsInvisibleError;
3764
+ }(TestRunErrorBase));
3765
+ // Native dialog errors
3766
+ //--------------------------------------------------------------------
3767
+ var NativeDialogNotHandledError = /** @class */ (function (_super) {
3768
+ __extends(NativeDialogNotHandledError, _super);
3769
+ function NativeDialogNotHandledError(dialogType, url) {
3770
+ var _this = _super.call(this, TEST_RUN_ERRORS.nativeDialogNotHandledError) || this;
3771
+ _this.dialogType = dialogType;
3772
+ _this.pageUrl = url;
3773
+ return _this;
3774
+ }
3775
+ return NativeDialogNotHandledError;
3776
+ }(TestRunErrorBase));
3777
+ var UncaughtErrorInNativeDialogHandler = /** @class */ (function (_super) {
3778
+ __extends(UncaughtErrorInNativeDialogHandler, _super);
3779
+ function UncaughtErrorInNativeDialogHandler(dialogType, errMsg, url) {
3780
+ var _this = _super.call(this, TEST_RUN_ERRORS.uncaughtErrorInNativeDialogHandler) || this;
3781
+ _this.dialogType = dialogType;
3782
+ _this.errMsg = errMsg;
3783
+ _this.pageUrl = url;
3784
+ return _this;
3785
+ }
3786
+ return UncaughtErrorInNativeDialogHandler;
3787
+ }(TestRunErrorBase));
3788
+
3789
+ // @ts-ignore
3790
+ function isNodeCollection(obj) {
3791
+ return obj instanceof hammerhead$1.nativeMethods.HTMLCollection || obj instanceof hammerhead$1.nativeMethods.NodeList;
3792
+ }
3793
+ function castToArray(list) {
3794
+ var length = list.length;
3795
+ var result = [];
3796
+ for (var i = 0; i < length; i++)
3797
+ result.push(list[i]);
3798
+ return result;
3799
+ }
3800
+ function isArrayOfNodes(obj) {
3801
+ if (!hammerhead$1.nativeMethods.isArray(obj))
3802
+ return false;
3803
+ for (var i = 0; i < obj.length; i++) {
3804
+ // @ts-ignore
3805
+ if (!(obj[i] instanceof hammerhead$1.nativeMethods.Node))
3806
+ return false;
3807
+ }
3808
+ return true;
3809
+ }
3810
+
3811
+ var _a$1;
3812
+ var SELECTOR_FILTER_ERROR = {
3813
+ filterVisible: 1,
3814
+ filterHidden: 2,
3815
+ nth: 3,
3816
+ };
3817
+ var FILTER_ERROR_TO_API_RE = (_a$1 = {},
3818
+ _a$1[SELECTOR_FILTER_ERROR.filterVisible] = /^\.filterVisible\(\)$/,
3819
+ _a$1[SELECTOR_FILTER_ERROR.filterHidden] = /^\.filterHidden\(\)$/,
3820
+ _a$1[SELECTOR_FILTER_ERROR.nth] = /^\.nth\(\d+\)$/,
3821
+ _a$1);
3822
+ var SelectorFilter = /** @class */ (function () {
3823
+ function SelectorFilter() {
3824
+ this._err = null;
3825
+ }
3826
+ Object.defineProperty(SelectorFilter.prototype, "error", {
3827
+ get: function () {
3828
+ return this._err;
3829
+ },
3830
+ set: function (message) {
3831
+ if (this._err === null)
3832
+ this._err = message;
3833
+ },
3834
+ enumerable: false,
3835
+ configurable: true
3836
+ });
3837
+ SelectorFilter.prototype.filter = function (nodes, options, apiInfo) {
3838
+ if (options.filterVisible) {
3839
+ nodes = nodes.filter(testCafeCore.positionUtils.isElementVisible);
3840
+ this._assertFilterError(nodes, apiInfo, SELECTOR_FILTER_ERROR.filterVisible);
3841
+ }
3842
+ if (options.filterHidden) {
3843
+ nodes = nodes.filter(function (n) { return !testCafeCore.positionUtils.isElementVisible(n); });
3844
+ this._assertFilterError(nodes, apiInfo, SELECTOR_FILTER_ERROR.filterHidden);
3845
+ }
3846
+ if (options.counterMode) {
3847
+ if (options.index === null)
3848
+ return nodes.length;
3849
+ return SelectorFilter._getNodeByIndex(nodes, options.index) ? 1 : 0;
3850
+ }
3851
+ if (options.collectionMode) {
3852
+ if (options.index !== null) {
3853
+ var nodeOnIndex_1 = SelectorFilter._getNodeByIndex(nodes, options.index);
3854
+ nodes = nodeOnIndex_1 ? [nodeOnIndex_1] : [];
3855
+ this._assertFilterError(nodes, apiInfo, SELECTOR_FILTER_ERROR.nth);
3856
+ }
3857
+ return nodes;
3858
+ }
3859
+ var nodeOnIndex = SelectorFilter._getNodeByIndex(nodes, options.index || 0);
3860
+ if (!nodeOnIndex)
3861
+ this.error = SelectorFilter._getErrorItem(apiInfo, SELECTOR_FILTER_ERROR.nth);
3862
+ return nodeOnIndex;
3863
+ };
3864
+ SelectorFilter.prototype.cast = function (searchResult) {
3865
+ if (searchResult === null || searchResult === void 0)
3866
+ return [];
3867
+ else if (searchResult instanceof hammerhead$1.nativeMethods.Node)
3868
+ return [searchResult];
3869
+ else if (isArrayOfNodes(searchResult))
3870
+ return searchResult;
3871
+ else if (isNodeCollection(searchResult))
3872
+ return castToArray(searchResult);
3873
+ throw new InvalidSelectorResultError();
3874
+ };
3875
+ SelectorFilter.prototype._assertFilterError = function (filtered, apiInfo, filterError) {
3876
+ if (filtered.length === 0)
3877
+ this.error = SelectorFilter._getErrorItem(apiInfo, filterError);
3878
+ };
3879
+ SelectorFilter._getErrorItem = function (_a, err) {
3880
+ var apiFnChain = _a.apiFnChain, apiFnID = _a.apiFnID;
3881
+ if (err) {
3882
+ for (var i = apiFnID; i < apiFnChain.length; i++) {
3883
+ if (FILTER_ERROR_TO_API_RE[err].test(apiFnChain[i]))
3884
+ return i;
3885
+ }
3886
+ }
3887
+ return null;
3888
+ };
3889
+ SelectorFilter._getNodeByIndex = function (nodes, index) {
3890
+ return index < 0 ? nodes[nodes.length + index] : nodes[index];
3891
+ };
3892
+ return SelectorFilter;
3893
+ }());
3894
+ var selectorFilter = new SelectorFilter();
3895
+
3896
+ // @ts-ignore
3897
+ // NOTE: evalFunction is isolated into a separate module to
3898
+ // restrict access to TestCafe intrinsics for the evaluated code.
3899
+ // It also accepts `__dependencies$` argument which may be used by evaluated code.
3900
+ function evalFunction(fnCode, __dependencies$) {
3901
+ var FunctionCtor = hammerhead$1.nativeMethods.Function;
3902
+ var evaluator = new FunctionCtor('fnCode', '__dependencies$', 'Promise',
3903
+ // NOTE: we should pass the original `RegExp`
3904
+ // to make the `instanceof RegExp` check successful in different contexts
3905
+ 'RegExp',
3906
+ // NOTE: `eval` in strict mode will not override context variables
3907
+ '"use strict"; return eval(fnCode)');
3908
+ return evaluator(fnCode, __dependencies$, hammerhead$1.Promise, RegExp);
3909
+ }
3910
+
3911
+ var FunctionTransform = /** @class */ (function () {
3912
+ function FunctionTransform() {
3913
+ this.type = 'Function';
3914
+ }
3915
+ FunctionTransform.prototype.shouldTransform = function (type) {
3916
+ return type === 'function';
3917
+ };
3918
+ FunctionTransform.prototype.toSerializable = function () {
3919
+ return '';
3920
+ };
3921
+ // HACK: UglifyJS + TypeScript + argument destructuring can generate incorrect code.
3922
+ // So we have to use plain assignments here.
3923
+ FunctionTransform.prototype.fromSerializable = function (opts) {
3924
+ var fnCode = opts.fnCode;
3925
+ var dependencies = opts.dependencies;
3926
+ if ('filterOptions' in dependencies)
3927
+ dependencies.selectorFilter = selectorFilter;
3928
+ return evalFunction(fnCode, dependencies);
3929
+ };
3930
+ return FunctionTransform;
3931
+ }());
3932
+
3933
+ var ClientFunctionNodeTransform = /** @class */ (function () {
3934
+ function ClientFunctionNodeTransform(instantiationCallsiteName) {
3935
+ this.type = 'Node';
3936
+ this._instantiationCallsiteName = instantiationCallsiteName;
3937
+ }
3938
+ ClientFunctionNodeTransform.prototype.shouldTransform = function (type, val) {
3939
+ if (val instanceof hammerhead$1.nativeMethods.Node)
3940
+ throw new DomNodeClientFunctionResultError(this._instantiationCallsiteName);
3941
+ return false;
3942
+ };
3943
+ ClientFunctionNodeTransform.prototype.toSerializable = function () {
3944
+ };
3945
+ ClientFunctionNodeTransform.prototype.fromSerializable = function () {
3946
+ };
3947
+ return ClientFunctionNodeTransform;
3948
+ }());
3949
+
3950
+ var ClientFunctionExecutor = /** @class */ (function () {
3951
+ function ClientFunctionExecutor(command) {
3952
+ this.command = command;
3953
+ this.replicator = this._createReplicator();
3954
+ this.dependencies = this.replicator.decode(command.dependencies);
3955
+ this.fn = evalFunction(command.fnCode, this.dependencies);
3956
+ }
3957
+ ClientFunctionExecutor.prototype.getResult = function () {
3958
+ var _this = this;
3959
+ return hammerhead$1.Promise.resolve()
3960
+ .then(function () {
3961
+ var args = _this.replicator.decode(_this.command.args);
3962
+ return _this._executeFn(args);
3963
+ })
3964
+ .catch(function (err) {
3965
+ if (!err.isTestCafeError)
3966
+ err = new UncaughtErrorInClientFunctionCode(_this.command.instantiationCallsiteName, err);
3967
+ throw err;
3968
+ });
3969
+ };
3970
+ ClientFunctionExecutor.prototype.encodeResult = function (result) {
3971
+ return this.replicator.encode(result);
3972
+ };
3973
+ ClientFunctionExecutor.prototype._createReplicator = function () {
3974
+ return createReplicator([
3975
+ new ClientFunctionNodeTransform(this.command.instantiationCallsiteName),
3976
+ new FunctionTransform(),
3977
+ ]);
3978
+ };
3979
+ ClientFunctionExecutor.prototype._executeFn = function (args) {
3980
+ return this.fn.apply(window, args);
3981
+ };
3982
+ return ClientFunctionExecutor;
3983
+ }());
3984
+
3985
+ // -------------------------------------------------------------
3986
+ // WARNING: this file is used by both the client and the server.
3987
+ // Do not use any browser or node-specific API!
3988
+ // -------------------------------------------------------------
3989
+ var NODE_SNAPSHOT_PROPERTIES = [
3990
+ 'nodeType',
3991
+ 'textContent',
3992
+ 'childNodeCount',
3993
+ 'hasChildNodes',
3994
+ 'childElementCount',
3995
+ 'hasChildElements',
3996
+ ];
3997
+ var ELEMENT_ACTION_SNAPSHOT_PROPERTIES = [
3998
+ 'tagName',
3999
+ 'attributes',
4000
+ ];
4001
+ var ELEMENT_SNAPSHOT_PROPERTIES = [
4002
+ 'tagName',
4003
+ 'visible',
4004
+ 'focused',
4005
+ 'attributes',
4006
+ 'boundingClientRect',
4007
+ 'classNames',
4008
+ 'style',
4009
+ 'innerText',
4010
+ 'namespaceURI',
4011
+ 'id',
4012
+ 'value',
4013
+ 'checked',
4014
+ 'selected',
4015
+ 'selectedIndex',
4016
+ 'scrollWidth',
4017
+ 'scrollHeight',
4018
+ 'scrollLeft',
4019
+ 'scrollTop',
4020
+ 'offsetWidth',
4021
+ 'offsetHeight',
4022
+ 'offsetLeft',
4023
+ 'offsetTop',
4024
+ 'clientWidth',
4025
+ 'clientHeight',
4026
+ 'clientLeft',
4027
+ 'clientTop',
4028
+ ];
4029
+
4030
+ var nodeSnapshotPropertyInitializers = {
4031
+ // eslint-disable-next-line no-restricted-properties
4032
+ childNodeCount: function (node) { return node.childNodes.length; },
4033
+ hasChildNodes: function (node) { return !!nodeSnapshotPropertyInitializers.childNodeCount(node); },
4034
+ childElementCount: function (node) {
4035
+ var children = node.children;
4036
+ if (children)
4037
+ // eslint-disable-next-line no-restricted-properties
4038
+ return children.length;
4039
+ // NOTE: IE doesn't have `children` for non-element nodes =/
4040
+ var childElementCount = 0;
4041
+ // eslint-disable-next-line no-restricted-properties
4042
+ var childNodeCount = node.childNodes.length;
4043
+ for (var i = 0; i < childNodeCount; i++) {
4044
+ // eslint-disable-next-line no-restricted-properties
4045
+ if (node.childNodes[i].nodeType === 1)
4046
+ childElementCount++;
4047
+ }
4048
+ return childElementCount;
4049
+ },
4050
+ // eslint-disable-next-line no-restricted-properties
4051
+ hasChildElements: function (node) { return !!nodeSnapshotPropertyInitializers.childElementCount(node); },
4052
+ };
4053
+ var BaseSnapshot = /** @class */ (function () {
4054
+ function BaseSnapshot() {
4055
+ }
4056
+ BaseSnapshot.prototype._initializeProperties = function (node, properties, initializers) {
4057
+ for (var _i = 0, properties_1 = properties; _i < properties_1.length; _i++) {
4058
+ var property = properties_1[_i];
4059
+ var initializer = initializers[property];
4060
+ this[property] = initializer ? initializer(node) : node[property];
4061
+ }
4062
+ };
4063
+ return BaseSnapshot;
4064
+ }());
4065
+ var NodeSnapshot = /** @class */ (function (_super) {
4066
+ __extends(NodeSnapshot, _super);
4067
+ function NodeSnapshot(node) {
4068
+ var _this = _super.call(this) || this;
4069
+ _this._initializeProperties(node, NODE_SNAPSHOT_PROPERTIES, nodeSnapshotPropertyInitializers);
4070
+ return _this;
4071
+ }
4072
+ return NodeSnapshot;
4073
+ }(BaseSnapshot));
4074
+ // Element
4075
+ var elementSnapshotPropertyInitializers = {
4076
+ tagName: function (element) { return element.tagName.toLowerCase(); },
4077
+ visible: function (element) { return testCafeCore.positionUtils.isElementVisible(element); },
4078
+ focused: function (element) { return hammerhead$1.utils.dom.getActiveElement() === element; },
4079
+ attributes: function (element) {
4080
+ // eslint-disable-next-line no-restricted-properties
4081
+ var attrs = element.attributes;
4082
+ var result = {};
4083
+ for (var i = attrs.length - 1; i >= 0; i--)
4084
+ // eslint-disable-next-line no-restricted-properties
4085
+ result[attrs[i].name] = attrs[i].value;
4086
+ return result;
4087
+ },
4088
+ boundingClientRect: function (element) {
4089
+ var rect = element.getBoundingClientRect();
4090
+ return {
4091
+ left: rect.left,
4092
+ right: rect.right,
4093
+ top: rect.top,
4094
+ bottom: rect.bottom,
4095
+ width: rect.width,
4096
+ height: rect.height,
4097
+ };
4098
+ },
4099
+ classNames: function (element) {
4100
+ var className = element.className;
4101
+ if (typeof className.animVal === 'string')
4102
+ className = className.animVal;
4103
+ return className
4104
+ .replace(/^\s+|\s+$/g, '')
4105
+ .split(/\s+/g);
4106
+ },
4107
+ style: function (element) {
4108
+ var result = {};
4109
+ var computed = window.getComputedStyle(element);
4110
+ for (var i = 0; i < computed.length; i++) {
4111
+ var prop = computed[i];
4112
+ result[prop] = computed[prop];
4113
+ }
4114
+ return result;
4115
+ },
4116
+ // eslint-disable-next-line no-restricted-properties
4117
+ innerText: function (element) { return element.innerText; },
4118
+ };
4119
+ var ElementActionSnapshot = /** @class */ (function (_super) {
4120
+ __extends(ElementActionSnapshot, _super);
4121
+ function ElementActionSnapshot(element) {
4122
+ var _this = _super.call(this) || this;
4123
+ _this._initializeProperties(element, ELEMENT_ACTION_SNAPSHOT_PROPERTIES, elementSnapshotPropertyInitializers);
4124
+ return _this;
4125
+ }
4126
+ return ElementActionSnapshot;
4127
+ }(BaseSnapshot));
4128
+ var ElementSnapshot = /** @class */ (function (_super) {
4129
+ __extends(ElementSnapshot, _super);
4130
+ function ElementSnapshot(element) {
4131
+ var _this = _super.call(this, element) || this;
4132
+ _this._initializeProperties(element, ELEMENT_SNAPSHOT_PROPERTIES, elementSnapshotPropertyInitializers);
4133
+ return _this;
4134
+ }
4135
+ return ElementSnapshot;
4136
+ }(NodeSnapshot));
4137
+
4138
+ var SelectorNodeTransform = /** @class */ (function () {
4139
+ function SelectorNodeTransform(customDOMProperties, instantiationCallsiteName) {
4140
+ if (customDOMProperties === void 0) { customDOMProperties = {}; }
4141
+ this.type = 'Node';
4142
+ this._customDOMProperties = customDOMProperties;
4143
+ this._instantiationCallsiteName = instantiationCallsiteName;
4144
+ }
4145
+ SelectorNodeTransform.prototype._extend = function (snapshot, node) {
4146
+ var props = hammerhead$1.nativeMethods.objectKeys(this._customDOMProperties);
4147
+ for (var _i = 0, props_1 = props; _i < props_1.length; _i++) {
4148
+ var prop = props_1[_i];
4149
+ try {
4150
+ snapshot[prop] = this._customDOMProperties[prop](node);
4151
+ }
4152
+ catch (err) {
4153
+ throw new UncaughtErrorInCustomDOMPropertyCode(this._instantiationCallsiteName, err, prop);
4154
+ }
4155
+ }
4156
+ };
4157
+ SelectorNodeTransform.prototype.shouldTransform = function (type, val) {
4158
+ return val instanceof hammerhead$1.nativeMethods.Node;
4159
+ };
4160
+ SelectorNodeTransform.prototype.toSerializable = function (node) {
4161
+ var snapshot = node.nodeType === 1 ? new ElementSnapshot(node) : new NodeSnapshot(node);
4162
+ this._extend(snapshot, node);
4163
+ return snapshot;
4164
+ };
4165
+ SelectorNodeTransform.prototype.fromSerializable = function () {
4166
+ };
4167
+ return SelectorNodeTransform;
4168
+ }());
4169
+
4170
+ var CHECK_ELEMENT_DELAY = 200;
4171
+
4172
+ var SelectorExecutor = /** @class */ (function (_super) {
4173
+ __extends(SelectorExecutor, _super);
4174
+ function SelectorExecutor(command, globalTimeout, startTime, createNotFoundError, createIsInvisibleError) {
4175
+ var _this = _super.call(this, command) || this;
4176
+ _this.createNotFoundError = createNotFoundError;
4177
+ _this.createIsInvisibleError = createIsInvisibleError;
4178
+ _this.timeout = typeof command.timeout === 'number' ? command.timeout : globalTimeout;
4179
+ _this.counterMode = _this.dependencies.filterOptions.counterMode;
4180
+ _this.getVisibleValueMode = _this.dependencies.filterOptions.getVisibleValueMode;
4181
+ _this.dependencies.selectorFilter = selectorFilter;
4182
+ if (startTime) {
4183
+ var elapsed = hammerhead$1.nativeMethods.dateNow() - startTime;
4184
+ _this.timeout = Math.max(_this.timeout - elapsed, 0);
4185
+ }
4186
+ var customDOMProperties = _this.dependencies.customDOMProperties;
4187
+ _this.replicator.addTransforms([
4188
+ new SelectorNodeTransform(customDOMProperties, command.instantiationCallsiteName),
4189
+ ]);
4190
+ return _this;
4191
+ }
4192
+ SelectorExecutor.prototype._createReplicator = function () {
4193
+ return createReplicator([
4194
+ new FunctionTransform(),
4195
+ ]);
4196
+ };
4197
+ SelectorExecutor.prototype._getTimeoutErrorParams = function (el) {
4198
+ var apiFnIndex = selectorFilter.error;
4199
+ var apiFnChain = this.command.apiFnChain;
4200
+ var reason = testCafeCore.positionUtils.getHiddenReason(el);
4201
+ return { apiFnIndex: apiFnIndex, apiFnChain: apiFnChain, reason: reason };
4202
+ };
4203
+ SelectorExecutor.prototype._getTimeoutError = function (elementExists) {
4204
+ return elementExists ? this.createIsInvisibleError : this.createNotFoundError;
4205
+ };
4206
+ SelectorExecutor.prototype._validateElement = function (args, startTime) {
4207
+ var _this = this;
4208
+ return hammerhead$1.Promise.resolve()
4209
+ .then(function () { return _super.prototype._executeFn.call(_this, args); })
4210
+ .then(function (el) {
4211
+ var element = el;
4212
+ var isElementExists = !!element;
4213
+ var isElementVisible = !_this.command.visibilityCheck || element && testCafeCore.positionUtils.isElementVisible(element);
4214
+ var isTimeout = hammerhead$1.nativeMethods.dateNow() - startTime >= _this.timeout;
4215
+ if (isElementExists && (isElementVisible || hammerhead$1.utils.dom.isShadowRoot(element)))
4216
+ return element;
4217
+ if (!isTimeout)
4218
+ return testCafeCore.delay(CHECK_ELEMENT_DELAY).then(function () { return _this._validateElement(args, startTime); });
4219
+ var createTimeoutError = _this.getVisibleValueMode ? null : _this._getTimeoutError(isElementExists);
4220
+ if (createTimeoutError)
4221
+ throw createTimeoutError(_this._getTimeoutErrorParams(element));
4222
+ return null;
4223
+ });
4224
+ };
4225
+ SelectorExecutor.prototype._executeFn = function (args) {
4226
+ if (this.counterMode)
4227
+ return _super.prototype._executeFn.call(this, args);
4228
+ return this._validateElement(args, hammerhead$1.nativeMethods.dateNow());
4229
+ };
4230
+ return SelectorExecutor;
4231
+ }(ClientFunctionExecutor));
4232
+
4233
+ var INTERNAL_PROPERTIES = {
4234
+ testCafeDriver: '%testCafeDriver%',
4235
+ testCafeIframeDriver: '%testCafeIframeDriver%',
4236
+ testCafeEmbeddingUtils: '%testCafeEmbeddingUtils%',
4237
+ testCafeDriverInstance: '%testCafeDriverInstance%',
4238
+ };
4239
+
4240
+ var GLOBAL_TIMEOUT = 5000;
4241
+ function createNotFoundError() {
4242
+ return null;
4243
+ }
4244
+ function createIsInvisibleError() {
4245
+ return null;
4246
+ }
4247
+ function parseSelector(selector) {
4248
+ return __awaiter(this, void 0, void 0, function () {
4249
+ var communicationUrls;
4250
+ return __generator(this, function (_a) {
4251
+ communicationUrls = window[INTERNAL_PROPERTIES.testCafeDriverInstance].communicationUrls;
4252
+ return [2 /*return*/, testCafeCore.browser.parseSelector(communicationUrls.parseSelector, hammerhead$1.createNativeXHR, selector)];
4253
+ });
4254
+ });
4255
+ }
4256
+ function executeSelector(parsedSelector) {
4257
+ return __awaiter(this, void 0, void 0, function () {
4258
+ var startTime, selectorExecutor, elements;
4259
+ return __generator(this, function (_a) {
4260
+ switch (_a.label) {
4261
+ case 0:
4262
+ startTime = hammerhead$1.nativeMethods.date();
4263
+ selectorExecutor = new SelectorExecutor(parsedSelector, GLOBAL_TIMEOUT, startTime, createNotFoundError, createIsInvisibleError);
4264
+ return [4 /*yield*/, selectorExecutor.getResult()];
4265
+ case 1:
4266
+ elements = _a.sent();
4267
+ return [2 /*return*/, elements];
4268
+ }
4269
+ });
4270
+ });
4271
+ }
4272
+ function getElementsBySelector(selector) {
4273
+ return __awaiter(this, void 0, void 0, function () {
4274
+ var parsedSelector;
4275
+ return __generator(this, function (_a) {
4276
+ switch (_a.label) {
4277
+ case 0: return [4 /*yield*/, parseSelector(selector)];
4278
+ case 1:
4279
+ parsedSelector = _a.sent();
4280
+ return [2 /*return*/, executeSelector(parsedSelector).catch(function () { return null; })];
4281
+ }
4282
+ });
4283
+ });
4284
+ }
4285
+
4286
+ var listeners$3 = hammerhead$1__default.eventSandbox.listeners;
4287
+ var serviceUtils$2 = testCafeCore__default.serviceUtils;
4288
+ var LIST_CHANGED = 'list-changed';
4289
+ var SELECTOR_SELECTED = 'selector-selected';
4290
+ var SelectorsList = /** @class */ (function (_super) {
4291
+ __extends(SelectorsList, _super);
4292
+ function SelectorsList() {
4293
+ var _this = _super.call(this) || this;
4294
+ _this._pickedSelectors = [];
4295
+ _this.element = createElementFromDescriptor(selectorsList);
4296
+ elementPicker.on(ELEMENT_PICKED, function (selectors) {
4297
+ _this.pickedSelectors = selectors;
4298
+ });
4299
+ return _this;
4300
+ }
4301
+ Object.defineProperty(SelectorsList.prototype, "pickedSelectors", {
4302
+ get: function () {
4303
+ return this._pickedSelectors;
4304
+ },
4305
+ set: function (selectors) {
4306
+ if (selectors === void 0) { selectors = []; }
4307
+ if (this._pickedSelectors === selectors)
4308
+ return;
4309
+ this._pickedSelectors = selectors;
4310
+ this.emit(LIST_CHANGED, selectors);
4311
+ },
4312
+ enumerable: false,
4313
+ configurable: true
4314
+ });
4315
+ SelectorsList.prototype._renderSelectors = function () {
4316
+ var _this = this;
4317
+ this.pickedSelectors.forEach(function (selector) {
4318
+ var el = createElementFromDescriptor({
4319
+ text: selector.value,
4320
+ class: 'selector-value',
4321
+ });
4322
+ _this.element.appendChild(el);
4323
+ });
4324
+ this.renderedSelectors = this.pickedSelectors;
4325
+ };
4326
+ SelectorsList.prototype._clear = function () {
4327
+ while (this.element.firstChild)
4328
+ this.element.removeChild(this.element.firstChild);
4329
+ this.renderedSelectors = null;
4330
+ };
4331
+ SelectorsList.prototype._addClickListener = function () {
4332
+ var _this = this;
4333
+ var onClick = function (event) {
4334
+ removeFromUiRoot(_this.element);
4335
+ if (event.target.parentElement === _this.element)
4336
+ _this.emit(SELECTOR_SELECTED, event.target.innerText);
4337
+ listeners$3.removeInternalEventBeforeListener(window, ['click'], onClick);
4338
+ };
4339
+ listeners$3.addFirstInternalEventBeforeListener(window, ['click'], onClick);
4340
+ };
4341
+ SelectorsList.prototype.show = function (_a) {
4342
+ var left = _a.left, bottom = _a.bottom, width = _a.width;
4343
+ if (!this.pickedSelectors || this.pickedSelectors.length === 0)
4344
+ return;
4345
+ if (this.pickedSelectors !== this.renderedSelectors) {
4346
+ this._clear();
4347
+ this._renderSelectors();
4348
+ }
4349
+ var styles = {
4350
+ left: left + 'px',
4351
+ bottom: bottom + 'px',
4352
+ width: width + 'px',
4353
+ };
4354
+ addToUiRoot(this.element);
4355
+ setStyles(this.element, styles);
4356
+ this._addClickListener();
4357
+ };
4358
+ SelectorsList.prototype.clear = function () {
4359
+ this.pickedSelectors = null;
4360
+ };
4361
+ return SelectorsList;
4362
+ }(serviceUtils$2.EventEmitter));
4363
+ var selectorsList$1 = new SelectorsList();
4364
+
4365
+ var nativeMethods$a = hammerhead$1__default.nativeMethods;
4366
+ var shadowUI$9 = hammerhead$1__default.shadowUI;
4367
+ var eventUtils$4 = testCafeCore__default.eventUtils;
4368
+ var ENABLED_CLASS = 'enabled';
4369
+ var MATCH_INDICATOR_CLASSES = {
4370
+ notFound: 'not-found',
4371
+ invalid: 'invalid',
4372
+ ok: 'ok',
4373
+ };
4374
+ var SelectorInputContainer = /** @class */ (function () {
4375
+ function SelectorInputContainer() {
4376
+ this._createElements();
4377
+ this._addEventListeners();
4378
+ }
4379
+ Object.defineProperty(SelectorInputContainer.prototype, "value", {
4380
+ get: function () {
4381
+ return nativeMethods$a.inputValueGetter.call(this.input);
4382
+ },
4383
+ set: function (value) {
4384
+ nativeMethods$a.inputValueSetter.call(this.input, value);
4385
+ },
4386
+ enumerable: false,
4387
+ configurable: true
4388
+ });
4389
+ SelectorInputContainer.prototype._createElements = function () {
4390
+ this.element = createElementFromDescriptor(selectorInputContainer);
4391
+ this.input = createElementFromDescriptor(selectorInput);
4392
+ this.indicator = createElementFromDescriptor(matchIndicator);
4393
+ this.expandButton = createElementFromDescriptor(expandSelectorsList);
4394
+ this.element.appendChild(this.input);
4395
+ this.element.appendChild(this.indicator);
4396
+ this.element.appendChild(this.expandButton);
4397
+ };
4398
+ SelectorInputContainer.prototype._addEventListeners = function () {
4399
+ var _this = this;
4400
+ eventUtils$4.bind(this.expandButton, 'click', function () { return _this._expandSelectorsList(); });
4401
+ eventUtils$4.bind(this.input, 'input', function () { return _this._onSelectorTyped(); });
4402
+ eventUtils$4.bind(this.input, 'focus', function () { return _this._onFocusInput(); });
4403
+ eventUtils$4.bind(this.input, 'blur', function () { return highlighter.stopHighlighting(); });
4404
+ selectorsList$1.on(LIST_CHANGED, function (selectors) {
4405
+ _this._updateExpandButton(selectors);
4406
+ });
4407
+ selectorsList$1.on(SELECTOR_SELECTED, function (value) {
4408
+ _this._setSelectorInputValue({ value: value });
4409
+ });
4410
+ elementPicker.on(ELEMENT_PICKED, function (selectors) {
4411
+ _this._setSelectorInputValue(selectors[0]);
4412
+ });
4413
+ };
4414
+ SelectorInputContainer.prototype._setMatchIndicatorText = function (text) {
4415
+ nativeMethods$a.nodeTextContentSetter.call(this.indicator, text);
4416
+ };
4417
+ SelectorInputContainer.prototype._setMatchIndicatorClass = function (value) {
4418
+ for (var key in MATCH_INDICATOR_CLASSES)
4419
+ shadowUI$9.removeClass(this.indicator, MATCH_INDICATOR_CLASSES[key]);
4420
+ shadowUI$9.addClass(this.indicator, value);
4421
+ };
4422
+ SelectorInputContainer.prototype._indicateMatches = function (elements) {
4423
+ if (elements === null) {
4424
+ this._setMatchIndicatorText('Invalid Selector');
4425
+ this._setMatchIndicatorClass(MATCH_INDICATOR_CLASSES.invalid);
4426
+ return;
4427
+ }
4428
+ if (elements.length === 0) {
4429
+ this._setMatchIndicatorText('No Matching Elements');
4430
+ this._setMatchIndicatorClass(MATCH_INDICATOR_CLASSES.notFound);
4431
+ return;
4432
+ }
4433
+ this._setMatchIndicatorText("Found: ".concat(elements.length));
4434
+ this._setMatchIndicatorClass(MATCH_INDICATOR_CLASSES.ok);
4435
+ };
4436
+ SelectorInputContainer.prototype._highlightElements = function (elements) {
4437
+ for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
4438
+ var element = elements_1[_i];
4439
+ highlighter.highlight(element);
4440
+ }
4441
+ };
4442
+ SelectorInputContainer.prototype._setSelectorInputValue = function (selector) {
4443
+ this.value = selector.value;
4444
+ this.input.focus();
4445
+ };
4446
+ SelectorInputContainer.prototype._expandSelectorsList = function () {
4447
+ var _a = this.element.getBoundingClientRect(), left = _a.left, top = _a.top, width = _a.width;
4448
+ var clientHeight = document.documentElement.clientHeight;
4449
+ var result = {
4450
+ left: left,
4451
+ width: width,
4452
+ bottom: clientHeight - top + 1,
4453
+ };
4454
+ selectorsList$1.show(result);
4455
+ };
4456
+ SelectorInputContainer.prototype._updateExpandButton = function (selectors) {
4457
+ if (selectors && selectors.length)
4458
+ shadowUI$9.addClass(this.expandButton, ENABLED_CLASS);
4459
+ else
4460
+ shadowUI$9.removeClass(this.expandButton, ENABLED_CLASS);
4461
+ };
4462
+ SelectorInputContainer.prototype._onSelectorTyped = function () {
4463
+ selectorsList$1.clear();
4464
+ this._onFocusInput();
4465
+ };
4466
+ SelectorInputContainer.prototype._onFocusInput = function () {
4467
+ return __awaiter(this, void 0, void 0, function () {
4468
+ var elements;
4469
+ return __generator(this, function (_a) {
4470
+ switch (_a.label) {
4471
+ case 0:
4472
+ highlighter.stopHighlighting();
4473
+ if (!this.value) {
4474
+ this._indicateMatches([]);
4475
+ return [2 /*return*/];
4476
+ }
4477
+ return [4 /*yield*/, getElementsBySelector(this.value)];
4478
+ case 1:
4479
+ elements = _a.sent();
4480
+ this._indicateMatches(elements);
4481
+ this._highlightElements(elements);
4482
+ return [2 /*return*/];
4483
+ }
4484
+ });
4485
+ });
4486
+ };
4487
+ return SelectorInputContainer;
4488
+ }());
4489
+
4490
+ function copy(value) {
4491
+ var element = createElementFromDescriptor(auxiliaryCopyInput);
4492
+ addToUiRoot(element);
4493
+ // eslint-disable-next-line no-restricted-properties
4494
+ element.value = value;
4495
+ element.select();
4496
+ document.execCommand('copy');
4497
+ removeFromUiRoot(element);
4498
+ }
4499
+
4500
+ var nativeMethods$b = hammerhead$1__default.nativeMethods;
4501
+ var eventUtils$5 = testCafeCore__default.eventUtils;
4502
+ var ANIMATION_TIMEOUT = 1200;
4503
+ var VALUES = {
4504
+ copy: 'Copy',
4505
+ copied: 'Copied!',
4506
+ };
4507
+ var CopyButton = /** @class */ (function () {
4508
+ function CopyButton(sourceElement) {
4509
+ var _this = this;
4510
+ this.element = createElementFromDescriptor(copyButton);
4511
+ this.sourceElement = sourceElement;
4512
+ eventUtils$5.bind(this.element, 'click', function () { return _this._copySelector(); });
4513
+ }
4514
+ CopyButton.prototype._copySelector = function () {
4515
+ // eslint-disable-next-line no-restricted-properties
4516
+ copy(this.sourceElement.value);
4517
+ this._animate();
4518
+ };
4519
+ CopyButton.prototype._animate = function () {
4520
+ var _this = this;
4521
+ this._changeAppearance(VALUES.copied, 'bold');
4522
+ nativeMethods$b.setTimeout.call(window, function () { return _this._resetAppearance(); }, ANIMATION_TIMEOUT);
4523
+ };
4524
+ CopyButton.prototype._resetAppearance = function () {
4525
+ this._changeAppearance(VALUES.copy, '');
4526
+ };
4527
+ CopyButton.prototype._changeAppearance = function (value, fontWeight) {
4528
+ nativeMethods$b.inputValueSetter.call(this.element, value);
4529
+ setStyles(this.element, { fontWeight: fontWeight });
4530
+ };
4531
+ return CopyButton;
4532
+ }());
4533
+
4534
+ var SelectorInspectorPanel = /** @class */ (function () {
4535
+ function SelectorInspectorPanel() {
4536
+ this.elementPicker = elementPicker;
4537
+ this.element = createElementFromDescriptor(panel);
4538
+ var pickButton = new PickButton();
4539
+ var selectorInputContainer = new SelectorInputContainer();
4540
+ var copyButton = new CopyButton(selectorInputContainer);
4541
+ this.element.appendChild(pickButton.element);
4542
+ this.element.appendChild(selectorInputContainer.element);
4543
+ this.element.appendChild(copyButton.element);
4544
+ }
4545
+ SelectorInspectorPanel.prototype.show = function () {
4546
+ if (!this.element.parentElement)
4547
+ uiRoot.insertFirstChildToPanelsContainer(this.element);
4548
+ setStyles(this.element, { display: 'flex' });
4549
+ };
4550
+ SelectorInspectorPanel.prototype.hide = function () {
4551
+ setStyles(this.element, { display: 'none' });
4552
+ };
4553
+ return SelectorInspectorPanel;
4554
+ }());
4555
+
4556
+ var Promise$2 = hammerhead$1__default.Promise;
4557
+ var messageSandbox$3 = hammerhead$1__default.eventSandbox.message;
1377
4558
  var sendRequestToFrame$1 = testCafeCore__default.sendRequestToFrame;
1378
4559
  var HIDE_REQUEST_CMD = 'ui|hide|request';
1379
4560
  var HIDE_RESPONSE_CMD = 'ui|hide|response';
@@ -1399,6 +4580,7 @@ window['%hammerhead%'].utils.removeInjectedScript();
1399
4580
  exports$1.ProgressPanel = ProgressPanel;
1400
4581
  exports$1.StatusBar = StatusBar;
1401
4582
  exports$1.IframeStatusBar = IframeStatusBar;
4583
+ exports$1.SelectorInspectorPanel = SelectorInspectorPanel;
1402
4584
  exports$1.hide = function (hideTopRoot) {
1403
4585
  if (hideTopRoot)
1404
4586
  return sendRequestToFrame$1({ cmd: HIDE_REQUEST_CMD }, HIDE_RESPONSE_CMD, window.top);
@@ -1413,11 +4595,11 @@ window['%hammerhead%'].utils.removeInjectedScript();
1413
4595
  };
1414
4596
  exports$1.showScreenshotMark = function (url) { return screenshotMark.show(url); };
1415
4597
  exports$1.hideScreenshotMark = function () { return screenshotMark.hide(); };
1416
- var nativeMethods$5 = hammerhead__default.nativeMethods;
1417
- var evalIframeScript = hammerhead__default.EVENTS.evalIframeScript;
1418
- nativeMethods$5.objectDefineProperty(window, '%testCafeUI%', { configurable: true, value: exports$1 });
4598
+ var nativeMethods$c = hammerhead$1__default.nativeMethods;
4599
+ var evalIframeScript = hammerhead$1__default.EVENTS.evalIframeScript;
4600
+ nativeMethods$c.objectDefineProperty(window, '%testCafeUI%', { configurable: true, value: exports$1 });
1419
4601
  // eslint-disable-next-line no-undef
1420
- hammerhead__default.on(evalIframeScript, function (e) { return initTestCafeUI(nativeMethods$5.contentWindowGetter.call(e.iframe), true); });
4602
+ hammerhead$1__default.on(evalIframeScript, function (e) { return initTestCafeUI(nativeMethods$c.contentWindowGetter.call(e.iframe), true); });
1421
4603
 
1422
4604
  }(window['%hammerhead%'], window['%testCafeCore%'], window['%hammerhead%'].Promise));
1423
4605