protractor typescript closing a popup in a non angular application

249 Views Asked by At

I'm working on protractor/typescript in non angular application, using handlers & trying to verify and close a popup message. Here is the code, but this does not looks like closing the popup window. Maybe the click is not really clicking the okbutton.

Here is the code:

Then(/^user validate login error message and ok to close the popup message and return to main page$/, async () => {

browser.getAllWindowHandles().then(function (handels) {
// browser.switchTo().window(handels[1]).then(function () {

return browser.wait(function () {
// return browser.isElementPresent(element(by.xpath('//*.....message')))
// }, 40000).then(function (text) {
// console.log("returned text is " + text);
// expect(text).to.equal('Error Signing In');
// browser.sleep(5000);

browser.getAllWindowHandles().then(function (handels) {
browser.switchTo().window(handels[1]).then(function () {
element(by.xpath('//*.....okbutton')).click();

})

browser.switchTo().window(handels[0]).then(function () {
expect(browser.getTitle()).to.eventually.equal('login page');
//browser.getTitle().then(function (title) {
// console.log(title);


//})
})

})
})

Can you help ?

Thank you

Sean,

1

There are 1 best solutions below

2
Avinash On

Can you try sending escape key on the popup(assuming your browser.switchTo().window(handels[1]).then)is working as expected : Try sending escape key to the control

element(by.xpath('//*.....okbutton')).sendKeys(protractor.Key.ESCAPE);