On our app, when we click on a button, it is opening a PDF file in a new browser tab. I am trying to validate that the URL is opened correctly, so I wrote the code following the answers given here:
G.View_Doc_Button.click();
browser.sleep(2000);
browser.getAllWindowHandles().then(function (handles) {
console.log(handles);
let newWindowHandle = handles[1];
browser.driver.switchTo().window(newWindowHandle).then(function() {
browser.getCurrentUrl().then(function(Tab){
expect(Tab).toBe('localhost:10001/assets/Doc.pdf');
});
browser.close();
browser.driver.switchTo().window(handles[0]);
});
// browser.driver.switchTo().window(handles[1]);
// browser.driver.close();
// browser.driver.switchTo().window(handles[0]);
});
The code fails on these lines :
browser.getCurrentUrl().then(function(Tab){
expect(Tab).toBe('localhost:10001/assets/Doc.pdf');
});
Since the tab opens a PDF document, most probably it is resulting in the failure. the error is
" AfterAll Failed: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or becaus e your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See https://github.com/angular/protractor/issues/2643 for details""
Please note that, If I remove the URL validation part, the code works fine. but it beats my purpose.
How can this be solved?