1

I have just started working with Cucumber + Serenity.

I would like to ignore UnhandledAlertException.

This is how chrome capabilities could be set in Selenium

capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);

But I am not sure what should be used in serenity.properties file to ignore the unhandled alerts.

chrome.capabilities.unexpectedAlertBehaviour = ignore

Is this correct? The problem is that I cannot test this behavior since the unexpected alert exception doesn't occur in all the runs.

So, I will get the feedback whether the above property is working only if a test fails (that I am unable to replay)

At least the below code doesn't work for me right now, so I decided to use the global setting along with the below method:

private void dismissAlertIfPresentAtStartOfScenario()
{
    try
    {
        Alert alert = REAL_DRIVER.switchTo().alert();
        String text = alert.getText();
        alert.dismiss();
        LOGGER.warn("Dismissed alert [{}] at start of this scenario!", text);
    }
    catch (NoAlertPresentException e)
    {
        // ignore the exception and do nothing, no alert is expected at the start of the scenario
    }
}
Navarasu
  • 5,221
  • 2
  • 17
  • 29
dinzy
  • 11
  • 3

1 Answers1

0

for Chrome the answer is :

chrome.capabilities.handlesAlerts = true

This sis equivalent to code :

cap.setCapability(CapabilityType.SUPPORTS_ALERTS, true);

Source : https://johnfergusonsmart.com/configuring-chromedriver-easily-with-serenity-bdd/

I am looking for the equivalent for Firefox but I have found nothing up to now.

  • Is this capability for handling unexpected alerts? It seems related to supporting alerts and not handling unexpected alerts. – dinzy Nov 23 '18 at 12:46