george petre
george petre

Reputation: 21

Vaadin Notification blocks access to elements behind it

I am working currently on a Vaadin Testbench infrastructure, and the GUI I am testing is written in Vaadin 7/8. There is a simple Notification (HUMANIZED_MESSAGE) that comes from UI (Vaadin 7/8) - as you can see in the screenshot attached.

The problem I am facing in Vaadin Testbench is, when the Notification appears on the UI (and I don't know when is appearing), I cannot see the elements behind the Notification. Is there a way (On Vaadin 7/8 or Testbench) to make the Notification not have all the focus of the UI?

The only solution I have is to search for the NotificationElement (VaadinTestbench) and if it finds it, close it, but that means I should change the whole existing infrastructure.

Thanks, George

Notification

Upvotes: 0

Views: 254

Answers (1)

Anna Koskinen
Anna Koskinen

Reputation: 1370

Depends on what you are doing. You can query the elements that are hidden behind the Notification and access their attributes without an issue. However, if you want to click on anything, that's supposed to emulate the end user experience, so it moves the cursor to the given position and tries to click whatever element happens to be there. Whether the Notification has focus or not makes no difference.

Now the good news is that you can close the Notification by clicking on it. The bad news is that webElement.click() throws an exception if the click tries to land on the wrong element. So some workaround is needed beyond just clicking twice.

Here are a few potential options, all a bit clunky, but should do the trick:

  • Query for notifications and close them before the click (can be called safely whether there are any Notifications or not):
    private void closeAnyNotifications() {
        for (WebElement notification : findElements(
                By.className("v-Notification"))) {
            notification.click();
        }
    }
  • Surround the click with try-catch and if the error happens, only then close notifications and try the click again:
        try {
            webElement.click();
        } catch (ElementClickInterceptedException e) {
            closeAnyNotifications();
            webElement.click();
        }
  • Don't use the click directly but through an action, and do another click if the first one didn't trigger whatever the click was supposed to trigger:
new Actions(getDriver()).moveToElement(webElement).click().perform();
  • Do the try-catch trick but with the Action workaround (no need to move to element because the failed click already moved cursor to the correct location, only works if there can't be more than one Notification blocking the way):
        try {
            webElement.click();
        } catch (ElementClickInterceptedException e) {
            // close the notification
            new Actions(getDriver()).click().perform();
            webElement.click();
        }

Upvotes: 0

Related Questions