Skip to content

Commit 7eb2d6b

Browse files
authored
fix: wait until content visible in notification element (#4926)
* fix: wait until content visible in notification element * refactor: update timeout to 1 second * chore: fix typo
1 parent 0e6cbd4 commit 7eb2d6b

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

  • vaadin-notification-flow-parent

‎vaadin-notification-flow-parent/vaadin-notification-flow-integration-tests/src/main/java/com/vaadin/flow/component/notification/tests/NotificationView.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ private void createDefaultNotificaiton() {
6464
private void createNotificationWithPosition() {
6565
NativeButton button = new NativeButton(BUTTON_CAPTION);
6666
Notification notification = new Notification(
67-
"This notification is located on Top-Left", 3000,
68-
Position.TOP_START);
67+
new Span("This notification is located on Top-Left"));
68+
notification.setDuration(3000);
69+
notification.setPosition(Position.TOP_START);
6970
button.addClickListener(event -> notification.open());
7071
button.setId("position-notification-button");
7172
notification.setId("position-notification");

‎vaadin-notification-flow-parent/vaadin-notification-flow-integration-tests/src/test/java/com/vaadin/flow/component/notification/tests/NotificationIT.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Optional;
2020
import java.util.stream.Collectors;
2121

22+
import com.vaadin.flow.component.notification.testbench.NotificationElement;
2223
import com.vaadin.flow.testutil.TestPath;
2324
import com.vaadin.tests.AbstractComponentIT;
2425

@@ -54,6 +55,10 @@ public void defaultNotification() {
5455
public void notificationWithPosition() {
5556
findElement(By.id("position-notification-button")).click();
5657
checkNotificationIsOpen();
58+
var notification = $(NotificationElement.class)
59+
.id("position-notification");
60+
Assert.assertEquals("This notification is located on Top-Left",
61+
notification.getText());
5762
assertNotificationContent("Top-Left");
5863
Assert.assertEquals(1,
5964
findElements(By.id("position-notification")).size());

‎vaadin-notification-flow-parent/vaadin-notification-testbench/src/main/java/com/vaadin/flow/component/notification/testbench/NotificationElement.java‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
*/
1616
package com.vaadin.flow.component.notification.testbench;
1717

18+
import org.openqa.selenium.By;
1819
import org.openqa.selenium.SearchContext;
1920
import org.openqa.selenium.StaleElementReferenceException;
21+
import org.openqa.selenium.TimeoutException;
2022

2123
import com.vaadin.testbench.TestBenchElement;
2224
import com.vaadin.testbench.elementsbase.Element;
@@ -60,6 +62,19 @@ public SearchContext getContext() {
6062
* @return the card for the notification
6163
*/
6264
private TestBenchElement getCard() {
63-
return getPropertyElement("_card");
65+
var card = getPropertyElement("_card");
66+
67+
try {
68+
// Wait until the content becomes visible
69+
waitUntil(driver -> {
70+
var hasVisibleText = !card.getText().isEmpty();
71+
var hasVisibleChildren = card.findElements(By.cssSelector("*"))
72+
.stream().anyMatch(element -> element.isDisplayed());
73+
return hasVisibleText || hasVisibleChildren;
74+
}, 1);
75+
} catch (TimeoutException e) {
76+
// Ignore, the card may be empty on purpose
77+
}
78+
return card;
6479
}
6580
}

0 commit comments

Comments
 (0)