0

Is there any function/class to handle alert or any other types of popups in a browser. I am dealing with an alert popup I know I can handle it by using driver.switchto().alert(); and perform further actions. Since Serenity BDD is quite tailored to handle elements is there any specific function to handle alerts (only by using serenity BDD functions).

JDelorean
  • 631
  • 13
  • 26
Santhosh Siddappa
  • 708
  • 3
  • 14
  • 29

1 Answers1

2

This is what Serenity PageObject's getAlert() method looks like:

public Alert getAlert() {
    return driver.switchTo().alert();
}

And this is what driver object references:

private WebDriver driver;

As you might have guessed it already, the WebDriver type/object comes from Selenium. Hence to answer your question, yes there is a method in Serenity to grab alert popups, but it's a direct reference to Selenium.

JDelorean
  • 631
  • 13
  • 26
  • I get " java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.WebDriver.switchTo()" because "this.driver" is null" on following this. It doesn't happen if it is directly given in the feature steps. Happens when given on the Page Objects Base page. @JDelorean – SUPARNA SOMAN Mar 11 '22 at 16:56