Reputation: 21
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
Upvotes: 0
Views: 254
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:
private void closeAnyNotifications() {
for (WebElement notification : findElements(
By.className("v-Notification"))) {
notification.click();
}
}
try {
webElement.click();
} catch (ElementClickInterceptedException e) {
closeAnyNotifications();
webElement.click();
}
new Actions(getDriver()).moveToElement(webElement).click().perform();
try {
webElement.click();
} catch (ElementClickInterceptedException e) {
// close the notification
new Actions(getDriver()).click().perform();
webElement.click();
}
Upvotes: 0