From ff52c42738a96c3fde01c40d33075376bcae1339 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Wed, 3 May 2017 11:57:03 +0300 Subject: Fix ComponentLocator with inherited classes without custom connector (#9176) Logic for finding elements corresponding a server-side classname does not work with inherited classes. For example making MyGrid extends Grid, you could not find the specific MyGrid, but only the common Grid. In most cases this is not a problem since these components are usually the only instance of said superclass, but the Composite introduced in the same UI, which makes testing them impossible. This patch adds the specific classname information for ServerConnectors that can be used to find the correct connector instance. --- .../ComponentLocatorInheritedClasses.java | 36 +++++++++++++++++++++ .../ComponentLocatorInheritedClassesTest.java | 37 ++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 uitest/src/main/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClasses.java create mode 100644 uitest/src/test/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClassesTest.java (limited to 'uitest') diff --git a/uitest/src/main/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClasses.java b/uitest/src/main/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClasses.java new file mode 100644 index 0000000000..46fb7cc00e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClasses.java @@ -0,0 +1,36 @@ +package com.vaadin.tests.componentlocator; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Label; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class ComponentLocatorInheritedClasses extends UI { + + public static class DefaultLabel extends Label { + + protected DefaultLabel(String content) { + super(content); + } + + public DefaultLabel() { + this("Default Custom Label"); + } + } + + public static class MyCustomLabel extends DefaultLabel { + public MyCustomLabel(String content) { + super(content); + } + } + + @Override + protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.addComponents(new Label("Vaadin Basic Label"), + new DefaultLabel(), new MyCustomLabel("My Custom Label")); + setContent(layout); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClassesTest.java b/uitest/src/test/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClassesTest.java new file mode 100644 index 0000000000..4d8449fa38 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClassesTest.java @@ -0,0 +1,37 @@ +package com.vaadin.tests.componentlocator; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elementsbase.ServerClass; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class ComponentLocatorInheritedClassesTest extends SingleBrowserTest { + + @ServerClass("com.vaadin.tests.componentlocator.ComponentLocatorInheritedClasses.DefaultLabel") + public static class DefaultLabelElement extends LabelElement { + } + + @ServerClass("com.vaadin.tests.componentlocator.ComponentLocatorInheritedClasses.MyCustomLabel") + public static class MyCustomLabelElement extends DefaultLabelElement { + } + + @Test + public void label_finds_all_three() { + openTestURL(); + Assert.assertEquals(3, $(LabelElement.class).all().size()); + } + + @Test + public void defaultlabel_finds_two() { + openTestURL(); + Assert.assertEquals(2, $(DefaultLabelElement.class).all().size()); + } + + @Test + public void mycustomlabel_finds_one() { + openTestURL(); + Assert.assertEquals(1, $(MyCustomLabelElement.class).all().size()); + } +} -- cgit v1.2.3