While using protractor and cucumber, I have encountered an issue where some tests may result in displaying an alert box. In order to handle this, I want to check for the presence of an alert box at the start of each test and close/dismiss it if it exists. However, the challenge I am facing is that there is no guarantee that an alert box will always be present. If there isn't one, I receive a NoSuchAlertError: no alert open
error, causing the entire script to stop.
Is there a workaround for this situation?
Below is my current code snippet:
try {
browser.switchTo().alert().dismiss();
}catch(err){
}