量角器关闭当前选项卡 [英] Protractor closing current tab

查看:80
本文介绍了量角器关闭当前选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非角度页面,我需要单击2个链接.单击一个在新选项卡中自动打开的链接时.现在,我切换到新选项卡并设置browser.ignoreSynchronization = false,因为新打开的选项卡是一个有角度的窗口.并打电话给我的测试之一.一旦验证.我想关闭当前选项卡,然后返回非角度页面以单击链接#2,该链接将再次在新选项卡中打开.我尝试了window.close,但是我正在获取未定义的窗口.我使用过browser.window,甚至无法正常工作.请指教

I have a non-angular page where I need to click on 2 links. When clicking on one of the link that automatically opens in a new tab. Now I switch to new tab and set the browser.ignoreSynchronization = false because the newly opened tab is a angular window; and call one of my test. Once verified. I want to close the current tab and go back to the non-angular page to click on link #2 which would again open in a new tab. I tried window.close but i am getting window is undefined. I used browser.window and even that is not working. Please advise

element(by.id('trMyUrl'));
    browser.getAllWindowHandles().then(function (handles) {
             var secondWindowHandle = handles[1];
             var firstWindowHandle = handles[0];
    browser.switchTo().window(secondWindowHandle).then(function () { //the focus moves on new tab\
    browser.ignoreSynchronization = false;    
    empLogin.test();
    window(secondWindowHandle).close()
    // window.close()
    // browser.close()
    // browser.window.close()

     })
});

推荐答案

关闭当前关注的第二个窗口,然后首先switchTo()上一个选项卡对其执行操作.这是-

Close your second window that is currently focused on and then switchTo() previous tab first to perform operations on it. Here's how -

browser.switchTo().window(secondWindowHandle)
.then(function () {
    browser.ignoreSynchronization = false;    
    empLogin.test();
}).then(function(){
    browser.close(); //close the current browser
}).then(function(){
    browser.switchTo().window(firstWindowHandle) //Switch to previous tab
    .then(function(){
        //Perform your operations on the first tab
    });
});

希望有帮助.

这篇关于量角器关闭当前选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆