How to use executeNavigateTo method in Testcafe

Best JavaScript code snippet using testcafe

index.js

Source:index.js Github

copy

Full Screen

...3201 var manipulationExecutor = new ManipulationExecutor(command, globalSelectorTimeout, statusBar);3202 return manipulationExecutor.execute();3203 }3204 var createNativeXHR = hammerhead__default.createNativeXHR, utils = hammerhead__default.utils;3205 function executeNavigateTo(command) {3206 var navigationUrl = utils.url.getNavigationUrl(command.url, window);3207 var ensurePagePromise = hammerhead__default.Promise.resolve();3208 if (navigationUrl && testCafeCore.browser.isRetryingTestPagesEnabled())3209 ensurePagePromise = testCafeCore.browser.fetchPageToCache(navigationUrl, createNativeXHR);3210 return ensurePagePromise3211 .then(function () {3212 var requestBarrier = new testCafeCore.RequestBarrier();3213 hammerhead__default.navigateTo(command.url, command.forceReload);3214 return hammerhead__default.Promise.all([requestBarrier.wait(), testCafeCore.pageUnloadBarrier.wait()]);3215 })3216 .then(function () { return new DriverStatus({ isCommandResult: true }); })3217 .catch(function (err) { return new DriverStatus({ isCommandResult: true, executionError: err }); });3218 }3219 function getResult(command, globalTimeout, startTime, createNotFoundError, createIsInvisibleError, statusBar) {3220 var selectorExecutor = new SelectorExecutor(command, globalTimeout, startTime, createNotFoundError, createIsInvisibleError);3221 statusBar.showWaitingElementStatus(selectorExecutor.timeout);3222 return selectorExecutor.getResult()3223 .then(function (el) {3224 return statusBar.hideWaitingElementStatus(!!el)3225 .then(function () { return el; });3226 })3227 .catch(function (err) {3228 return statusBar.hideWaitingElementStatus(false)3229 .then(function () {3230 throw err;3231 });3232 });3233 }3234 function getResultDriverStatus(command, globalTimeout, startTime, createNotFoundError, createIsInvisibleError, statusBar) {3235 var selectorExecutor = new SelectorExecutor(command, globalTimeout, startTime, createNotFoundError, createIsInvisibleError);3236 statusBar.showWaitingElementStatus(selectorExecutor.timeout);3237 return selectorExecutor.getResultDriverStatus()3238 .then(function (status) {3239 return statusBar.hideWaitingElementStatus(!!status.result)3240 .then(function () { return status; });3241 });3242 }3243 var Promise$1 = hammerhead__default.Promise;3244 function executeChildWindowDriverLinkSelector(selector, childWindowLinks) {3245 if (typeof selector === 'string') {3246 var foundChildWindowDriverLink = testCafeCore.arrayUtils.find(childWindowLinks, function (link) { return link.windowId === selector; });3247 if (!foundChildWindowDriverLink) {3248 var error = new ChildWindowNotFoundError();3249 return Promise$1.reject(error);3250 }3251 // NOTE: We cannot pass the driver window of the found child window driver link3252 // because the current Promise implementation checks the type of the value passed to the 'resolve' function.3253 // It causes an unhandled JavaScript error on accessing to cross-domain iframe.3254 return Promise$1.resolve(foundChildWindowDriverLink);3255 }3256 // TODO: Query url and title properties of the all driverLinks' windows3257 return Promise$1.resolve(null);3258 }3259 var ChildWindowDriverLink = /** @class */ (function () {3260 function ChildWindowDriverLink(driverWindow, windowId) {3261 this.driverWindow = driverWindow;3262 this.windowId = windowId;3263 }3264 ChildWindowDriverLink.prototype.setAsMaster = function () {3265 var msg = new SetAsMasterMessage();3266 return sendMessageToDriver(msg, this.driverWindow, WAIT_FOR_WINDOW_DRIVER_RESPONSE_TIMEOUT, CannotSwitchToWindowError);3267 };3268 ChildWindowDriverLink.prototype.closeAllChildWindows = function () {3269 var msg = new CloseAllChildWindowsMessage();3270 return sendMessageToDriver(msg, this.driverWindow, WAIT_FOR_WINDOW_DRIVER_RESPONSE_TIMEOUT, CloseChildWindowError);3271 };3272 return ChildWindowDriverLink;3273 }());3274 var ParentWindowDriverLink = /** @class */ (function () {3275 function ParentWindowDriverLink(currentDriverWindow) {3276 this.currentDriverWindow = currentDriverWindow;3277 }3278 ParentWindowDriverLink.prototype._getTopOpenedWindow = function (wnd) {3279 var topOpened = wnd;3280 while (topOpened.opener)3281 topOpened = topOpened.opener;3282 return topOpened;3283 };3284 ParentWindowDriverLink.prototype._setAsMaster = function (wnd) {3285 var msg = new SetAsMasterMessage();3286 return sendMessageToDriver(msg, wnd, WAIT_FOR_WINDOW_DRIVER_RESPONSE_TIMEOUT, CannotSwitchToWindowError);3287 };3288 ParentWindowDriverLink.prototype.setTopOpenedWindowAsMaster = function () {3289 var wnd = this._getTopOpenedWindow(this.currentDriverWindow);3290 return this._setAsMaster(wnd);3291 };3292 ParentWindowDriverLink.prototype.setParentWindowAsMaster = function () {3293 var wnd = this.currentDriverWindow.opener;3294 return this._setAsMaster(wnd);3295 };3296 return ParentWindowDriverLink;3297 }());3298 var DriverRole = {3299 master: 'master',3300 replica: 'replica'3301 };3302 var transport = hammerhead__default.transport;3303 var Promise$2 = hammerhead__default.Promise;3304 var messageSandbox$2 = hammerhead__default.eventSandbox.message;3305 var storages = hammerhead__default.storages;3306 var nativeMethods$4 = hammerhead__default.nativeMethods;3307 var DateCtor = nativeMethods$4.date;3308 var TEST_DONE_SENT_FLAG = 'testcafe|driver|test-done-sent-flag';3309 var PENDING_STATUS = 'testcafe|driver|pending-status';3310 var EXECUTING_CLIENT_FUNCTION_DESCRIPTOR = 'testcafe|driver|executing-client-function-descriptor';3311 var SELECTOR_EXECUTION_START_TIME = 'testcafe|driver|selector-execution-start-time';3312 var PENDING_PAGE_ERROR = 'testcafe|driver|pending-page-error';3313 var ACTIVE_IFRAME_SELECTOR = 'testcafe|driver|active-iframe-selector';3314 var TEST_SPEED = 'testcafe|driver|test-speed';3315 var ASSERTION_RETRIES_TIMEOUT = 'testcafe|driver|assertion-retries-timeout';3316 var ASSERTION_RETRIES_START_TIME = 'testcafe|driver|assertion-retries-start-time';3317 var CONSOLE_MESSAGES = 'testcafe|driver|console-messages';3318 var ACTION_IFRAME_ERROR_CTORS = {3319 NotLoadedError: ActionIframeIsNotLoadedError,3320 NotFoundError: ActionElementNotFoundError,3321 IsInvisibleError: ActionElementIsInvisibleError3322 };3323 var CURRENT_IFRAME_ERROR_CTORS = {3324 NotLoadedError: CurrentIframeIsNotLoadedError,3325 NotFoundError: CurrentIframeNotFoundError,3326 IsInvisibleError: CurrentIframeIsInvisibleError3327 };3328 var COMMAND_EXECUTION_MAX_TIMEOUT = Math.pow(2, 31) - 1;3329 var EMPTY_COMMAND_EVENT_WAIT_TIMEOUT = 30 * 1000;3330 var STATUS_WITH_COMMAND_RESULT_EVENT = 'status-with-command-result-event';3331 var EMPTY_COMMAND_EVENT = 'empty-command-event';3332 var Driver = /** @class */ (function (_super) {3333 __extends(Driver, _super);3334 function Driver(testRunId, communicationUrls, runInfo, options) {3335 var _this = _super.call(this) || this;3336 _this.COMMAND_EXECUTING_FLAG = 'testcafe|driver|command-executing-flag';3337 _this.EXECUTING_IN_IFRAME_FLAG = 'testcafe|driver|executing-in-iframe-flag';3338 _this.PENDING_WINDOW_SWITCHING_FLAG = 'testcafe|driver|pending-window-switching-flag';3339 _this.testRunId = testRunId;3340 _this.heartbeatUrl = communicationUrls.heartbeat;3341 _this.browserStatusUrl = communicationUrls.status;3342 _this.browserStatusDoneUrl = communicationUrls.statusDone;3343 _this.browserActiveWindowId = communicationUrls.activeWindowId;3344 _this.userAgent = runInfo.userAgent;3345 _this.fixtureName = runInfo.fixtureName;3346 _this.testName = runInfo.testName;3347 _this.selectorTimeout = options.selectorTimeout;3348 _this.pageLoadTimeout = options.pageLoadTimeout;3349 _this.childWindowReadyTimeout = options.childWindowReadyTimeout;3350 _this.initialSpeed = options.speed;3351 _this.skipJsErrors = options.skipJsErrors;3352 _this.dialogHandler = options.dialogHandler;3353 _this.customCommandHandlers = {};3354 _this.contextStorage = null;3355 _this.nativeDialogsTracker = null;3356 _this.childIframeDriverLinks = [];3357 _this.activeChildIframeDriverLink = null;3358 _this.childWindowDriverLinks = [];3359 _this.parentWindowDriverLink = null;3360 _this.statusBar = null;3361 _this.windowId = _this._getCurrentWindowId();3362 _this.role = DriverRole.replica;3363 _this.setAsMasterInProgress = false;3364 _this.checkClosedChildWindowIntervalId = null;3365 if (options.retryTestPages)3366 testCafeCore.browser.enableRetryingTestPages();3367 _this.pageInitialRequestBarrier = new testCafeCore.RequestBarrier();3368 _this.readyPromise = testCafeCore.eventUtils3369 .documentReady(_this.pageLoadTimeout)3370 .then(function () { return _this.pageInitialRequestBarrier.wait(true); });3371 _this._initChildDriverListening();3372 testCafeCore.pageUnloadBarrier.init();3373 testCafeCore.preventRealEvents();3374 hammerhead__default.on(hammerhead__default.EVENTS.uncaughtJsError, function (err) { return _this._onJsError(err); });3375 hammerhead__default.on(hammerhead__default.EVENTS.unhandledRejection, function (err) { return _this._onJsError(err); });3376 hammerhead__default.on(hammerhead__default.EVENTS.consoleMethCalled, function (e) { return _this._onConsoleMessage(e); });3377 hammerhead__default.on(hammerhead__default.EVENTS.beforeFormSubmit, function (e) { return _this._onFormSubmit(e); });3378 hammerhead__default.on(hammerhead__default.EVENTS.windowOpened, function (e) { return _this._onChildWindowOpened(e); });3379 _this.setCustomCommandHandlers(COMMAND_TYPE.unlockPage, function () { return _this._unlockPageAfterTestIsDone(); });3380 return _this;3381 }3382 Object.defineProperty(Driver.prototype, "speed", {3383 get: function () {3384 return this.contextStorage.getItem(TEST_SPEED);3385 },3386 set: function (val) {3387 this.contextStorage.setItem(TEST_SPEED, val);3388 },3389 enumerable: true,3390 configurable: true3391 });3392 Object.defineProperty(Driver.prototype, "consoleMessages", {3393 get: function () {3394 return new BrowserConsoleMessages(this.contextStorage.getItem(CONSOLE_MESSAGES));3395 },3396 set: function (messages) {3397 return this.contextStorage.setItem(CONSOLE_MESSAGES, messages ? messages.getCopy() : null);3398 },3399 enumerable: true,3400 configurable: true3401 });3402 Driver.prototype._hasPendingActionFlags = function (contextStorage) {3403 return contextStorage.getItem(this.COMMAND_EXECUTING_FLAG) ||3404 contextStorage.getItem(this.EXECUTING_IN_IFRAME_FLAG);3405 };3406 Driver.prototype._getCurrentWindowId = function () {3407 var currentUrl = window.location.toString();3408 var parsedProxyUrl = hammerhead__default.utils.url.parseProxyUrl(currentUrl);3409 return parsedProxyUrl && parsedProxyUrl.windowId || null;3410 };3411 // Error handling3412 Driver.prototype._onJsError = function (err) {3413 // NOTE: we should not send any message to the server if we've3414 // sent the 'test-done' message but haven't got the response.3415 if (this.skipJsErrors || this.contextStorage.getItem(TEST_DONE_SENT_FLAG))3416 return Promise$2.resolve();3417 var error = new UncaughtErrorOnPage(err.stack, err.pageUrl);3418 if (!this.contextStorage.getItem(PENDING_PAGE_ERROR))3419 this.contextStorage.setItem(PENDING_PAGE_ERROR, error);3420 return null;3421 };3422 Driver.prototype._unlockPageAfterTestIsDone = function () {3423 testCafeCore.disableRealEventsPreventing();3424 return Promise$2.resolve();3425 };3426 Driver.prototype._failIfClientCodeExecutionIsInterrupted = function () {3427 // NOTE: ClientFunction should be used primarily for observation. We raise3428 // an error if the page was reloaded during ClientFunction execution.3429 var executingClientFnDescriptor = this.contextStorage.getItem(EXECUTING_CLIENT_FUNCTION_DESCRIPTOR);3430 if (executingClientFnDescriptor) {3431 this._onReady(new DriverStatus({3432 isCommandResult: true,3433 executionError: new ClientFunctionExecutionInterruptionError(executingClientFnDescriptor.instantiationCallsiteName)3434 }));3435 return true;3436 }3437 return false;3438 };3439 Driver.prototype.onCustomClientScriptError = function (err, moduleName) {3440 var error = moduleName3441 ? new UncaughtErrorInCustomClientScriptLoadedFromModule(err, moduleName)3442 : new UncaughtErrorInCustomClientScriptCode(err);3443 if (!this.contextStorage.getItem(PENDING_PAGE_ERROR))3444 this.contextStorage.setItem(PENDING_PAGE_ERROR, error);3445 };3446 Driver.prototype._addChildWindowDriverLink = function (e) {3447 var childWindowDriverLink = new ChildWindowDriverLink(e.window, e.windowId);3448 this.childWindowDriverLinks.push(childWindowDriverLink);3449 this._ensureClosedChildWindowWatcher();3450 };3451 Driver.prototype._ensureClosedChildWindowWatcher = function () {3452 var _this = this;3453 if (this.checkClosedChildWindowIntervalId)3454 return;3455 this.checkClosedChildWindowIntervalId = nativeMethods$4.setInterval.call(window, function () {3456 var firstClosedChildWindowDriverLink = testCafeCore.arrayUtils.find(_this.childWindowDriverLinks, function (childWindowDriverLink) { return childWindowDriverLink.driverWindow.closed; });3457 if (!firstClosedChildWindowDriverLink)3458 return;3459 testCafeCore.arrayUtils.remove(_this.childWindowDriverLinks, firstClosedChildWindowDriverLink);3460 _this._setCurrentWindowAsMaster();3461 if (!_this.childWindowDriverLinks.length)3462 nativeMethods$4.clearInterval.call(window, _this.checkClosedChildWindowIntervalId);3463 }, CHECK_CHILD_WINDOW_CLOSED_INTERVAL);3464 };3465 Driver.prototype._setAsMasterInProgressOrCompleted = function () {3466 return this.setAsMasterInProgress || this.role === DriverRole.master;3467 };3468 Driver.prototype._setCurrentWindowAsMaster = function () {3469 var _this = this;3470 if (this._setAsMasterInProgressOrCompleted())3471 return;3472 this.setAsMasterInProgress = true;3473 Promise$2.resolve()3474 .then(function () {3475 return testCafeCore.browser.setActiveWindowId(_this.browserActiveWindowId, hammerhead__default.createNativeXHR, _this.windowId);3476 })3477 .then(function () {3478 _this._startInternal({3479 finalizePendingCommand: true,3480 isFirstRequestAfterWindowSwitching: true3481 });3482 _this.setAsMasterInProgress = false;3483 })3484 .catch(function () {3485 _this._onReady(new DriverStatus({3486 isCommandResult: true,3487 executionError: new CannotSwitchToWindowError()3488 }));3489 });3490 };3491 Driver.prototype._onChildWindowOpened = function (e) {3492 this._addChildWindowDriverLink(e);3493 this._switchToChildWindow(e.windowId);3494 };3495 // HACK: For https://github.com/DevExpress/testcafe/issues/35603496 // We have to cancel every form submit after a test is done3497 // to prevent requests to a closed session3498 Driver.prototype._onFormSubmit = function (e) {3499 // NOTE: We need to refactor this code to avoid the undefined value in contextStorage3500 // https://github.com/DevExpress/testcafe/issues/43603501 if (this.contextStorage && this.contextStorage.getItem(TEST_DONE_SENT_FLAG))3502 e.preventSubmit = true;3503 };3504 // Console messages3505 Driver.prototype._onConsoleMessage = function (_a) {3506 var meth = _a.meth, line = _a.line;3507 var messages = this.consoleMessages;3508 messages.addMessage(meth, line, this.windowId);3509 this.consoleMessages = messages;3510 };3511 // Status3512 Driver.prototype._addPendingErrorToStatus = function (status) {3513 var pendingPageError = this.contextStorage.getItem(PENDING_PAGE_ERROR);3514 if (pendingPageError) {3515 this.contextStorage.setItem(PENDING_PAGE_ERROR, null);3516 status.pageError = pendingPageError;3517 }3518 };3519 Driver.prototype._addUnexpectedDialogErrorToStatus = function (status) {3520 var dialogError = this.nativeDialogsTracker.getUnexpectedDialogError();3521 status.pageError = status.pageError || dialogError;3522 };3523 Driver.prototype._addConsoleMessagesToStatus = function (status) {3524 status.consoleMessages = this.consoleMessages;3525 this.consoleMessages = null;3526 };3527 Driver.prototype._addPendingWindowSwitchingStateToStatus = function (status) {3528 status.isPendingWindowSwitching = !!this.contextStorage.getItem(this.PENDING_WINDOW_SWITCHING_FLAG);3529 };3530 Driver.prototype._sendStatusRequest = function (status) {3531 var statusRequestOptions = {3532 cmd: TEST_RUN_MESSAGES.ready,3533 status: status,3534 disableResending: true,3535 allowRejecting: true3536 };3537 var requestAttempt = function () { return testCafeCore.getTimeLimitedPromise(transport.asyncServiceMsg(statusRequestOptions), SEND_STATUS_REQUEST_TIME_LIMIT); };3538 var retryRequest = function () { return testCafeCore.delay(SEND_STATUS_REQUEST_RETRY_DELAY).then(requestAttempt); };3539 var statusPromise = requestAttempt();3540 for (var i = 0; i < SEND_STATUS_REQUEST_RETRY_COUNT; i++)3541 statusPromise = statusPromise.catch(retryRequest);3542 return statusPromise;3543 };3544 Driver.prototype._sendStatus = function (status) {3545 var _this = this;3546 // NOTE: We should not modify the status if it is resent after3547 // the page load because the server has cached the response3548 if (!status.resent) {3549 this._addPendingErrorToStatus(status);3550 this._addUnexpectedDialogErrorToStatus(status);3551 this._addConsoleMessagesToStatus(status);3552 this._addPendingWindowSwitchingStateToStatus(status);3553 }3554 this.contextStorage.setItem(PENDING_STATUS, status);3555 var readyCommandResponse = null;3556 // NOTE: postpone status sending if the page is unloading3557 return testCafeCore.pageUnloadBarrier3558 .wait(0)3559 .then(function () { return _this._sendStatusRequest(status); })3560 //NOTE: do not execute the next command if the page is unloading3561 .then(function (res) {3562 readyCommandResponse = res;3563 return testCafeCore.pageUnloadBarrier.wait(0);3564 })3565 .then(function () {3566 _this.contextStorage.setItem(PENDING_STATUS, null);3567 return readyCommandResponse;3568 });3569 };3570 // Iframes and child windows interaction3571 Driver.prototype._addChildIframeDriverLink = function (id, driverWindow) {3572 var childIframeDriverLink = this._getChildIframeDriverLinkByWindow(driverWindow);3573 if (!childIframeDriverLink) {3574 var driverId = this.testRunId + "-" + generateId();3575 childIframeDriverLink = new ChildIframeDriverLink(driverWindow, driverId);3576 this.childIframeDriverLinks.push(childIframeDriverLink);3577 }3578 childIframeDriverLink.sendConfirmationMessage(id);3579 };3580 Driver.prototype._handleSetAsMasterMessage = function (msg, wnd) {3581 var _this = this;3582 // NOTE: The 'setAsMaster' message can be send a few times because3583 // the 'sendMessageToDriver' function resend messages if the message confirmation is not received in 1 sec.3584 // This message can be send even after driver is started.3585 if (this._setAsMasterInProgressOrCompleted())3586 return;3587 this.setAsMasterInProgress = true;3588 sendConfirmationMessage({3589 requestMsgId: msg.id,3590 window: wnd3591 });3592 Promise$2.resolve()3593 .then(function () {3594 return testCafeCore.browser.setActiveWindowId(_this.browserActiveWindowId, hammerhead__default.createNativeXHR, _this.windowId);3595 })3596 .then(function () {3597 _this._startInternal();3598 _this.setAsMasterInProgress = false;3599 })3600 .catch(function () {3601 _this._onReady(new DriverStatus({3602 isCommandResult: true,3603 executionError: new CannotSwitchToWindowError()3604 }));3605 });3606 };3607 Driver.prototype._handleCloseAllWindowsMessage = function (msg, wnd) {3608 var _this = this;3609 this._closeAllChildWindows()3610 .then(function () {3611 sendConfirmationMessage({3612 requestMsgId: msg.id,3613 window: wnd3614 });3615 })3616 .catch(function () {3617 _this._onReady(new DriverStatus({3618 isCommandResult: true,3619 executionError: new CloseChildWindowError()3620 }));3621 });3622 };3623 Driver.prototype._initChildDriverListening = function () {3624 var _this = this;3625 messageSandbox$2.on(messageSandbox$2.SERVICE_MSG_RECEIVED_EVENT, function (e) {3626 var msg = e.message;3627 var window = e.source;3628 if (msg.type === TYPE.establishConnection)3629 _this._addChildIframeDriverLink(msg.id, window);3630 else if (msg.type === TYPE.setAsMaster)3631 _this._handleSetAsMasterMessage(msg, window);3632 else if (msg.type === TYPE.closeAllChildWindows)3633 _this._handleCloseAllWindowsMessage(msg, window);3634 });3635 };3636 Driver.prototype._getChildIframeDriverLinkByWindow = function (driverWindow) {3637 return testCafeCore.arrayUtils.find(this.childIframeDriverLinks, function (link) { return link.driverWindow === driverWindow; });3638 };3639 Driver.prototype._getChildWindowDriverLinkByWindow = function (childDriverWindow) {3640 return testCafeCore.arrayUtils.find(this.childWindowDriverLinks, function (link) { return link.driverWindow === childDriverWindow; });3641 };3642 Driver.prototype._runInActiveIframe = function (command) {3643 var _this = this;3644 var runningChain = Promise$2.resolve();3645 var activeIframeSelector = this.contextStorage.getItem(ACTIVE_IFRAME_SELECTOR);3646 // NOTE: if the page was reloaded we restore the active child driver link via the iframe selector3647 if (!this.activeChildIframeDriverLink && activeIframeSelector)3648 runningChain = this._switchToIframe(activeIframeSelector, CURRENT_IFRAME_ERROR_CTORS);3649 runningChain3650 .then(function () {3651 _this.contextStorage.setItem(_this.EXECUTING_IN_IFRAME_FLAG, true);3652 return _this.activeChildIframeDriverLink.executeCommand(command, _this.speed);3653 })3654 .then(function (status) { return _this._onCommandExecutedInIframe(status); })3655 .catch(function (err) { return _this._onCommandExecutedInIframe(new DriverStatus({3656 isCommandResult: true,3657 executionError: err3658 })); });3659 };3660 Driver.prototype._onCommandExecutedInIframe = function (status) {3661 this.contextStorage.setItem(this.EXECUTING_IN_IFRAME_FLAG, false);3662 this._onReady(status);3663 };3664 Driver.prototype._ensureChildIframeDriverLink = function (iframeWindow, ErrorCtor, selectorTimeout) {3665 var _this = this;3666 // NOTE: a child iframe driver should establish connection with the parent when it's loaded.3667 // Here we are waiting while the appropriate child iframe driver do this if it didn't do yet.3668 return testCafeCore.waitFor(function () { return _this._getChildIframeDriverLinkByWindow(iframeWindow); }, CHECK_IFRAME_DRIVER_LINK_DELAY, selectorTimeout)3669 .catch(function () {3670 throw new ErrorCtor();3671 });3672 };3673 Driver.prototype._ensureChildWindowDriverLink = function (childWindow, ErrorCtor, timeout) {3674 var _this = this;3675 // NOTE: a child window driver should establish connection with the parent when it's loaded.3676 // Here we are waiting while the appropriate child window driver do this if it didn't do yet.3677 return testCafeCore.waitFor(function () { return _this._getChildWindowDriverLinkByWindow(childWindow); }, CHECK_CHILD_WINDOW_DRIVER_LINK_DELAY, timeout)3678 .catch(function () {3679 throw new ErrorCtor();3680 });3681 };3682 Driver.prototype._switchToIframe = function (selector, iframeErrorCtors) {3683 var _this = this;3684 var hasSpecificTimeout = typeof selector.timeout === 'number';3685 var commandSelectorTimeout = hasSpecificTimeout ? selector.timeout : this.selectorTimeout;3686 return getResult(selector, commandSelectorTimeout, null, function (fn) { return new iframeErrorCtors.NotFoundError(fn); }, function () { return new iframeErrorCtors.IsInvisibleError(); }, this.statusBar)3687 .then(function (iframe) {3688 if (!testCafeCore.domUtils.isIframeElement(iframe))3689 throw new ActionElementNotIframeError();3690 return _this._ensureChildIframeDriverLink(nativeMethods$4.contentWindowGetter.call(iframe), iframeErrorCtors.NotLoadedError, commandSelectorTimeout);3691 })3692 .then(function (childDriverLink) {3693 childDriverLink.availabilityTimeout = commandSelectorTimeout;3694 _this.activeChildIframeDriverLink = childDriverLink;3695 _this.contextStorage.setItem(ACTIVE_IFRAME_SELECTOR, selector);3696 });3697 };3698 Driver.prototype._createWaitForEventPromise = function (eventName, timeout) {3699 var _this = this;3700 var eventHandler = null;3701 var timeoutPromise = new Promise$2(function (resolve) {3702 nativeMethods$4.setTimeout.call(window, function () {3703 _this.off(eventName, eventHandler);3704 resolve();3705 }, timeout);3706 });3707 var resultPromise = new Promise$2(function (resolve) {3708 eventHandler = function () {3709 this.off(eventName, eventHandler);3710 resolve();3711 };3712 _this.on(eventName, eventHandler);3713 });3714 return Promise$2.race([timeoutPromise, resultPromise]);3715 };3716 Driver.prototype._waitForCurrentCommandCompletion = function () {3717 if (!this.contextStorage.getItem(this.COMMAND_EXECUTING_FLAG))3718 return Promise$2.resolve();3719 return this._createWaitForEventPromise(STATUS_WITH_COMMAND_RESULT_EVENT, COMMAND_EXECUTION_MAX_TIMEOUT);3720 };3721 Driver.prototype._waitForEmptyCommand = function () {3722 return this._createWaitForEventPromise(EMPTY_COMMAND_EVENT, EMPTY_COMMAND_EVENT_WAIT_TIMEOUT);3723 };3724 Driver.prototype._abortSwitchingToChildWindowIfItClosed = function () {3725 if (!this.activeChildWindowDriverLink.driverWindow.closed)3726 return;3727 testCafeCore.arrayUtils.remove(this.childWindowDriverLinks, this.activeChildWindowDriverLink);3728 this.activeChildWindowDriverLink = null;3729 throw new ChildWindowClosedBeforeSwitchingError();3730 };3731 Driver.prototype._switchToChildWindow = function (selector) {3732 var _this = this;3733 this.contextStorage.setItem(this.PENDING_WINDOW_SWITCHING_FLAG, true);3734 return executeChildWindowDriverLinkSelector(selector, this.childWindowDriverLinks)3735 .then(function (childWindowDriverLink) {3736 return _this._ensureChildWindowDriverLink(childWindowDriverLink.driverWindow, ChildWindowIsNotLoadedError, _this.childWindowReadyTimeout);3737 })3738 .then(function (childWindowDriverLink) {3739 _this.activeChildWindowDriverLink = childWindowDriverLink;3740 return _this._waitForCurrentCommandCompletion();3741 })3742 .then(function () {3743 return _this._waitForEmptyCommand();3744 })3745 .then(function () {3746 _this._abortSwitchingToChildWindowIfItClosed();3747 _this._stopInternal();3748 return _this.activeChildWindowDriverLink.setAsMaster();3749 })3750 .then(function () {3751 _this.contextStorage.setItem(_this.PENDING_WINDOW_SWITCHING_FLAG, false);3752 })3753 .catch(function (err) {3754 _this.contextStorage.setItem(_this.PENDING_WINDOW_SWITCHING_FLAG, false);3755 if (err instanceof ChildWindowClosedBeforeSwitchingError) {3756 _this._onReady(new DriverStatus());3757 return;3758 }3759 _this._onReady(new DriverStatus({3760 isCommandResult: true,3761 executionError: new CannotSwitchToWindowError()3762 }));3763 });3764 };3765 Driver.prototype._switchToTopParentWindow = function () {3766 var switchFn = this.parentWindowDriverLink.setTopOpenedWindowAsMaster.bind(this.parentWindowDriverLink);3767 this._switchToParentWindowInternal(switchFn);3768 };3769 Driver.prototype._switchToParentWindow = function () {3770 var switchFn = this.parentWindowDriverLink.setParentWindowAsMaster.bind(this.parentWindowDriverLink);3771 this._switchToParentWindowInternal(switchFn);3772 };3773 Driver.prototype._switchToParentWindowInternal = function (parentWindowSwitchFn) {3774 var _this = this;3775 this.contextStorage.setItem(this.PENDING_WINDOW_SWITCHING_FLAG, true);3776 return Promise$2.resolve()3777 .then(function () {3778 _this._stopInternal();3779 return parentWindowSwitchFn();3780 })3781 .then(function () {3782 _this.contextStorage.setItem(_this.PENDING_WINDOW_SWITCHING_FLAG, false);3783 })3784 .catch(function () {3785 _this.contextStorage.setItem(_this.PENDING_WINDOW_SWITCHING_FLAG, false);3786 _this._onReady(new DriverStatus({3787 isCommandResult: true,3788 executionError: new CannotSwitchToWindowError()3789 }));3790 });3791 };3792 Driver.prototype._switchToMainWindow = function (command) {3793 if (this.activeChildIframeDriverLink)3794 this.activeChildIframeDriverLink.executeCommand(command);3795 this.contextStorage.setItem(ACTIVE_IFRAME_SELECTOR, null);3796 this.activeChildIframeDriverLink = null;3797 };3798 Driver.prototype._setNativeDialogHandlerInIframes = function (dialogHandler) {3799 var msg = new SetNativeDialogHandlerMessage(dialogHandler);3800 for (var i = 0; i < this.childIframeDriverLinks.length; i++)3801 messageSandbox$2.sendServiceMsg(msg, this.childIframeDriverLinks[i].driverWindow);3802 };3803 // Commands handling3804 Driver.prototype._onActionCommand = function (command) {3805 var _this = this;3806 var _a = executeAction(command, this.selectorTimeout, this.statusBar, this.speed), startPromise = _a.startPromise, completionPromise = _a.completionPromise;3807 startPromise.then(function () { return _this.contextStorage.setItem(_this.COMMAND_EXECUTING_FLAG, true); });3808 completionPromise3809 .then(function (driverStatus) {3810 _this.contextStorage.setItem(_this.COMMAND_EXECUTING_FLAG, false);3811 return _this._onReady(driverStatus);3812 });3813 };3814 Driver.prototype._onSetNativeDialogHandlerCommand = function (command) {3815 this.nativeDialogsTracker.setHandler(command.dialogHandler);3816 this._setNativeDialogHandlerInIframes(command.dialogHandler);3817 this._onReady(new DriverStatus({ isCommandResult: true }));3818 };3819 Driver.prototype._onGetNativeDialogHistoryCommand = function () {3820 this._onReady(new DriverStatus({3821 isCommandResult: true,3822 result: this.nativeDialogsTracker.appearedDialogs3823 }));3824 };3825 Driver.prototype._onGetBrowserConsoleMessagesCommand = function () {3826 this._onReady(new DriverStatus({ isCommandResult: true }));3827 };3828 Driver.prototype._onNavigateToCommand = function (command) {3829 var _this = this;3830 this.contextStorage.setItem(this.COMMAND_EXECUTING_FLAG, true);3831 executeNavigateTo(command)3832 .then(function (driverStatus) {3833 _this.contextStorage.setItem(_this.COMMAND_EXECUTING_FLAG, false);3834 return _this._onReady(driverStatus);3835 });3836 };3837 Driver.prototype._onExecuteClientFunctionCommand = function (command) {3838 var _this = this;3839 this.contextStorage.setItem(EXECUTING_CLIENT_FUNCTION_DESCRIPTOR, { instantiationCallsiteName: command.instantiationCallsiteName });3840 var executor = new ClientFunctionExecutor(command);3841 executor.getResultDriverStatus()3842 .then(function (driverStatus) {3843 _this.contextStorage.setItem(EXECUTING_CLIENT_FUNCTION_DESCRIPTOR, null);3844 _this._onReady(driverStatus);3845 });...

Full Screen

Full Screen

execute-navigate-to.js

Source:execute-navigate-to.js Github

copy

Full Screen

1import hammerhead from '../deps/hammerhead';2import testCafeCore from '../deps/testcafe-core';3import DriverStatus from '../status';4var Promise = hammerhead.Promise;5var RequestBarrier = testCafeCore.RequestBarrier;6var pageUnloadBarrier = testCafeCore.pageUnloadBarrier;7export default function executeNavigateTo (command) {8 var requestBarrier = new RequestBarrier();9 hammerhead.navigateTo(command.url);10 return Promise.all([requestBarrier.wait(), pageUnloadBarrier.wait()])11 .then(() => new DriverStatus({ isCommandResult: true }))12 .catch(err => new DriverStatus({ isCommandResult: true, executionError: err }));...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5});6test('My second test', async t => {7 .typeText('#developer-name', 'John Smith')8 .click('#submit-button');9});10test('My third test', async t => {11 .typeText('#developer-name', 'John Smith')12 .click('#submit-button');13});14test('My fourth test', async t => {15 .typeText('#developer-name', 'John Smith')16 .click('#submit-button');17});18test('My fifth test', async t => {19 .typeText('#developer-name', 'John Smith')20 .click('#submit-button');21});22test('My sixth test', async t => {23 .typeText('#developer-name', 'John Smith')24 .click('#submit-button');25});26test('My seventh test', async t => {27 .typeText('#developer-name', 'John Smith')28 .click('#submit-button');29});30test('My eighth test', async t => {31 .typeText('#developer-name', 'John Smith')32 .click('#submit-button');33});34test('My ninth test', async t => {35 .typeText('#developer-name', 'John Smith')36 .click('#submit-button');37});38test('My tenth test', async t => {39 .typeText('#developer-name', 'John Smith')40 .click('#submit-button');41});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button')5 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');6});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button')5 .wait(10000)6});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 const articleHeader = await Selector('.result-content').find('h1');6 let headerText = await articleHeader.innerText;7 let id = await articleHeader.id;8 let cssClass = await articleHeader.classNames;9 let color = await articleHeader.getStyleProperty('color');10 let tagName = await articleHeader.tagName;11 let headerNode = await articleHeader();12});13import { Selector } from 'testcafe';14test('My first test', async t => {15 .typeText('#developer-name', 'John Smith')16 .click('#submit-button');17 const articleHeader = await Selector('.result-content').find('h1');18 let headerText = await articleHeader.innerText;19 let id = await articleHeader.id;20 let cssClass = await articleHeader.classNames;21 let color = await articleHeader.getStyleProperty('color');22 let tagName = await articleHeader.tagName;23 let headerNode = await articleHeader();24});25import { Selector } from 'testcafe';26test('My first test', async t => {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5});6test('My second test', async t => {7 .typeText('#developer-name', 'John Smith')8 .click('#submit-button');9});10test('My third test', async t => {11 .typeText('#developer-name', 'John Smith')12 .click('#submit-button');13});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5});6import { Selector } from 'testcafe';7test('My first test', async t => {8 .typeText('#developer-name', 'John Smith')9 .click('#submit-button');10});11Your name to display (optional):12Your name to display (optional):13Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button')5 .wait(5000);6});7test('Navigate to a different page', async t => {8 .typeText('#developer-name', 'John Smith')9 .click('#submit-button')10 .wait(5000);11});12test('Navigate to a different page', async t => {13 .typeText('#developer-name', 'John Smith')14 .click('#submit-button')15 .wait(5000);16});17test('Navigate to a different page', async t => {18 .typeText('#developer-name', 'John Smith')19 .click('#submit-button')20 .wait(5000);21});22test('Navigate to a different page', async t => {23 .typeText('#developer-name', 'John Smith')24 .click('#submit-button')25 .wait(5000);26});27test('Navigate to a different page', async t => {28 .typeText('#developer-name', 'John Smith')29 .click('#submit-button')30 .wait(5000);31});32test('Navigate to a different page', async t => {33 .typeText('#developer-name', 'John Smith')

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 const articleHeader = await Selector('.result-content').find('h1');6 let headerText = await articleHeader.innerText;7 let id = await articleHeader.id;8 let headerNode = await articleHeader();9});10import { Selector } from 'testcafe';11test('My first test', async t => {12 .typeText('#developer-name', 'John Smith')13 .click('#submit-button');14 const articleHeader = await Selector('.result-content').find('h1');15 let headerText = await articleHeader.innerText;16 let id = await articleHeader.id;17 let headerNode = await articleHeader();18});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .click('#populate')4 .click('#submit-button');5});6import { Selector } from 'testcafe';7test('My first test', async t => {8 .click('#populate')9 .click('#submit-button');10});11import { Selector } from 'testcafe';12test('My first test', async t => {13 .click('#populate')14 .click('#submit-button');15});16import { Selector } from 'testcafe';17test('My first test', async t => {18 .click('#populate')19 .click('#submit-button');20});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful