testcafe
Version:
Automated browser testing for the modern web development stack.
1,005 lines (983 loc) • 224 kB
JavaScript
window['%hammerhead%'].utils.removeInjectedScript();
// NOTE: We should have the capability to initialize scripts with different contexts.
// This is required for iframes without the src attribute because Hammerhead does not
// inject scripts into such iframes. So, we wrap all scripts in initialization functions.
(function () {
function initTestCafeUI(window) {
var document = window.document;
(function (hammerhead$1, testCafeCore, Promise$4) {
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var hammerhead__default = /*#__PURE__*/_interopDefaultLegacy(hammerhead$1);
var testCafeCore__default = /*#__PURE__*/_interopDefaultLegacy(testCafeCore);
var Promise__default = /*#__PURE__*/_interopDefaultLegacy(Promise$4);
var PANELS_CONTAINER_CLASS = 'panels-container';
var uiRoot = {
uiRoot: null,
container: null,
element: function () {
if (!this.uiRoot) {
this.uiRoot = document.createElement('div');
hammerhead$1.shadowUI.getRoot().appendChild(this.uiRoot);
}
return this.uiRoot;
},
panelsContainer: function () {
if (!this.container) {
this.container = document.createElement('div');
hammerhead$1.shadowUI.addClass(this.container, PANELS_CONTAINER_CLASS);
this.element().appendChild(this.container);
}
return this.container;
},
insertFirstChildToPanelsContainer: function (element) {
var panelsContainer = this.panelsContainer();
var firstChild = hammerhead$1.nativeMethods.nodeFirstChildGetter.call(panelsContainer);
panelsContainer.insertBefore(element, firstChild);
},
hide: function () {
if (!this.uiRoot)
return;
this.uiRoot.style.visibility = 'hidden';
},
show: function () {
if (!this.uiRoot)
return;
this.uiRoot.style.visibility = '';
},
remove: function () {
var shadowRoot = hammerhead$1.shadowUI.getRoot();
var parent = hammerhead$1.nativeMethods.nodeParentNodeGetter.call(shadowRoot);
parent.removeChild(shadowRoot);
},
};
//NOTE: we can't manipulate (open/close option list) with a native select element during test running, so we
var shadowUI$9 = hammerhead__default["default"].shadowUI;
var browserUtils$1 = hammerhead__default["default"].utils.browser;
var featureDetection$2 = hammerhead__default["default"].utils.featureDetection;
var nativeMethods$e = hammerhead__default["default"].nativeMethods;
var eventSimulator = hammerhead__default["default"].eventSandbox.eventSimulator;
var listeners$3 = hammerhead__default["default"].eventSandbox.listeners;
var positionUtils$1 = testCafeCore__default["default"].positionUtils;
var domUtils$b = testCafeCore__default["default"].domUtils;
var styleUtils$9 = testCafeCore__default["default"].styleUtils;
var eventUtils$6 = testCafeCore__default["default"].eventUtils;
var arrayUtils$9 = testCafeCore__default["default"].arrayUtils;
var selectController = testCafeCore__default["default"].selectController;
var OPTION_LIST_CLASS = 'tcOptionList';
var DISABLED_CLASS = 'disabled';
var MAX_OPTION_LIST_LENGTH = 20;
function onDocumentMouseDown(e) {
var target = nativeMethods$e.eventTargetGetter.call(e);
var curSelectEl = selectController.currentEl;
//NOTE: only in Mozilla 'mousedown' raises for option
if ((target || e.srcElement) !== curSelectEl && !domUtils$b.containsElement(curSelectEl, target) &&
!domUtils$b.containsElement(selectController.optionList, target))
collapseOptionList();
}
function onWindowClick(e, dispatched, preventDefault) {
var target = nativeMethods$e.eventTargetGetter.call(e);
var optionIndex = arrayUtils$9.indexOf(selectController.options, target);
if (optionIndex < 0)
return;
preventDefault();
var isDisabled = target.className.indexOf(DISABLED_CLASS) > -1;
if (isDisabled && browserUtils$1.isWebKit)
return;
clickOnOption(optionIndex, isDisabled);
}
function clickOnOption(optionIndex, isOptionDisabled) {
var curSelectEl = selectController.currentEl;
var curSelectIndex = curSelectEl.selectedIndex;
var realOption = curSelectEl.getElementsByTagName('option')[optionIndex];
var clickLeadChanges = !isOptionDisabled && optionIndex !== curSelectIndex;
if (clickLeadChanges)
curSelectEl.selectedIndex = optionIndex;
if (!browserUtils$1.isFirefox && clickLeadChanges) {
eventSimulator.input(curSelectEl);
eventSimulator.change(curSelectEl);
}
if (browserUtils$1.isFirefox)
eventSimulator.mousedown(browserUtils$1.isFirefox ? realOption : curSelectEl);
if (!featureDetection$2.isTouchDevice)
eventSimulator.mouseup(browserUtils$1.isFirefox ? realOption : curSelectEl);
if (browserUtils$1.isFirefox && clickLeadChanges) {
eventSimulator.input(curSelectEl);
eventSimulator.change(curSelectEl);
}
if (!featureDetection$2.isTouchDevice)
eventSimulator.click(browserUtils$1.isFirefox ? realOption : curSelectEl);
if (!isOptionDisabled)
collapseOptionList();
}
function expandOptionList(select) {
var selectChildren = select.children;
if (!selectChildren.length || select.disabled)
return;
//NOTE: check is option list expanded
if (selectController.currentEl) {
var isSelectExpanded = select === selectController.currentEl;
collapseOptionList();
if (isSelectExpanded)
return;
}
var curSelectEl = selectController.currentEl = select;
var optionList = selectController.optionList = document.createElement('div');
uiRoot.element().appendChild(optionList);
shadowUI$9.addClass(optionList, OPTION_LIST_CLASS);
selectController.createChildren(selectChildren, optionList);
listeners$3.addInternalEventBeforeListener(window, ['click'], onWindowClick);
nativeMethods$e.setTimeout.call(window, function () {
eventUtils$6.bind(document, 'mousedown', onDocumentMouseDown);
}, 0);
styleUtils$9.set(optionList, {
position: 'absolute',
fontSize: styleUtils$9.get(curSelectEl, 'fontSize'),
fontFamily: styleUtils$9.get(curSelectEl, 'fontFamily'),
minWidth: styleUtils$9.getWidth(curSelectEl) + 'px',
left: positionUtils$1.getOffsetPosition(curSelectEl).left + 'px',
height: domUtils$b.getSelectVisibleChildren(select).length > MAX_OPTION_LIST_LENGTH ?
styleUtils$9.getOptionHeight(select) * MAX_OPTION_LIST_LENGTH : '',
});
var selectTopPosition = positionUtils$1.getOffsetPosition(curSelectEl).top;
var optionListHeight = styleUtils$9.getHeight(optionList);
var optionListTopPosition = selectTopPosition + styleUtils$9.getHeight(curSelectEl) + 2;
if (optionListTopPosition + optionListHeight > styleUtils$9.getScrollTop(window) + styleUtils$9.getHeight(window)) {
var topPositionAboveSelect = selectTopPosition - 3 - optionListHeight;
if (topPositionAboveSelect >= styleUtils$9.getScrollTop(window))
optionListTopPosition = topPositionAboveSelect;
}
styleUtils$9.set(optionList, 'top', optionListTopPosition + 'px');
}
function collapseOptionList() {
domUtils$b.remove(selectController.optionList);
eventUtils$6.unbind(document, 'mousedown', onDocumentMouseDown);
selectController.clear();
}
function scrollOptionListByChild(child) {
var select = domUtils$b.getSelectParent(child);
if (!select)
return;
var realSizeValue = styleUtils$9.getSelectElementSize(select);
var optionHeight = styleUtils$9.getOptionHeight(select);
var scrollIndent = 0;
var topVisibleIndex = Math.max(styleUtils$9.getScrollTop(select) / optionHeight, 0);
var bottomVisibleIndex = topVisibleIndex + realSizeValue - 1;
var childIndex = domUtils$b.getChildVisibleIndex(select, child);
if (childIndex < topVisibleIndex) {
scrollIndent = optionHeight * (topVisibleIndex - childIndex);
styleUtils$9.setScrollTop(select, Math.max(styleUtils$9.getScrollTop(select) - scrollIndent, 0));
}
else if (childIndex > bottomVisibleIndex) {
scrollIndent = optionHeight * (childIndex - bottomVisibleIndex);
styleUtils$9.setScrollTop(select, styleUtils$9.getScrollTop(select) + scrollIndent);
}
}
function getSelectChildCenter(child) {
var select = domUtils$b.getSelectParent(child);
if (!select) {
return {
x: 0,
y: 0,
};
}
var optionHeight = styleUtils$9.getOptionHeight(select);
var childRectangle = positionUtils$1.getElementRectangle(child);
return {
x: Math.round(childRectangle.left + childRectangle.width / 2),
y: Math.round(childRectangle.top + optionHeight / 2),
};
}
function switchOptionsByKeys(element, command) {
var selectSize = styleUtils$9.getSelectElementSize(element);
var optionListHidden = !styleUtils$9.hasDimensions(shadowUI$9.select('.' + OPTION_LIST_CLASS)[0]);
if (/down|up/.test(command) ||
(selectSize <= 1 || browserUtils$1.isFirefox) &&
(optionListHidden || browserUtils$1.isFirefox) && /left|right/.test(command)) {
var realOptions = element.querySelectorAll('option');
var enabledOptions = [];
for (var i = 0; i < realOptions.length; i++) {
var parent_1 = realOptions[i].parentElement;
if (!realOptions[i].disabled && !(domUtils$b.getTagName(parent_1) === 'optgroup' && parent_1.disabled))
enabledOptions.push(realOptions[i]);
}
var curSelectedOptionIndex = arrayUtils$9.indexOf(enabledOptions, realOptions[element.selectedIndex]);
var nextIndex = curSelectedOptionIndex + (/down|right/.test(command) ? 1 : -1);
if (nextIndex >= 0 && nextIndex < enabledOptions.length) {
element.selectedIndex = arrayUtils$9.indexOf(realOptions, enabledOptions[nextIndex]);
eventSimulator.input(element);
eventSimulator.change(element);
}
}
}
var selectElement = /*#__PURE__*/Object.freeze({
__proto__: null,
expandOptionList: expandOptionList,
collapseOptionList: collapseOptionList,
scrollOptionListByChild: scrollOptionListByChild,
getSelectChildCenter: getSelectChildCenter,
switchOptionsByKeys: switchOptionsByKeys
});
//Const
var LOADING_TEXT = 'Loading page...';
var BACKGROUND_CLASS = 'modal-background';
var LOADING_TEXT_CLASS = 'loading-text';
var BACKGROUND_OPACITY = 0.7;
var BACKGROUND_OPACITY_WITH_LOADING_TEXT = 0.8;
var LOADING_ICON_CLASS = 'loading-icon';
//Globals
var backgroundDiv = null;
var loadingTextDiv = null;
var loadingIconDiv = null;
var initialized = false;
//Markup
function createBackground() {
var root = uiRoot.element();
backgroundDiv = document.createElement('div');
root.appendChild(backgroundDiv);
hammerhead$1.shadowUI.addClass(backgroundDiv, BACKGROUND_CLASS);
loadingTextDiv = document.createElement('div');
hammerhead$1.nativeMethods.nodeTextContentSetter.call(loadingTextDiv, LOADING_TEXT);
root.appendChild(loadingTextDiv);
hammerhead$1.shadowUI.addClass(loadingTextDiv, LOADING_TEXT_CLASS);
loadingIconDiv = document.createElement('div');
testCafeCore.styleUtils.set(loadingIconDiv, 'visibility', 'hidden');
root.appendChild(loadingIconDiv);
hammerhead$1.shadowUI.addClass(loadingIconDiv, LOADING_ICON_CLASS);
}
//Behavior
function adjustLoadingTextPos() {
var wHeight = testCafeCore.styleUtils.getHeight(window);
var wWidth = testCafeCore.styleUtils.getWidth(window);
var loadingTextHidden = !testCafeCore.styleUtils.hasDimensions(loadingTextDiv);
if (loadingTextHidden) {
testCafeCore.styleUtils.set(loadingTextDiv, 'visibility', 'hidden');
testCafeCore.styleUtils.set(loadingTextDiv, 'display', 'block');
}
testCafeCore.styleUtils.set(loadingTextDiv, {
left: Math.max((wWidth - testCafeCore.styleUtils.getWidth(loadingTextDiv)) / 2, 0) + 'px',
top: Math.max((wHeight - testCafeCore.styleUtils.getHeight(loadingTextDiv)) / 2, 0) + 'px',
});
if (loadingTextHidden) {
testCafeCore.styleUtils.set(loadingTextDiv, 'display', 'none');
testCafeCore.styleUtils.set(loadingTextDiv, 'visibility', '');
}
}
function initSizeAdjustments() {
var adjust = function () {
var wHeight = testCafeCore.styleUtils.getHeight(window);
var wWidth = testCafeCore.styleUtils.getWidth(window);
testCafeCore.styleUtils.set(backgroundDiv, 'width', wWidth + 'px');
testCafeCore.styleUtils.set(backgroundDiv, 'height', wHeight + 'px');
testCafeCore.styleUtils.set(loadingIconDiv, {
left: Math.round((wWidth - testCafeCore.styleUtils.getWidth(loadingIconDiv)) / 2) + 'px',
top: Math.round((wHeight - testCafeCore.styleUtils.getHeight(loadingIconDiv)) / 2) + 'px',
});
};
adjust();
testCafeCore.eventUtils.bind(window, 'resize', adjust);
}
function init() {
createBackground();
initSizeAdjustments();
adjustLoadingTextPos();
initialized = true;
}
function initAndShowLoadingText() {
var shown = false;
//NOTE: init and show modal background as soon as possible
var initAndShow = function () {
init();
testCafeCore.styleUtils.set(backgroundDiv, 'opacity', BACKGROUND_OPACITY_WITH_LOADING_TEXT);
testCafeCore.styleUtils.set(backgroundDiv, 'display', 'block');
testCafeCore.styleUtils.set(loadingTextDiv, 'display', 'block');
shown = true;
};
var tryShowBeforeReady = function () {
if (!shown) {
if (document.body)
initAndShow();
else
hammerhead$1.nativeMethods.setTimeout.call(window, tryShowBeforeReady, 0);
}
};
tryShowBeforeReady();
//NOTE: ensure that background was shown on ready
testCafeCore.eventUtils
.documentReady()
.then(function () {
if (!shown)
initAndShow();
});
}
function show(transparent) {
if (!initialized)
init();
testCafeCore.styleUtils.set(backgroundDiv, 'opacity', transparent ? 0 : BACKGROUND_OPACITY);
testCafeCore.styleUtils.set(backgroundDiv, 'display', 'block');
}
function hide() {
if (!initialized)
return;
testCafeCore.styleUtils.set(loadingTextDiv, 'display', 'none');
testCafeCore.styleUtils.set(backgroundDiv, 'display', 'none');
}
function showLoadingIcon() {
testCafeCore.styleUtils.set(loadingIconDiv, 'visibility', 'visible');
}
function hideLoadingIcon() {
testCafeCore.styleUtils.set(loadingIconDiv, 'visibility', 'hidden');
}
var modalBackground = /*#__PURE__*/Object.freeze({
__proto__: null,
initAndShowLoadingText: initAndShowLoadingText,
show: show,
hide: hide,
showLoadingIcon: showLoadingIcon,
hideLoadingIcon: hideLoadingIcon
});
var shadowUI$8 = hammerhead__default["default"].shadowUI;
var styleUtils$8 = testCafeCore__default["default"].styleUtils;
var CONTAINER_CLASS$1 = 'progress-bar';
var VALUE_CLASS$1 = 'value';
var SUCCESS_CLASS = 'success';
var ProgressBar$1 = /** @class */ (function () {
function ProgressBar(containerElement) {
this.containerElement = document.createElement('div');
this.valueElement = document.createElement('div');
containerElement.appendChild(this.containerElement);
this.containerElement.appendChild(this.valueElement);
shadowUI$8.addClass(this.containerElement, CONTAINER_CLASS$1);
shadowUI$8.addClass(this.valueElement, VALUE_CLASS$1);
}
ProgressBar.prototype.setValue = function (value) {
value = typeof value !== 'number' ? 0 : Math.min(Math.max(value, 0), 100);
styleUtils$8.set(this.valueElement, 'width', value + '%');
};
ProgressBar.prototype.setSuccess = function (value) {
if (value)
shadowUI$8.addClass(this.containerElement, SUCCESS_CLASS);
else
shadowUI$8.removeClass(this.containerElement, SUCCESS_CLASS);
};
return ProgressBar;
}());
var shadowUI$7 = hammerhead__default["default"].shadowUI;
var nativeMethods$d = hammerhead__default["default"].nativeMethods;
var eventUtils$5 = testCafeCore__default["default"].eventUtils;
var styleUtils$7 = testCafeCore__default["default"].styleUtils;
var PANEL_CLASS = 'progress-panel';
var TITLE_CLASS = 'title';
var CONTENT_CLASS = 'content';
var UPDATE_INTERVAL = 100;
var ANIMATION_UPDATE_INTERVAL$3 = 10;
var OPENING_DELAY = 300;
var SHOWING_DELAY$1 = 200;
var HIDING_DELAY = 600;
var MIN_SHOWING_TIME = 1000;
var ProgressPanel = /** @class */ (function () {
function ProgressPanel() {
var _this = this;
this.startTime = null;
this.openingTimeout = null;
this.updateInterval = null;
this.animationInterval = null;
this.panelDiv = document.createElement('div');
uiRoot.element().appendChild(this.panelDiv);
this.titleDiv = document.createElement('div');
this.panelDiv.appendChild(this.titleDiv);
this.contentDiv = document.createElement('div');
this.panelDiv.appendChild(this.contentDiv);
shadowUI$7.addClass(this.panelDiv, PANEL_CLASS);
shadowUI$7.addClass(this.titleDiv, TITLE_CLASS);
shadowUI$7.addClass(this.contentDiv, CONTENT_CLASS);
ProgressPanel._showAtWindowCenter(this.panelDiv);
this.progressBar = new ProgressBar$1(this.contentDiv);
this.disposePanel = function () { return ProgressPanel._showAtWindowCenter(_this.panelDiv); };
}
ProgressPanel._getInvisibleElementProperty = function (element, property) {
var needShowElement = styleUtils$7.get(element, 'display') === 'none';
if (needShowElement)
styleUtils$7.set(element, 'display', 'block');
var value = element[property];
if (needShowElement)
styleUtils$7.set(element, 'display', 'none');
return value;
};
ProgressPanel._showAtWindowCenter = function (element) {
var elementHeight = ProgressPanel._getInvisibleElementProperty(element, 'offsetHeight');
var elementWidth = ProgressPanel._getInvisibleElementProperty(element, 'offsetWidth');
var top = Math.round(styleUtils$7.getHeight(window) / 2 - elementHeight / 2);
var left = Math.round(styleUtils$7.getWidth(window) / 2 - elementWidth / 2);
styleUtils$7.set(element, {
left: left + 'px',
top: top + 'px',
});
};
ProgressPanel.prototype._setCurrentProgress = function () {
var progress = Math.round((nativeMethods$d.dateNow() - this.startTime) / this.maxTimeout * 100);
this.progressBar.setValue(progress);
};
ProgressPanel.prototype._setSuccess = function (value) {
this.progressBar.setSuccess(value);
};
ProgressPanel.prototype._stopAnimation = function () {
nativeMethods$d.clearInterval.call(window, this.animationInterval);
};
ProgressPanel.prototype._animate = function (el, duration, show, complete) {
var _this = this;
var startTime = nativeMethods$d.dateNow();
var startOpacityValue = show ? 0 : 1;
var passedTime = 0;
var progress = 0;
var delta = 0;
if (show) {
styleUtils$7.set(el, 'opacity', startOpacityValue);
styleUtils$7.set(el, 'display', 'block');
}
this._stopAnimation();
this.animationInterval = nativeMethods$d.setInterval.call(window, function () {
passedTime = nativeMethods$d.dateNow() - startTime;
progress = Math.min(passedTime / duration, 1);
delta = 0.5 - Math.cos(progress * Math.PI) / 2;
styleUtils$7.set(el, 'opacity', startOpacityValue + (show ? delta : -delta));
if (progress === 1) {
_this._stopAnimation();
if (complete)
complete();
}
}, ANIMATION_UPDATE_INTERVAL$3);
};
ProgressPanel.prototype._showPanel = function () {
eventUtils$5.bind(window, 'resize', this.disposePanel);
this._animate(this.panelDiv, SHOWING_DELAY$1, true);
};
ProgressPanel.prototype._hidePanel = function (force) {
var _this = this;
this.startTime = null;
eventUtils$5.unbind(window, 'resize', this.disposePanel);
this._animate(this.panelDiv, force ? 0 : HIDING_DELAY, false, function () { return styleUtils$7.set(_this.panelDiv, 'display', 'none'); });
};
ProgressPanel.prototype.show = function (text, timeout) {
var _this = this;
this.startTime = nativeMethods$d.dateNow();
this.maxTimeout = timeout;
nativeMethods$d.nodeTextContentSetter.call(this.titleDiv, text);
this._setSuccess(false);
this.openingTimeout = nativeMethods$d.setTimeout.call(window, function () {
_this.openingTimeout = null;
_this._setCurrentProgress();
_this._showPanel();
_this.updateInterval = nativeMethods$d.setInterval.call(window, function () { return _this._setCurrentProgress(); }, UPDATE_INTERVAL);
}, OPENING_DELAY);
};
ProgressPanel.prototype.close = function (success) {
var _this = this;
if (success)
this._setSuccess(true);
if (this.openingTimeout) {
nativeMethods$d.clearTimeout.call(window, this.openingTimeout);
this.openingTimeout = null;
}
if (this.updateInterval) {
nativeMethods$d.clearInterval.call(window, this.updateInterval);
this.updateInterval = null;
}
if (success) {
if (this.startTime && nativeMethods$d.dateNow() - this.startTime < MIN_SHOWING_TIME) {
nativeMethods$d.setTimeout.call(window, function () {
nativeMethods$d.setTimeout.call(window, function () { return _this._hidePanel(false); }, SHOWING_DELAY$1);
}, UPDATE_INTERVAL);
}
else
nativeMethods$d.setTimeout.call(window, function () { return _this._hidePanel(false); }, SHOWING_DELAY$1);
}
else
this._hidePanel(true);
};
return ProgressPanel;
}());
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise__default["default"]))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _)
try {
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)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};
var shadowUI$6 = hammerhead__default["default"].shadowUI;
var nativeMethods$c = hammerhead__default["default"].nativeMethods;
var styleUtils$6 = testCafeCore__default["default"].styleUtils;
var DETERMINATE_STYLE_CLASS = 'determinate';
var ANIMATION_UPDATE_INTERVAL$2 = 10;
var DeterminateIndicator = /** @class */ (function () {
function DeterminateIndicator(progressBar, firstValue) {
this.progressBar = progressBar;
this.firstValueElement = firstValue;
this.maxTimeout = null;
this.startTime = null;
this.animationInterval = null;
}
DeterminateIndicator.prototype._setCurrentProgress = function () {
var progress = (nativeMethods$c.dateNow() - this.startTime) / this.maxTimeout;
var percent = Math.min(Math.max(progress, 0), 1);
var progressBarWidth = styleUtils$6.getWidth(this.progressBar);
var newWidth = Math.round(progressBarWidth * percent);
styleUtils$6.set(this.firstValueElement, 'width', newWidth + 'px');
};
DeterminateIndicator.prototype.start = function (maxTimeout, startTime) {
var _this = this;
shadowUI$6.addClass(this.progressBar, DETERMINATE_STYLE_CLASS);
this.maxTimeout = maxTimeout;
this.startTime = startTime || nativeMethods$c.dateNow();
this._setCurrentProgress();
this.animationInterval = nativeMethods$c.setInterval.call(window, function () { return _this._setCurrentProgress(); }, ANIMATION_UPDATE_INTERVAL$2);
};
DeterminateIndicator.prototype.stop = function () {
if (this.animationInterval) {
nativeMethods$c.clearInterval.call(window, this.animationInterval);
this.animationInterval = null;
}
};
DeterminateIndicator.prototype.reset = function () {
styleUtils$6.set(this.firstValueElement, 'width', 0);
shadowUI$6.removeClass(this.progressBar, DETERMINATE_STYLE_CLASS);
};
return DeterminateIndicator;
}());
function getLineYByXCoord(startLine, endLine, x) {
if (endLine.x === startLine.x)
return 0;
var equationSlope = (endLine.y - startLine.y) / (endLine.x - startLine.x);
var equationYIntercept = startLine.x * (startLine.y - endLine.y) / (endLine.x - startLine.x) + startLine.y;
return Math.round(equationSlope * x + equationYIntercept);
}
var shadowUI$5 = hammerhead__default["default"].shadowUI;
var nativeMethods$b = hammerhead__default["default"].nativeMethods;
var styleUtils$5 = testCafeCore__default["default"].styleUtils;
var FIRST_VALUE_ANIMATION_OPTIONS = {
time: 2800,
points: [0.815, 0.395],
positionByCompletePercent: {
0: { left: -35, right: 100 },
0.6: { left: 100, right: -90 },
1: { left: 100, right: -90 },
},
};
var SECOND_VALUE_ANIMATION_OPTIONS = {
time: 3000,
points: [0.84, 1],
positionByCompletePercent: {
0: { left: -200, right: 100 },
0.6: { left: 107, right: -8 },
1: { left: 107, right: -8 },
},
};
var SECOND_VALUE_ELEMENT_ANIMATION_DELAY = 1000;
var ANIMATION_UPDATE_INTERVAL$1 = 10;
var ANIMATION_RESTART_INTERVAL = 1950;
var ANIMATION_PERCENTS = {
start: 0,
middle: 0.6,
end: 1,
};
var INDETERMINATE_STYLE_CLASS = 'indeterminate';
//Utils
// NOTE: we use Bezier curves to establish a correspondence between
// time and the animation percent. The curve we build by two point.
function getCompletePercent(time, y1, y2) {
return 3 * Math.pow(1 - time, 2) * time * y1 + 3 * (1 - time) * time * time * y2 + time * time * time;
}
function getNewPosition(completePercent, positions) {
var isFirstAnimationPart = completePercent < ANIMATION_PERCENTS.middle;
var startPercent = isFirstAnimationPart ? ANIMATION_PERCENTS.start : ANIMATION_PERCENTS.middle;
var endPercent = isFirstAnimationPart ? ANIMATION_PERCENTS.middle : ANIMATION_PERCENTS.end;
var startPosition = positions[startPercent];
var endPosition = positions[endPercent];
var startPoint = { x: startPercent, y: startPosition.left };
var endPoint = { x: endPercent, y: endPosition.left };
var left = getLineYByXCoord(startPoint, endPoint, completePercent);
startPoint = { x: startPercent, y: startPosition.right };
endPoint = { x: endPercent, y: endPosition.right };
var right = getLineYByXCoord(startPoint, endPoint, completePercent);
return { left: left, right: right };
}
var IndeterminateIndicator = /** @class */ (function () {
function IndeterminateIndicator(progressBar, firstValue, secondValue) {
this.progressBar = progressBar;
this.firstValue = firstValue;
this.secondValue = secondValue;
this.animationInterval = null;
this.secondValueAnimationInterval = null;
this.secondValueAnimationTimeout = null;
this.restartAnimationTimeout = null;
}
IndeterminateIndicator._updateValueAnimation = function (startTime, valueElement, animationOptions) {
var animationTime = animationOptions.time;
var animationPoints = animationOptions.points;
var positions = animationOptions.positionByCompletePercent;
var currentTime = nativeMethods$b.dateNow() - startTime;
var timePercent = currentTime / animationTime;
var completePercent = getCompletePercent(timePercent, animationPoints[0], animationPoints[1]);
var _a = getNewPosition(completePercent, positions), left = _a.left, right = _a.right;
styleUtils$5.set(valueElement, 'left', Math.round(left) + '%');
styleUtils$5.set(valueElement, 'right', Math.round(right) + '%');
};
IndeterminateIndicator.prototype._clearFirstValueAnimation = function () {
if (this.animationInterval) {
nativeMethods$b.clearInterval.call(window, this.animationInterval);
this.animationInterval = null;
}
styleUtils$5.set(this.firstValue, 'left', '-35%');
styleUtils$5.set(this.firstValue, 'right', '100%');
};
IndeterminateIndicator.prototype._clearSecondValueAnimation = function () {
if (this.secondValueAnimationInterval) {
nativeMethods$b.clearInterval.call(window, this.secondValueAnimationInterval);
this.secondValueAnimationInterval = null;
}
styleUtils$5.set(this.secondValue, 'left', '-200%');
styleUtils$5.set(this.secondValue, 'right', '100%');
};
IndeterminateIndicator.prototype._startFirstValueAnimation = function () {
var _this = this;
this._clearFirstValueAnimation();
var startTime = nativeMethods$b.dateNow();
this.animationInterval = nativeMethods$b.setInterval.call(window, function () {
IndeterminateIndicator._updateValueAnimation(startTime, _this.firstValue, FIRST_VALUE_ANIMATION_OPTIONS);
}, ANIMATION_UPDATE_INTERVAL$1);
};
IndeterminateIndicator.prototype._startSecondValueAnimation = function () {
var _this = this;
this._clearSecondValueAnimation();
var startTime = nativeMethods$b.dateNow();
this.secondValueAnimationInterval = nativeMethods$b.setInterval.call(window, function () {
IndeterminateIndicator._updateValueAnimation(startTime, _this.secondValue, SECOND_VALUE_ANIMATION_OPTIONS);
}, ANIMATION_UPDATE_INTERVAL$1);
};
IndeterminateIndicator.prototype._startAnimation = function () {
var _this = this;
this._startFirstValueAnimation();
this.secondValueAnimationTimeout = nativeMethods$b.setTimeout.call(window, function () { return _this._startSecondValueAnimation(); }, SECOND_VALUE_ELEMENT_ANIMATION_DELAY);
this.restartAnimationTimeout = nativeMethods$b.setTimeout.call(window, function () { return _this._startAnimation(); }, ANIMATION_RESTART_INTERVAL);
};
IndeterminateIndicator.prototype._stopAnimation = function () {
this._clearFirstValueAnimation();
this._clearSecondValueAnimation();
if (this.secondValueAnimationTimeout) {
nativeMethods$b.clearInterval.call(window, this.secondValueAnimationTimeout);
this.secondValueAnimationTimeout = null;
}
if (this.restartAnimationTimeout) {
nativeMethods$b.clearInterval.call(window, this.restartAnimationTimeout);
this.restartAnimationTimeout = null;
}
};
IndeterminateIndicator.prototype.start = function () {
shadowUI$5.addClass(this.progressBar, INDETERMINATE_STYLE_CLASS);
this._startAnimation();
};
IndeterminateIndicator.prototype.stop = function () {
shadowUI$5.removeClass(this.progressBar, INDETERMINATE_STYLE_CLASS);
this._stopAnimation();
};
return IndeterminateIndicator;
}());
var shadowUI$4 = hammerhead__default["default"].shadowUI;
var styleUtils$4 = testCafeCore__default["default"].styleUtils;
var PROGRESS_BAR_CLASS = 'progress-bar';
var CONTAINER_CLASS = 'value-container';
var VALUE_CLASS = 'value';
var ProgressBar = /** @class */ (function () {
function ProgressBar(containerElement) {
this.progressBar = null;
this.firstValueElement = null;
this.secondValueElement = null;
this._create(containerElement);
this.determinateIndicator = new DeterminateIndicator(this.progressBar, this.firstValueElement);
this.indeterminateIndicator = new IndeterminateIndicator(this.progressBar, this.firstValueElement, this.secondValueElement);
}
ProgressBar.prototype._create = function (containerElement) {
this.progressBar = document.createElement('div');
shadowUI$4.addClass(this.progressBar, PROGRESS_BAR_CLASS);
containerElement.appendChild(this.progressBar);
var container = document.createElement('div');
shadowUI$4.addClass(container, CONTAINER_CLASS);
this.progressBar.appendChild(container);
this.firstValueElement = document.createElement('div');
shadowUI$4.addClass(this.firstValueElement, VALUE_CLASS);
container.appendChild(this.firstValueElement);
this.secondValueElement = document.createElement('div');
shadowUI$4.addClass(this.secondValueElement, VALUE_CLASS);
container.appendChild(this.secondValueElement);
};
ProgressBar.prototype.show = function () {
styleUtils$4.set(this.progressBar, 'visibility', 'visible');
};
ProgressBar.prototype.hide = function () {
styleUtils$4.set(this.progressBar, 'visibility', 'hidden');
};
return ProgressBar;
}());
var MESSAGES = {
startWaitingElement: 'start-waiting-element',
endWaitingElementRequest: 'end-waiting-element-request',
endWaitingElementResponse: 'end-waiting-element-response',
startWaitingAssertionRetries: 'start-waiting-assertion-retries',
endWaitingAssertionRetriesRequest: 'end-waiting-assertion-retries-request',
endWaitingAssertionRetriesResponse: 'end-waiting-assertion-retries-response',
};
var DEBUG_ACTION = {
step: 'step',
resume: 'resume',
};
function isIframeWindow(window) {
return window.top !== window;
}
var Promise$3 = hammerhead__default["default"].Promise;
var shadowUI$3 = hammerhead__default["default"].shadowUI;
var nativeMethods$a = hammerhead__default["default"].nativeMethods;
var messageSandbox$3 = hammerhead__default["default"].eventSandbox.message;
var browserUtils = hammerhead__default["default"].utils.browser;
var featureDetection$1 = hammerhead__default["default"].utils.featureDetection;
var listeners$2 = hammerhead__default["default"].eventSandbox.listeners;
var styleUtils$3 = testCafeCore__default["default"].styleUtils;
var eventUtils$4 = testCafeCore__default["default"].eventUtils;
var domUtils$a = testCafeCore__default["default"].domUtils;
var serviceUtils$2 = testCafeCore__default["default"].serviceUtils;
var arrayUtils$8 = testCafeCore__default["default"].arrayUtils;
var STATUS_BAR_CLASS = 'status-bar';
var STATUS_BAR_DEBUGGING_CLASS = 'status-bar-debugging';
var ICON_CLASS = 'icon';
var INFO_CONTAINER_CLASS = 'info-container';
var INFO_TEXT_CONTAINER_CLASS = 'info-text-container';
var ACTIONS_CONTAINER_CLASS = 'actions-container';
var FIXTURE_DIV_CLASS = 'fixture';
var STATUS_CONTAINER_CLASS = 'status-container';
var INFO_CLASS = 'info';
var STATUS_DIV_CLASS = 'status';
var USER_AGENT_DIV_CLASS = 'user-agent';
var BUTTONS_CLASS = 'buttons';
var BUTTON_CLASS = 'button';
var BUTTON_ICON_CLASS = 'button-icon';
var LOCKED_BUTTON_CLASS = 'locked';
var UNLOCKED_BUTTON_CLASS = 'unlocked';
var RESUME_BUTTON_CLASS = 'resume';
var STEP_BUTTON_CLASS = 'step';
var FINISH_BUTTON_CLASS = 'finish';
var WAITING_FAILED_CLASS = 'waiting-element-failed';
var WAITING_SUCCESS_CLASS = 'waiting-element-success';
var LOADING_PAGE_TEXT = 'Loading Web Page...';
var WAITING_FOR_ELEMENT_TEXT = 'Waiting for element to appear...';
var WAITING_FOR_ASSERTION_EXECUTION_TEXT = 'Waiting for assertion execution...';
var DEBUGGING_TEXT = 'Debugging test...';
var TEST_FAILED_TEXT = 'Test failed';
var UNLOCK_PAGE_TEXT = 'Unlock Page';
var PAGE_UNLOCKED_TEXT = 'Page unlocked';
var SHOWING_DELAY = 300;
var ANIMATION_DELAY = 500;
var ANIMATION_UPDATE_INTERVAL = 10;
var LOCAL_STORAGE_STATUS_PREFIX_ITEM = '%testCafeStatusPrefix%';
var StatusBar = /** @class */ (function (_super) {
__extends(StatusBar, _super);
function StatusBar(userAgent, fixtureName, testName, contextStorage, nativeAutomation) {
var _this = _super.call(this) || this;
_this.UNLOCK_PAGE_BTN_CLICK = 'testcafe|ui|status-bar|unlock-page-btn-click';
_this.userAgent = userAgent;
_this.fixtureName = fixtureName;
_this.testName = testName;
_this.contextStorage = contextStorage;
_this.nativeAutomation = nativeAutomation;
_this.statusBar = null;
_this.infoContainer = null;
_this.actionsContainer = null;
_this.icon = null;
_this.resumeButton = null;
_this.finishButton = null;
_this.nextButton = null;
_this.statusDiv = null;
_this.buttons = null;
_this.progressBar = null;
_this.animationInterval = null;
_this.showingTimeout = null;
_this.windowHeight = document.documentElement ? styleUtils$3.getHeight(window) : window.innerHeight;
_this.maxHeight = 0;
_this.state = {
created: false,
showing: false,
hiding: false,
debugging: false,
waiting: false,
assertionRetries: false,
hidden: false,
};
_this.currentView = null;
_this._createBeforeReady();
_this._initChildListening();
return _this;
}
Object.defineProperty(StatusBar.prototype, "visibleHeight", {
get: function () {
this.maxHeight = Math.max(this.maxHeight, styleUtils$3.getHeight(this.statusBar));
return this.maxHeight;
},
enumerable: false,
configurable: true
});
StatusBar.prototype._createButton = function (text, className) {
var button = document.createElement('div');
var icon = document.createElement('div');
var span = document.createElement('span');
nativeMethods$a.nodeTextContentSetter.call(span, text);
shadowUI$3.addClass(button, BUTTON_CLASS);
shadowUI$3.addClass(button, className);
shadowUI$3.addClass(icon, BUTTON_ICON_CLASS);
if (browserUtils.isSafari) {
span.style.position = 'relative';
span.style.top = '1px';
}
button.appendChild(icon);
button.appendChild(span);
return button;
};
StatusBar.prototype._createIconArea = function () {
this.icon = document.createElement('div');
shadowUI$3.addClass(this.icon, ICON_CLASS);
this.statusBar.appendChild(this.icon);
};
StatusBar.prototype._createInformationArea = function () {
this.infoContainer = document.createElement('div');
shadowUI$3.addClass(this.infoContainer, INFO_CONTAINER_CLASS);
this.statusBar.appendChild(this.infoContainer);
var infoTextContainer = document.createElement('div');
shadowUI$3.addClass(infoTextContainer, INFO_TEXT_CONTAINER_CLASS);
this.infoContainer.appendChild(infoTextContainer);
var statusContainer = document.createElement('div');
shadowUI$3.addClass(statusContainer, STATUS_CONTAINER_CLASS);
infoTextContainer.appendChild(statusContainer);
this.statusDiv = document.createElement('div');
this.statusDiv = document.createElement('div');
nativeMethods$a.nodeTextContentSetter.call(this.statusDiv, this._getFullStatusText(LOADING_PAGE_TEXT));
shadowUI$3.addClass(this.statusDiv, STATUS_DIV_CLASS);
shadowUI$3.addClass(this.statusDiv, INFO_CLASS);
statusContainer.appendChild(this.statusDiv);
var fixtureDiv = document.createElement('div');
nativeMethods$a.nodeTextContentSetter.call(fixtureDiv, "".concat(this.fixtureName, " - ").concat(this.testName));
shadowUI$3.addClass(fixtureDiv, FIXTURE_DIV_CLASS);
shadowUI$3.addClass(fixtureDiv, INFO_CLASS);
statusContainer.appendChild(fixtureDiv);
var userAgentDiv = document.createElement('div');
nativeMethods$a.nodeTextContentSetter.call(userAgentDiv, this.userAgent);
shadowUI$3.addClass(userAgentDiv, USER_AGENT_DIV_CLASS);
infoTextC