admin管理员组

文章数量:1323529

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()

     })
});

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()

     })
});
Share Improve this question edited Oct 23, 2015 at 9:39 giri-sh 6,9622 gold badges27 silver badges50 bronze badges asked Sep 10, 2015 at 21:40 user2744620user2744620 4391 gold badge10 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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
    });
});

Hope it helps.

本文标签: javascriptProtractor closing current tabStack Overflow