0

I've tried the advice offered in this post How to close the current tab of the browser in protractor with out closing the complete browser to close the new browser tab in Chrome and return to the main application. The first one is ignored; the second results in errors. I also tried the browser.actions().keyDown(protractor.Key.CONTROL).sendKeys('w').perform(); which I found elsewhere.

  • What is the error message you are getting? Using `window[handles]` should work, it possible you are getting an error due to async or something – Ben Mohorc Jul 10 '18 at 19:22
  • Here's the totally odd thing. Our devs have said the entire front end is angular, so in theory I should not need browser.waitForAngularEnabled(false); but when I don't have that in the test I get this: Failed: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds. This may be because the current page is not an Angular application. Please see the FAQ for more details: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular. The following tasks were pending: – TheGreatKate Jul 10 '18 at 19:54
  • so it is probably not what is causing the errors you are seeing, but the assumption both the solutions there make that the popup is handle 1 and the original is 0 is one you cannot rely upon. – Jeremy Kahan Jul 11 '18 at 05:06

2 Answers2

0
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
    });
});
Madhan Raj
  • 1,404
  • 1
  • 7
  • 13
0

First function moves to first tab, second goes back to previous and closes the second:

var moveToTab = function() {
    browser.driver.sleep(5000).then(function() {
        browser.getAllWindowHandles().then(function(handles) {
            newWindowHandle = handles[1]; // this is your new tab
            browser.switchTo().window(newWindowHandle);
        });
    });
};
var goBackToPreviousTab = function() {
    browser.getAllWindowHandles().then(function(handles) {
        previousWindowHandle = handles[0]; // this is your previous tab
        browser.switchTo().window(previousWindowHandle);
    });
}
Sanja Paskova
  • 1,110
  • 8
  • 15