Innovenergy_trunk/frontend/node_modules/testcafe/lib/test-run/browser-manipulation-queue.js

99 lines
15 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const device_specs_1 = require("device-specs");
const utils_1 = require("./commands/utils");
const type_1 = __importDefault(require("./commands/type"));
const warning_message_1 = __importDefault(require("../notifications/warning-message"));
const test_run_1 = require("../errors/test-run/");
class BrowserManipulationQueue {
constructor(browserConnection, screenshotCapturer, warningLog) {
this.commands = [];
this.browserId = browserConnection.id;
this.browserProvider = browserConnection.provider;
this.screenshotCapturer = screenshotCapturer;
this.warningLog = warningLog;
}
async _resizeWindow(width, height, currentWidth, currentHeight) {
const canResizeWindow = await this.browserProvider.canResizeWindowToDimensions(this.browserId, width, height);
if (!canResizeWindow)
throw new test_run_1.WindowDimensionsOverflowError();
try {
return await this.browserProvider.resizeWindow(this.browserId, width, height, currentWidth, currentHeight);
}
catch (err) {
this.warningLog.addWarning(warning_message_1.default.resizeError, err.message);
return null;
}
}
async _resizeWindowToFitDevice(device, portrait, currentWidth, currentHeight) {
const { landscapeWidth, portraitWidth } = (0, device_specs_1.getViewportSize)(device);
const width = portrait ? portraitWidth : landscapeWidth;
const height = portrait ? landscapeWidth : portraitWidth;
return await this._resizeWindow(width, height, currentWidth, currentHeight);
}
async _maximizeWindow() {
try {
return await this.browserProvider.maximizeWindow(this.browserId);
}
catch (err) {
this.warningLog.addWarning(warning_message_1.default.maximizeError, err.message);
return null;
}
}
async _takeScreenshot(capture) {
return capture();
}
async _executeCommand(driverMsg) {
const command = this.commands.shift();
switch (command.type) {
case type_1.default.takeElementScreenshot:
case type_1.default.takeScreenshot:
return await this._takeScreenshot(() => this.screenshotCapturer.captureAction({
actionId: command.actionId,
customPath: command.path,
pageDimensions: driverMsg.pageDimensions,
cropDimensions: driverMsg.cropDimensions,
markSeed: command.markSeed,
fullPage: command.fullPage,
thumbnails: command.thumbnails,
}));
case type_1.default.takeScreenshotOnFail:
return await this._takeScreenshot(() => this.screenshotCapturer.captureError({
actionId: command.actionId,
failedActionId: command.failedActionId,
pageDimensions: driverMsg.pageDimensions,
markSeed: command.markSeed,
fullPage: command.fullPage,
}));
case type_1.default.resizeWindow:
return await this._resizeWindow(command.width, command.height, driverMsg.pageDimensions.innerWidth, driverMsg.pageDimensions.innerHeight);
case type_1.default.resizeWindowToFitDevice:
return await this._resizeWindowToFitDevice(command.device, command.options.portraitOrientation, driverMsg.pageDimensions.innerWidth, driverMsg.pageDimensions.innerHeight);
case type_1.default.maximizeWindow:
return await this._maximizeWindow();
}
return null;
}
async executePendingManipulation(driverMsg, messageBus) {
const command = this.commands[0];
const handleBrowserManipulationWarning = warning => {
warning.actionId = warning.actionId || command.actionId;
};
messageBus.on('before-warning-add', handleBrowserManipulationWarning);
const result = await this._executeCommand(driverMsg);
messageBus.off('before-warning-add', handleBrowserManipulationWarning);
return result;
}
push(command) {
this.commands.push(command);
}
removeAllNonServiceManipulations() {
this.commands = this.commands.filter(command => (0, utils_1.isServiceCommand)(command));
}
}
exports.default = BrowserManipulationQueue;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJvd3Nlci1tYW5pcHVsYXRpb24tcXVldWUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGVzdC1ydW4vYnJvd3Nlci1tYW5pcHVsYXRpb24tcXVldWUuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSwrQ0FBK0M7QUFDL0MsNENBQW9EO0FBQ3BELDJEQUEyQztBQUMzQyx1RkFBK0Q7QUFDL0Qsa0RBQW9FO0FBRXBFLE1BQXFCLHdCQUF3QjtJQUN6QyxZQUFhLGlCQUFpQixFQUFFLGtCQUFrQixFQUFFLFVBQVU7UUFDMUQsSUFBSSxDQUFDLFFB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