giorgiosironi / phpunit-selenium

Selenium RC integration for PHPUnit
http://www.phpunit.de/
Other
602 stars 271 forks source link

WebDriverException prior to handling alerts dialogs #382

Closed seanirwin closed 7 years ago

seanirwin commented 8 years ago

When a JavaScript alert is on the page I am unable to access the acceptAlert()/alertText()/declineAlert() methods, I can only test for expectedExceptions. Is there a way to switch to the alert dialog or other dialogs?

@expectedException PHPUnit_Extensions_Selenium2TestCase_WebDriverException unexpected alert open

Java documentation suggest that you can switch to the alert window, but there doesn't seem to be a comparable method in the phpunit-selenium library. driver.switchTo().alert();

paulbriton commented 7 years ago

I think you are trying to handle the alert too soon. I've made a wrapper function that's throw "unexpected alert open" exceptions and waits for getting the text of the alert. That's not the most elegant solution, but at least it works for my case.

paulbriton commented 7 years ago

Can also be closed, switchTo() command for alert isn't referenced in the webdriver spec.

Moreover, alertIsPresent() method has been added and should do what you want.