From 0f91a9f8736642dd41cbf0cafe19adec9ead45c1 Mon Sep 17 00:00:00 2001 From: Marco Collovati Date: Fri, 29 May 2026 11:33:00 +0200 Subject: [PATCH] refactor: deprecate `$` and `$view` in favor of `find` and `findInView` The `$` and `$view` query methods in the UI unit test base class have been deprecated, aligning the API with the browserless-test replacement. Introduce `find` and `findInView` as their replacements and update the tests to use the new methods. --- .../component/grid/BasicGridTesterTest.java | 2 +- .../component/login/LoginFormTesterTest.java | 8 +- .../login/LoginOverlayTesterTest.java | 8 +- .../testbench/unit/ComponentQueryTest.java | 347 ++++++++++-------- .../vaadin/testbench/unit/BaseUIUnitTest.java | 59 ++- 5 files changed, 263 insertions(+), 161 deletions(-) diff --git a/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/grid/BasicGridTesterTest.java b/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/grid/BasicGridTesterTest.java index 197b4aabb..fc3914e27 100644 --- a/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/grid/BasicGridTesterTest.java +++ b/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/grid/BasicGridTesterTest.java @@ -177,7 +177,7 @@ void getCellComponent_columnByKey_canClickAButton() { Assertions.assertInstanceOf(Button.class, cellComponent); var button = (Button) cellComponent; test(button).click(); - var notification = $(Notification.class).last(); + var notification = find(Notification.class).last(); Assertions.assertEquals("Clicked!", test(notification).getText()); } diff --git a/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/login/LoginFormTesterTest.java b/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/login/LoginFormTesterTest.java index 847e8bf0d..70eea3885 100644 --- a/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/login/LoginFormTesterTest.java +++ b/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/login/LoginFormTesterTest.java @@ -32,8 +32,8 @@ void init() { @Test void login_generatesLoginEvent() { test(view.login).login("user", "pwd"); - Assertions.assertEquals(1, $(Span.class).from(view).all().size()); - Span message = $(Span.class).from(view).withId("m1").first(); + Assertions.assertEquals(1, find(Span.class).from(view).all().size()); + Span message = find(Span.class).from(view).withId("m1").first(); Assertions.assertEquals(view.generateLoginMessage("user", "pwd"), message.getText()); } @@ -54,8 +54,8 @@ void login_disablesLoginComponent() { void forgotPassword_generatesEvent() { test(view.login).forgotPassword(); - Assertions.assertEquals(1, $(Span.class).from(view).all().size()); - Span message = $(Span.class).from(view).withId("m1").first(); + Assertions.assertEquals(1, find(Span.class).from(view).all().size()); + Span message = find(Span.class).from(view).withId("m1").first(); Assertions.assertEquals("forgot", message.getText()); } diff --git a/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/login/LoginOverlayTesterTest.java b/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/login/LoginOverlayTesterTest.java index 5c4412ebf..0c8b9d7c2 100644 --- a/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/login/LoginOverlayTesterTest.java +++ b/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/login/LoginOverlayTesterTest.java @@ -42,8 +42,8 @@ void login_generatesLoginEvent() { login_.openOverlay(); login_.login("user", "pwd"); - Assertions.assertEquals(1, $(Span.class).from(view).all().size()); - Span message = $(Span.class).from(view).withId("m1").first(); + Assertions.assertEquals(1, find(Span.class).from(view).all().size()); + Span message = find(Span.class).from(view).withId("m1").first(); Assertions.assertEquals(view.generateLoginMessage("user", "pwd"), message.getText()); } @@ -66,8 +66,8 @@ void forgotPassword_generatesEvent() { login_.openOverlay(); login_.forgotPassword(); - Assertions.assertEquals(1, $(Span.class).from(view).all().size()); - Span message = $(Span.class).from(view).withId("m1").first(); + Assertions.assertEquals(1, find(Span.class).from(view).all().size()); + Span message = find(Span.class).from(view).withId("m1").first(); Assertions.assertEquals("forgot", message.getText()); } diff --git a/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/testbench/unit/ComponentQueryTest.java b/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/testbench/unit/ComponentQueryTest.java index 3cdec9315..68a9d5dcd 100644 --- a/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/testbench/unit/ComponentQueryTest.java +++ b/vaadin-testbench-unit-junit5/src/test/java/com/vaadin/testbench/unit/ComponentQueryTest.java @@ -43,7 +43,7 @@ void find_invisibleComponents_noResults() { rootElement.getChildren().filter(el -> !el.isTextNode()) .forEach(el -> el.setVisible(false)); - Assertions.assertTrue($(Div.class).all().isEmpty()); + Assertions.assertTrue(find(Div.class).all().isEmpty()); } @Test @@ -55,11 +55,11 @@ void first_exactMatch_getsComponent() { Button button = new Button(); root.appendChild(button.getElement()); - ComponentQuery textFieldQuery = $(TextField.class); + ComponentQuery textFieldQuery = find(TextField.class); Assertions.assertSame(textField, textFieldQuery.first(), "Expecting query to find TextField component, but got different instance"); - ComponentQuery