Innovenergy_trunk/frontend/node_modules/testcafe/lib/test-run/bookmark.js

133 lines
20 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 phase_1 = __importDefault(require("../test-run/phase"));
const types_1 = require("../errors/types");
const testcafe_hammerhead_1 = require("testcafe-hammerhead");
const actions_1 = require("./commands/actions");
const test_run_1 = require("../errors/test-run");
const default_values_1 = require("../configuration/default-values");
class TestRunBookmark {
constructor(testRun, role) {
this.testRun = testRun;
this.role = role;
this.url = testcafe_hammerhead_1.SPECIAL_BLANK_PAGE;
this.ctx = null;
this.fixtureCtx = null;
this.dialogHandler = null;
this.iframeSelector = null;
this.speed = default_values_1.DEFAULT_SPEED_VALUE;
this.pageLoadTimeout = 0;
this.consoleMessages = null;
this.dialogHandler = this.testRun.activeDialogHandler;
this.iframeSelector = this.testRun.activeIframeSelector;
this.speed = this.testRun.speed;
this.pageLoadTimeout = this.testRun.pageLoadTimeout;
this.consoleMessages = this.testRun.consoleMessages;
}
async _initCtxs() {
if (this.testRun.compilerService) {
this.ctx = await this.testRun.compilerService.getCtx({ testRunId: this.testRun.id });
this.fixtureCtx = await this.testRun.compilerService.getFixtureCtx({ testRunId: this.testRun.id });
}
else {
this.ctx = this.testRun.ctx;
this.fixtureCtx = this.testRun.fixtureCtx;
}
}
async _restoreCtxs() {
if (this.testRun.compilerService) {
await this.testRun.compilerService.setCtx({
testRunId: this.testRun.id,
value: this.ctx,
});
await this.testRun.compilerService.setFixtureCtx({
testRunId: this.testRun.id,
value: this.fixtureCtx,
});
}
else {
this.testRun.ctx = this.ctx;
this.testRun.fixtureCtx = this.fixtureCtx;
}
}
async init() {
await this._initCtxs();
if (this.testRun.activeIframeSelector)
await this.testRun.executeCommand(new actions_1.SwitchToMainWindowCommand());
if (!this.role.opts.preserveUrl)
await this.role.setCurrentUrlAsRedirectUrl(this.testRun);
}
async _restoreDialogHandler() {
if (this.testRun.activeDialogHandler !== this.dialogHandler) {
const restoreDialogCommand = new actions_1.SetNativeDialogHandlerCommand({ dialogHandler: { fn: this.dialogHandler } });
await this.testRun.executeCommand(restoreDialogCommand);
}
}
async _restoreSpeed() {
if (this.testRun.speed !== this.speed) {
const restoreSpeedCommand = new actions_1.SetTestSpeedCommand({ speed: this.speed });
await this.testRun.executeCommand(restoreSpeedCommand);
}
}
async _restorePageLoadTimeout() {
if (this.testRun.pageLoadTimeout !== this.pageLoadTimeout) {
const restorePageLoadTimeoutCommand = new actions_1.SetPageLoadTimeoutCommand({ duration: this.pageLoadTimeout });
await this.testRun.executeCommand(restorePageLoadTimeoutCommand);
}
}
async _restoreWorkingFrame() {
if (this.testRun.activeIframeSelector !== this.iframeSelector) {
const switchWorkingFrameCommand = this.iframeSelector ?
new actions_1.SwitchToIframeCommand({ selector: this.iframeSelector }) :
new actions_1.SwitchToMainWindowCommand();
try {
await this.testRun.executeCommand(switchWorkingFrameCommand);
}
catch (err) {
if (err.code === types_1.TEST_RUN_ERRORS.actionElementNotFoundError)
throw new test_run_1.CurrentIframeNotFoundError();
if (err.code === types_1.TEST_RUN_ERRORS.actionIframeIsNotLoadedError)
throw new test_run_1.CurrentIframeIsNotLoadedError();
throw err;
}
}
}
async _restorePage(url, stateSnapshot) {
await this.testRun.navigateToUrl(url, true, JSON.stringify(stateSnapshot));
}
_setConsoleMessages() {
this.testRun.consoleMessages = this.consoleMessages;
}
_setPhase(value) {
this.testRun.phase = value;
}
async restore(callsite, stateSnapshot) {
const prevPhase = await this.testRun.phase;
this._setPhase(phase_1.default.inBookmarkRestore);
await this._restoreCtxs();
this._setConsoleMessages();
try {
await this._restoreSpeed();
await this._restorePageLoadTimeout();
await this._restoreDialogHandler();
const preserveUrl = this.role.opts.preserveUrl;
const redirectUrl = preserveUrl
? this.role.redirectUrl
: this.role.redirectUrl[this.testRun.test.id];
await this._restorePage(redirectUrl, stateSnapshot);
if (!preserveUrl)
await this._restoreWorkingFrame();
}
catch (err) {
err.callsite = callsite;
throw err;
}
this._setPhase(prevPhase);
}
}
exports.default = TestRunBookmark;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYm9va21hcmsuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGVzdC1ydW4vYm9va21hcmsudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSw4REFBK0M7QUFDL0MsMkNBQWtEO0FBQ2xELDZEQUF3RTtBQUV4RSxnREFNNEI7QUFFNUIsaURBQStGO0FBSS9GLG9FQUFzRTtBQUt0RSxNQUFxQixlQUFlO0lBWWhDLFlBQW9CLE9BQWdCLEVBQUUsSUFBVTtRQUM1QyxJQUFJLENBQUMsT0FBTyxHQUFXLE9BQU8sQ0FBQztRQUMvQixJQUFJLENBQUMsSUFBSSxHQUFjLElBQUksQ0FBQztRQUM1QixJQUFJLENBQUMsR0FBRyxHQUFlLHdDQUFrQixDQUFDO1FBQzFDLElBQUksQ0FBQyxHQUFHLEdBQWUsSUFBSSxDQUFDO1FBQzVCLElBQUksQ0FBQyxVQUFVLEdBQVEsSUFBSSxDQUFDO1FBQzVCLElBQUksQ0FBQyxhQUFhLEdBQUssSUFBSSxDQUFDO1FBQzVCLElBQUksQ0FBQyxjQUFjLEdBQUksSUFBSSxDQUFDO1FBQzVCLElBQUksQ0FBQyxLQUFLLEdBQWEsb0NBQW1CLENBQUM7UUFDM0MsSUFBSSxDQUFDLGVBQWUsR0FBRyxDQUFDLENBQUM7UUFDekIsSUFBSSxDQUFDLGVBQWUsR0FBRyxJQUFJLENBQUM7UUFDNUIsSUFBSSxDQUFDLGFBQWEsR0FBSyxJQUFJLENBQUMsT0FBTyxDQUFDLG1CQUFtQixDQUFDO1FBQ3hELElBQUksQ0FBQyxjQUFjLEdBQUksSUFBSSxDQUFDLE9BQU8sQ0FBQyxvQkF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