testcafe 1.18.3 → 1.18.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/lib/browser/provider/built-in/dedicated/chrome/cdp-client/automations/click/create-mouse-click-strategy.js +59 -0
- package/lib/browser/provider/built-in/dedicated/chrome/cdp-client/shared-adapter-initializer.js +15 -1
- package/lib/browser/provider/built-in/dedicated/chrome/cdp-client/utils/dom-utils.js +94 -3
- package/lib/browser/provider/built-in/dedicated/chrome/cdp-client/utils/position-utils.js +38 -7
- package/lib/browser/provider/built-in/dedicated/chrome/cdp-client/utils/style-utils.js +8 -15
- package/lib/client/automation/index.js +1699 -1380
- package/lib/client/automation/index.min.js +1 -1
- package/lib/client/core/index.js +33 -4
- package/lib/client/core/index.min.js +1 -1
- package/lib/client/core/scroll/index.js +2 -2
- package/lib/client/core/utils/shared/position.js +2 -2
- package/lib/client/driver/index.js +143 -94
- package/lib/client/driver/index.min.js +1 -1
- package/lib/client/proxyless/index.js +5 -3
- package/lib/shared/actions/action-executor.js +4 -4
- package/lib/shared/actions/automations/click/index.js +53 -0
- package/lib/shared/actions/automations/click/mouse-click-strategy-base.js +21 -0
- package/lib/shared/actions/automations/move.js +4 -4
- package/lib/shared/actions/automations/visible-element-automation.js +162 -0
- package/lib/shared/actions/get-element.js +68 -0
- package/lib/shared/actions/utils/is-window-iframe.js +8 -0
- package/lib/shared/actions/utils/offsets.js +33 -0
- package/lib/shared/actions/utils/screen-point-to-client.js +15 -0
- package/package.json +3 -3
|
@@ -25,21 +25,6 @@ window['%hammerhead%'].utils.removeInjectedScript();
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
var nativeMethods = hammerhead__default.nativeMethods, Promise = hammerhead__default.Promise, _a = hammerhead__default.utils, browser = _a.browser, featureDetection = _a.featureDetection;
|
|
29
|
-
var dom = testCafeCore__default.domUtils, position = testCafeCore__default.positionUtils, style = testCafeCore__default.styleUtils, event = testCafeCore__default.eventUtils;
|
|
30
|
-
var getOffsetOptions = testCafeAutomation__default.getOffsetOptions;
|
|
31
|
-
initializeAdapter({
|
|
32
|
-
PromiseCtor: Promise,
|
|
33
|
-
nativeMethods: nativeMethods,
|
|
34
|
-
getOffsetOptions: getOffsetOptions,
|
|
35
|
-
dom: dom, position: position, style: style, event: event, browser: browser, featureDetection: featureDetection,
|
|
36
|
-
// NOTE: this functions are unnecessary in the driver
|
|
37
|
-
getElementExceptUI: function () { return Promise.resolve(); },
|
|
38
|
-
scroll: function () { return Promise.resolve(); },
|
|
39
|
-
createEventSequence: function () { },
|
|
40
|
-
sendRequestToFrame: function () { return Promise.resolve(); },
|
|
41
|
-
});
|
|
42
|
-
|
|
43
28
|
/*! *****************************************************************************
|
|
44
29
|
Copyright (c) Microsoft Corporation.
|
|
45
30
|
|
|
@@ -115,6 +100,49 @@ window['%hammerhead%'].utils.removeInjectedScript();
|
|
|
115
100
|
return r;
|
|
116
101
|
}
|
|
117
102
|
|
|
103
|
+
var MouseClickStrategyBase = /** @class */ (function () {
|
|
104
|
+
function MouseClickStrategyBase() {
|
|
105
|
+
}
|
|
106
|
+
return MouseClickStrategyBase;
|
|
107
|
+
}());
|
|
108
|
+
var MouseClickStrategyEmpty = /** @class */ (function (_super) {
|
|
109
|
+
__extends(MouseClickStrategyEmpty, _super);
|
|
110
|
+
function MouseClickStrategyEmpty() {
|
|
111
|
+
return _super.call(this) || this;
|
|
112
|
+
}
|
|
113
|
+
MouseClickStrategyEmpty.prototype.mousedown = function () {
|
|
114
|
+
throw new Error('not implemented');
|
|
115
|
+
};
|
|
116
|
+
MouseClickStrategyEmpty.prototype.mouseup = function () {
|
|
117
|
+
throw new Error('not implemented');
|
|
118
|
+
};
|
|
119
|
+
return MouseClickStrategyEmpty;
|
|
120
|
+
}(MouseClickStrategyBase));
|
|
121
|
+
|
|
122
|
+
var nativeMethods = hammerhead__default.nativeMethods, Promise = hammerhead__default.Promise, _a = hammerhead__default.utils, browser = _a.browser, featureDetection = _a.featureDetection, extend = _a.extend;
|
|
123
|
+
var dom = testCafeCore__default.domUtils, position = testCafeCore__default.positionUtils, style = testCafeCore__default.styleUtils, event = testCafeCore__default.eventUtils;
|
|
124
|
+
var getOffsetOptions = testCafeAutomation__default.getOffsetOptions;
|
|
125
|
+
initializeAdapter({
|
|
126
|
+
PromiseCtor: Promise,
|
|
127
|
+
nativeMethods: nativeMethods,
|
|
128
|
+
getOffsetOptions: getOffsetOptions,
|
|
129
|
+
dom: dom, position: position, style: style, event: event, browser: browser, featureDetection: featureDetection,
|
|
130
|
+
utils: { extend: extend },
|
|
131
|
+
// NOTE: this functions are unnecessary in the driver
|
|
132
|
+
getElementExceptUI: function () { return Promise.resolve(); },
|
|
133
|
+
scroll: function () { return Promise.resolve(); },
|
|
134
|
+
createEventSequence: function () { },
|
|
135
|
+
sendRequestToFrame: function () { return Promise.resolve(); },
|
|
136
|
+
ensureMouseEventAfterScroll: function () { return Promise.resolve(); },
|
|
137
|
+
automations: {
|
|
138
|
+
click: {
|
|
139
|
+
createMouseClickStrategy: function () { return new MouseClickStrategyEmpty(); },
|
|
140
|
+
},
|
|
141
|
+
_ensureWindowAndCursorForLegacyTests: function () {
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
118
146
|
// -------------------------------------------------------------
|
|
119
147
|
// WARNING: this file is used by both the client and the server.
|
|
120
148
|
// Do not use any browser or node-specific API!
|
|
@@ -2704,15 +2732,25 @@ window['%hammerhead%'].utils.removeInjectedScript();
|
|
|
2704
2732
|
handler.ensureElsProps(this._elements);
|
|
2705
2733
|
};
|
|
2706
2734
|
ActionExecutor.prototype._ensureCommandOptions = function () {
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2735
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2736
|
+
var opts, _a, offsetX, offsetY;
|
|
2737
|
+
return __generator(this, function (_b) {
|
|
2738
|
+
switch (_b.label) {
|
|
2739
|
+
case 0:
|
|
2740
|
+
opts = this._command.options;
|
|
2741
|
+
if (!(this._elements.length && opts && 'offsetX' in opts && 'offsetY' in opts)) return [3 /*break*/, 2];
|
|
2742
|
+
return [4 /*yield*/, adapter.getOffsetOptions(this._elements[0], opts.offsetX, opts.offsetY)];
|
|
2743
|
+
case 1:
|
|
2744
|
+
_a = _b.sent(), offsetX = _a.offsetX, offsetY = _a.offsetY;
|
|
2745
|
+
// @ts-ignore TODO
|
|
2746
|
+
opts.offsetX = offsetX;
|
|
2747
|
+
// @ts-ignore TODO
|
|
2748
|
+
opts.offsetY = offsetY;
|
|
2749
|
+
_b.label = 2;
|
|
2750
|
+
case 2: return [2 /*return*/];
|
|
2751
|
+
}
|
|
2752
|
+
});
|
|
2753
|
+
});
|
|
2716
2754
|
};
|
|
2717
2755
|
ActionExecutor.prototype._createAutomation = function () {
|
|
2718
2756
|
var handler = ActionExecutor.ACTIONS_HANDLERS[this._command.type];
|
|
@@ -2724,8 +2762,8 @@ window['%hammerhead%'].utils.removeInjectedScript();
|
|
|
2724
2762
|
var _this = this;
|
|
2725
2763
|
return this._ensureCommandElements()
|
|
2726
2764
|
.then(function () { return _this._ensureCommandElementsProperties(); })
|
|
2765
|
+
.then(function () { return _this._ensureCommandOptions(); })
|
|
2727
2766
|
.then(function () {
|
|
2728
|
-
_this._ensureCommandOptions();
|
|
2729
2767
|
var automation = _this._createAutomation();
|
|
2730
2768
|
if (automation.TARGET_ELEMENT_FOUND_EVENT) {
|
|
2731
2769
|
automation.on(automation.TARGET_ELEMENT_FOUND_EVENT, function (e) {
|
|
@@ -2822,73 +2860,84 @@ window['%hammerhead%'].utils.removeInjectedScript();
|
|
|
2822
2860
|
return Math.round(cropStart + limitNumber(cropEnd - cropStart, 0, viewportBound) / 2);
|
|
2823
2861
|
}
|
|
2824
2862
|
function ensureCropOptions(element, options) {
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2863
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2864
|
+
var elementRectangle, elementBounds, elementMargin, elementPadding, elementBordersWidth, scrollRight, scrollBottom, horizontalCropBounds, verticalCropBounds, viewportDimensions, hasScrollTargetX, hasScrollTargetY, _a, offsetX, offsetY, isScrollTargetXValid, isScrollTargetYValid;
|
|
2865
|
+
return __generator(this, function (_b) {
|
|
2866
|
+
switch (_b.label) {
|
|
2867
|
+
case 0:
|
|
2868
|
+
elementRectangle = element.getBoundingClientRect();
|
|
2869
|
+
elementBounds = {
|
|
2870
|
+
left: elementRectangle.left,
|
|
2871
|
+
right: elementRectangle.right,
|
|
2872
|
+
top: elementRectangle.top,
|
|
2873
|
+
bottom: elementRectangle.bottom,
|
|
2874
|
+
};
|
|
2875
|
+
elementMargin = testCafeCore.styleUtils.getElementMargin(element);
|
|
2876
|
+
elementPadding = testCafeCore.styleUtils.getElementPadding(element);
|
|
2877
|
+
elementBordersWidth = testCafeCore.styleUtils.getBordersWidth(element);
|
|
2878
|
+
options.originOffset = { x: 0, y: 0 };
|
|
2879
|
+
scrollRight = elementBounds.left + element.scrollWidth + elementBordersWidth.left + elementBordersWidth.right;
|
|
2880
|
+
scrollBottom = elementBounds.top + element.scrollHeight + elementBordersWidth.top + elementBordersWidth.bottom;
|
|
2881
|
+
elementBounds.right = Math.max(elementBounds.right, scrollRight);
|
|
2882
|
+
elementBounds.bottom = Math.max(elementBounds.bottom, scrollBottom);
|
|
2883
|
+
if (!options.includeBorders || !options.includePaddings) {
|
|
2884
|
+
options.originOffset.x += elementBordersWidth.left;
|
|
2885
|
+
options.originOffset.y += elementBordersWidth.top;
|
|
2886
|
+
elementBounds.left += elementBordersWidth.left;
|
|
2887
|
+
elementBounds.top += elementBordersWidth.top;
|
|
2888
|
+
elementBounds.right -= elementBordersWidth.right;
|
|
2889
|
+
elementBounds.bottom -= elementBordersWidth.bottom;
|
|
2890
|
+
if (!options.includePaddings) {
|
|
2891
|
+
options.originOffset.x += elementPadding.left;
|
|
2892
|
+
options.originOffset.y += elementPadding.top;
|
|
2893
|
+
elementBounds.left += elementPadding.left;
|
|
2894
|
+
elementBounds.top += elementPadding.top;
|
|
2895
|
+
elementBounds.right -= elementPadding.right;
|
|
2896
|
+
elementBounds.bottom -= elementPadding.bottom;
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2899
|
+
else if (options.includeMargins) {
|
|
2900
|
+
options.originOffset.x -= elementMargin.left;
|
|
2901
|
+
options.originOffset.y -= elementMargin.top;
|
|
2902
|
+
elementBounds.left -= elementMargin.left;
|
|
2903
|
+
elementBounds.top -= elementMargin.top;
|
|
2904
|
+
elementBounds.right += elementMargin.right;
|
|
2905
|
+
elementBounds.bottom += elementMargin.bottom;
|
|
2906
|
+
}
|
|
2907
|
+
elementBounds.width = elementBounds.right - elementBounds.left;
|
|
2908
|
+
elementBounds.height = elementBounds.bottom - elementBounds.top;
|
|
2909
|
+
horizontalCropBounds = determineDimensionBounds({ min: options.crop.left, max: options.crop.right, length: options.crop.width }, elementBounds.width);
|
|
2910
|
+
verticalCropBounds = determineDimensionBounds({ min: options.crop.top, max: options.crop.bottom, length: options.crop.height }, elementBounds.height);
|
|
2911
|
+
options.crop.left = horizontalCropBounds.min;
|
|
2912
|
+
options.crop.right = horizontalCropBounds.max;
|
|
2913
|
+
options.crop.width = horizontalCropBounds.length;
|
|
2914
|
+
options.crop.top = verticalCropBounds.min;
|
|
2915
|
+
options.crop.bottom = verticalCropBounds.max;
|
|
2916
|
+
options.crop.height = verticalCropBounds.length;
|
|
2917
|
+
if (options.crop.width <= 0 || options.crop.height <= 0)
|
|
2918
|
+
throw new InvalidElementScreenshotDimensionsError(options.crop.width, options.crop.height);
|
|
2919
|
+
viewportDimensions = testCafeCore.styleUtils.getViewportDimensions();
|
|
2920
|
+
if (elementBounds.width > viewportDimensions.width || elementBounds.height > viewportDimensions.height)
|
|
2921
|
+
options.scrollToCenter = true;
|
|
2922
|
+
hasScrollTargetX = typeof options.scrollTargetX === 'number';
|
|
2923
|
+
hasScrollTargetY = typeof options.scrollTargetY === 'number';
|
|
2924
|
+
if (!hasScrollTargetX)
|
|
2925
|
+
options.scrollTargetX = determineScrollPoint(options.crop.left, options.crop.right, viewportDimensions.width);
|
|
2926
|
+
if (!hasScrollTargetY)
|
|
2927
|
+
options.scrollTargetY = determineScrollPoint(options.crop.top, options.crop.bottom, viewportDimensions.height);
|
|
2928
|
+
return [4 /*yield*/, testCafeAutomation.getOffsetOptions(element, options.scrollTargetX, options.scrollTargetY)];
|
|
2929
|
+
case 1:
|
|
2930
|
+
_a = _b.sent(), offsetX = _a.offsetX, offsetY = _a.offsetY;
|
|
2931
|
+
options.scrollTargetX = offsetX;
|
|
2932
|
+
options.scrollTargetY = offsetY;
|
|
2933
|
+
isScrollTargetXValid = !hasScrollTargetX || options.scrollTargetX >= options.crop.left && options.scrollTargetX <= options.crop.right;
|
|
2934
|
+
isScrollTargetYValid = !hasScrollTargetY || options.scrollTargetY >= options.crop.top && options.scrollTargetY <= options.crop.bottom;
|
|
2935
|
+
if (!isScrollTargetXValid || !isScrollTargetYValid)
|
|
2936
|
+
throw new ActionInvalidScrollTargetError(isScrollTargetXValid, isScrollTargetYValid);
|
|
2937
|
+
return [2 /*return*/];
|
|
2938
|
+
}
|
|
2939
|
+
});
|
|
2940
|
+
});
|
|
2892
2941
|
}
|
|
2893
2942
|
|
|
2894
2943
|
var CHECK_ELEMENT_DELAY = 200;
|
|
@@ -3388,8 +3437,8 @@ window['%hammerhead%'].utils.removeInjectedScript();
|
|
|
3388
3437
|
throw error;
|
|
3389
3438
|
});
|
|
3390
3439
|
})
|
|
3440
|
+
.then(function () { return ensureCropOptions(_this.element, _this.command.options); })
|
|
3391
3441
|
.then(function () {
|
|
3392
|
-
ensureCropOptions(_this.element, _this.command.options);
|
|
3393
3442
|
var _a = _this.command.options, scrollTargetX = _a.scrollTargetX, scrollTargetY = _a.scrollTargetY, scrollToCenter = _a.scrollToCenter;
|
|
3394
3443
|
var scrollAutomation = new testCafeCore.ScrollAutomation(_this.element, new ScrollOptions({
|
|
3395
3444
|
offsetX: scrollTargetX,
|
|
@@ -3845,7 +3894,7 @@ window['%hammerhead%'].utils.removeInjectedScript();
|
|
|
3845
3894
|
create: function (command, elements) {
|
|
3846
3895
|
if (/option|optgroup/.test(testCafeCore.domUtils.getTagName(elements[0])))
|
|
3847
3896
|
return new testCafeAutomation.SelectChildClick(elements[0], command.options);
|
|
3848
|
-
return new testCafeAutomation.Click(elements[0], command.options);
|
|
3897
|
+
return new testCafeAutomation.Click(elements[0], command.options, window, testCafeAutomation.cursor);
|
|
3849
3898
|
},
|
|
3850
3899
|
};
|
|
3851
3900
|
ActionExecutor.ACTIONS_HANDLERS[COMMAND_TYPE.rightClick] = {
|