diff --git a/junit6/src/test/java/com/example/locator/LocatorDemoView.java b/junit6/src/test/java/com/example/locator/LocatorDemoView.java index 5540430..635eb33 100644 --- a/junit6/src/test/java/com/example/locator/LocatorDemoView.java +++ b/junit6/src/test/java/com/example/locator/LocatorDemoView.java @@ -43,6 +43,7 @@ public LocatorDemoView() { save.setId("save"); Button clear = new Button("Clear", e -> name.setValue("")); + clear.setAriaLabel("Reset form"); Grid people = new Grid<>(Person.class); people.setItems(List.of(new Person("Alice", 30), new Person("Bob", 25), @@ -62,8 +63,8 @@ public LocatorDemoView() { */ public static class PersonForm extends Composite { - public final TextField nameField = new TextField("Name"); - public final TextField emailField = new TextField("Email"); + public final TextField nameField = new TextField("Full name"); + public final TextField emailField = new TextField("Email address"); public final Button submit; public PersonForm(Span echo) { diff --git a/junit6/src/test/java/com/vaadin/browserless/ComponentQueryTest.java b/junit6/src/test/java/com/vaadin/browserless/ComponentQueryTest.java index e486b31..4330a14 100644 --- a/junit6/src/test/java/com/vaadin/browserless/ComponentQueryTest.java +++ b/junit6/src/test/java/com/vaadin/browserless/ComponentQueryTest.java @@ -32,7 +32,10 @@ import com.vaadin.flow.component.Text; import com.vaadin.flow.component.UI; import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.dialog.Dialog; import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.component.html.NativeLabel; +import com.vaadin.flow.component.masterdetaillayout.MasterDetailLayout; import com.vaadin.flow.component.textfield.IntegerField; import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.component.textfield.TextFieldBase; @@ -617,6 +620,173 @@ void withCaptionContaining_null_throws() { () -> query.withCaptionContaining(null)); } + @Test + void withLabel_exactMatch_getsCorrectComponent() { + TestComponent labelled = new TestComponent(); + labelled.getElement().setProperty("label", "Full name"); + + TestComponent other = new TestComponent(); + other.getElement().setProperty("label", "Email"); + + TestComponent withLabelComponent = new TestComponent(); + withLabelComponent.setId("random123"); + NativeLabel labelComponent = new NativeLabel("Native"); + labelComponent.setFor(withLabelComponent); + + TestComponent noLabel = new TestComponent(); + + UI.getCurrent().getElement().appendChild(labelled.getElement(), + other.getElement(), noLabel.getElement(), + withLabelComponent.getElement(), labelComponent.getElement()); + + Assertions.assertSame(labelled, + find(TestComponent.class).withLabel("Full name").single()); + Assertions.assertSame(other, + find(TestComponent.class).withLabel("Email").single()); + // A separate