]> source.dussan.org Git - vaadin-framework.git/commitdiff
Test fixes and tweaks (#12239)
authorAnna Koskinen <Ansku@users.noreply.github.com>
Tue, 16 Mar 2021 07:45:15 +0000 (09:45 +0200)
committerGitHub <noreply@github.com>
Tue, 16 Mar 2021 07:45:15 +0000 (09:45 +0200)
- Properly init client-side data in GridDataChangeHandlerTest
- Update Chrome version
- Separate and refactor ComboboxMenuBarAutoopenTest test cases to match
test description
- Update screenshot for ResponsiveStylesTest
- Refactor TextAreaEventPropagationTest to better match expected
behavior
- Add delay to GridDetailsClientTest and EscalatorSpacerTest for
stability
- Add delay and retries to TreeItemDoubleClickTest for stability

Co-authored-by: Teemu Suo-Anttila <teemusa@vaadin.com>
uitest/reference-screenshots/ResponsiveStylesTest-testValoMenuResponsiveHover_ANY_Chrome__collapsedMenu.png
uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridDataChangeHandlerWidget.java
uitest/src/test/java/com/vaadin/tests/VerifyBrowserVersionTest.java
uitest/src/test/java/com/vaadin/tests/components/combobox/ComboboxMenuBarAutoopenTest.java
uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridDetailsClientTest.java
uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorSpacerTest.java
uitest/src/test/java/com/vaadin/tests/components/tree/TreeItemDoubleClickTest.java
uitest/src/test/java/com/vaadin/tests/components/ui/TextAreaEventPropagationTest.java

index 608ac63b8a387d70c8992fdb951f2bf04571c373..215a5cc52c4036b5b60de0dec41040d54cb8e5c7 100644 (file)
Binary files a/uitest/reference-screenshots/ResponsiveStylesTest-testValoMenuResponsiveHover_ANY_Chrome__collapsedMenu.png and b/uitest/reference-screenshots/ResponsiveStylesTest-testValoMenuResponsiveHover_ANY_Chrome__collapsedMenu.png differ
index 0d68c385c4f6f6a123e00f87ce9095a67d0c84f6..055fad260aed37a07bb4e1e65b2e6207f3700f69 100644 (file)
@@ -65,6 +65,8 @@ public class GridDataChangeHandlerWidget extends Composite {
         public RemoteDelayedDataSource(List<String> datasource) {
             super();
             rows = datasource;
+            // Make Grid request not exceed actual size.
+            resetDataAndSize(rows.size());
         }
 
         @Override
@@ -86,7 +88,6 @@ public class GridDataChangeHandlerWidget extends Composite {
         public Object getRowKey(String row) {
             return row;
         }
-
     }
 
     public GridDataChangeHandlerWidget() {
index ec3fb525a38c6566510b6082db8e5e984283a8a7..a7c7b3800646272ad256b5ba3981ec7e6bd24a90 100644 (file)
@@ -25,7 +25,7 @@ public class VerifyBrowserVersionTest extends MultiBrowserTest {
             // Chrome version does not necessarily match the desired version
             // because of auto updates...
             browserIdentifier = getExpectedUserAgentString(
-                    getDesiredCapabilities()) + "88";
+                    getDesiredCapabilities()) + "89";
         } else {
             browserIdentifier = getExpectedUserAgentString(desiredCapabilities)
                     + desiredCapabilities.getVersion();
index bdb47da998dffabca19bf70eaf702955157d0496..3fb5203580e18bf19908d264ec5bca59da9766a1 100644 (file)
@@ -1,6 +1,7 @@
 package com.vaadin.tests.components.combobox;
 
-import org.junit.Assert;
+import static org.junit.Assert.assertFalse;
+
 import org.junit.Test;
 import org.openqa.selenium.By;
 import org.openqa.selenium.WebElement;
@@ -9,6 +10,7 @@ import org.openqa.selenium.interactions.Actions;
 import com.vaadin.testbench.elements.MenuBarElement;
 import com.vaadin.tests.tb3.MultiBrowserTest;
 import com.vaadin.tests.tb3.newelements.ComboBoxElement;
+import com.vaadin.ui.Notification.Type;
 
 /**
  * Test that checks whether Combobox popup is closed on click to autoopen
@@ -20,24 +22,32 @@ public class ComboboxMenuBarAutoopenTest extends MultiBrowserTest {
 
     @Test
     public void closeComboboxPopupOnClickToMenuBar() {
-        setDebug(true);
         openTestURL();
 
         openPopup();
         MenuBarElement menuBar = selectMenuBar();
         menuBar.click();
-        Assert.assertFalse("Combobox popup items are visible",
+        assertFalse("Combobox popup items are visible",
                 isElementPresent(By.className("gwt-MenuItem")));
+    }
+
+    @Test
+    public void closeComboboxPopupOnClickToMenuBarItem() {
+        openTestURL();
 
         openPopup();
-        menuBar = selectMenuBar();
 
+        // hover over menubar to open
         WebElement menuBarItem = findElement(
                 By.className("v-menubar-menuitem-caption"));
-        Actions actions = new Actions(getDriver());
-        actions.moveToElement(menuBarItem).build().perform();
-        menuBar.click();
-        Assert.assertFalse("Combobox popup items are visible",
+        moveToElement(menuBarItem);
+
+        // click submenu item
+        findElements(By.className("v-menubar-menuitem-caption")).get(1).click();
+        assertElementPresent(By.className(
+                "v-Notification-" + Type.HUMANIZED_MESSAGE.getStyle()));
+
+        assertFalse("Combobox popup items are visible",
                 isElementPresent(By.className("gwt-MenuItem")));
     }
 
@@ -47,20 +57,20 @@ public class ComboboxMenuBarAutoopenTest extends MultiBrowserTest {
         combobox.openPopup();
         combobox.focus();
 
-        Actions actions = new Actions(getDriver());
-        actions.moveToElement(
-                getDriver().findElement(By.className("gwt-MenuItem"))).build()
-                .perform();
+        moveToElement(findElement(By.className("gwt-MenuItem")));
     }
 
     private MenuBarElement selectMenuBar() {
         MenuBarElement menuBar = $(MenuBarElement.class).first();
         menuBar.focus();
 
-        Actions actions = new Actions(getDriver());
-        actions.moveToElement(menuBar).build().perform();
+        moveToElement(menuBar);
 
         return menuBar;
     }
 
+    private void moveToElement(WebElement target) {
+        Actions actions = new Actions(driver);
+        actions.moveToElement(target).build().perform();
+    }
 }
index fb2baf4e69008870c7b930692b89ea1dc8a28f27..e99d6053d7fc48df171c0051016181aeeb544980 100644 (file)
@@ -79,6 +79,7 @@ public class GridDetailsClientTest extends GridBasicClientFeaturesTest {
 
         selectMenuPath(SET_GENERATOR);
         toggleDetailsFor(100);
+        waitForElementPresent(By.className("gwt-Button"));
 
         // scroll a bit beyond so we see below.
         getGridElement().scrollToRow(101);
index 28ad3fbdb12f8d3fd2cc59f4d700611b2e5e0ee8..a360cc5128d66dff0999f5ec8cf9f88b165f6245 100644 (file)
@@ -406,10 +406,12 @@ public class EscalatorSpacerTest extends EscalatorBasicClientFeaturesTest {
     }
 
     @Test
-    public void spacersAreInCorrectDomPositionAfterScroll() {
+    public void spacersAreInCorrectDomPositionAfterScroll()
+            throws InterruptedException {
         selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
 
         scrollVerticallyTo(32); // roughly one row's worth
+        sleep(100);
 
         WebElement tbody = getEscalator().findElement(By.tagName("tbody"));
         WebElement spacer = getChild(tbody, 1);
index 0684fc638a68edcb400de7cf1f47fd260639b330..36bb1180642561b6928136bdf97326dd9531c507 100644 (file)
@@ -17,13 +17,24 @@ public class TreeItemDoubleClickTest extends MultiBrowserTest {
         openTestURL();
         String caption = "Tree Item 2";
         doubleClick(getTreeNodeByCaption(caption));
-        assertLogText("Double Click " + caption);
+        try {
+            assertLogText("Double Click " + caption);
+        } catch (AssertionError e) {
+            // double click is flaky, try again
+            doubleClick(getTreeNodeByCaption(caption));
+            assertLogText("Double Click " + caption);
+        }
 
         changeImmediate();
 
         caption = "Tree Item 3";
         doubleClick(getTreeNodeByCaption(caption));
-        assertLogText("Double Click " + caption);
+        try {
+            assertLogText("Double Click " + caption);
+        } catch (AssertionError e) {
+            doubleClick(getTreeNodeByCaption(caption));
+            assertLogText("Double Click " + caption);
+        }
     }
 
     private void changeImmediate() {
@@ -36,9 +47,9 @@ public class TreeItemDoubleClickTest extends MultiBrowserTest {
                 .findElement(By.xpath("//span[text() = '" + caption + "']"));
     }
 
-    private void doubleClick(WebElement element) {
+    private void doubleClick(WebElement element) throws InterruptedException {
         new Actions(getDriver()).doubleClick(element).build().perform();
-
+        sleep(100);
     }
 
     private void assertLogText(String text) {
index 6c5513e17db2e39e7f777f4b9925fd839aa55b66..4bc34801dd7ec591a6bf0ae0bea179a5dfe77859 100644 (file)
@@ -1,16 +1,17 @@
 package com.vaadin.tests.components.ui;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import org.junit.Test;
 import org.openqa.selenium.Keys;
-import org.openqa.selenium.WebElement;
 import org.openqa.selenium.interactions.Actions;
 
 import com.vaadin.testbench.elements.TextAreaElement;
 import com.vaadin.testbench.elements.TextFieldElement;
 import com.vaadin.tests.tb3.MultiBrowserTest;
 
-import static org.junit.Assert.assertEquals;
-
 /**
  * Tests that the TextArea widget correctly stops ENTER events from propagating.
  *
@@ -21,14 +22,17 @@ public class TextAreaEventPropagationTest extends MultiBrowserTest {
     @Test
     public void textAreaEnterEventPropagation() throws InterruptedException {
         openTestURL();
-        WebElement textArea = $(TextAreaElement.class).first();
+        TextAreaElement textArea = $(TextAreaElement.class).first();
         Actions builder = new Actions(driver);
         builder.click(textArea);
-        builder.sendKeys(textArea, "first line asdf");
-        builder.sendKeys(Keys.ENTER);
-        builder.sendKeys(textArea, "second line jkl;");
+        builder.sendKeys(textArea, "first line asdf", Keys.ENTER,
+                "second line jkl;");
         builder.perform();
+        waitUntilLoadingIndicatorNotVisible();
 
+        String text = textArea.getValue();
+        assertEquals("Unexpected text area content,",
+                "first line asdf\nsecond line jkl;", text);
         // Should not have triggered shortcut
         assertEquals(" ", getLogRow(0));
     }
@@ -37,48 +41,55 @@ public class TextAreaEventPropagationTest extends MultiBrowserTest {
     public void testTextAreaEscapeEventPropagation()
             throws InterruptedException {
         openTestURL();
-        WebElement textArea = $(TextAreaElement.class).first();
+        TextAreaElement textArea = $(TextAreaElement.class).first();
         Actions builder = new Actions(driver);
         builder.click(textArea);
-        builder.sendKeys(textArea, "first line asdf");
-        builder.sendKeys(Keys.ESCAPE);
-        builder.sendKeys(textArea, "second line jkl;");
+        builder.sendKeys(textArea, "first line asdf", Keys.ESCAPE,
+                "second line jkl;");
         builder.perform();
+        waitUntilLoadingIndicatorNotVisible();
 
+        String text = textArea.getValue();
+        // sendKeys is erratic and can eat some letters after escape, so only
+        // test that beginning and end are present
+        assertTrue("Unexpected text area content: " + text,
+                text.startsWith("first line asdf"));
+        assertTrue("Unexpected text area content: " + text,
+                text.endsWith("nd line jkl;"));
+        assertFalse("Unexpected text area content: " + text,
+                text.contains("\n"));
         assertEquals("1. Escape button pressed", getLogRow(0));
     }
 
     @Test
-    public void testTextFieldEscapeEventPropagation() throws InterruptedException {
+    public void testTextFieldEscapeEventPropagation() {
         openTestURL();
-        WebElement textField = $(TextFieldElement.class).first();
+        TextFieldElement textField = $(TextFieldElement.class).first();
         Actions builder2 = new Actions(driver);
         builder2.click(textField);
 
-        builder2.sendKeys("third line");
-        builder2.sendKeys(Keys.ENTER);
-        sleep(100);
-        builder2.sendKeys(Keys.ESCAPE);
-        sleep(100);
+        builder2.sendKeys(textField, "third line", Keys.ESCAPE);
         builder2.perform();
-        sleep(100);
+        waitUntilLoadingIndicatorNotVisible();
 
-        assertEquals("1. Enter button pressed", getLogRow(1));
-        assertEquals("2. Escape button pressed", getLogRow(0));
+        String text = textField.getValue();
+        assertEquals("Unexpected text field content,", "third line", text);
+        assertEquals("1. Escape button pressed", getLogRow(0));
     }
 
     @Test
     public void testTextFieldEnterEventPropagation() {
         openTestURL();
-        WebElement textField = $(TextFieldElement.class).first();
+        TextFieldElement textField = $(TextFieldElement.class).first();
         Actions builder2 = new Actions(driver);
         builder2.click(textField);
 
-        builder2.sendKeys("third line");
-        builder2.sendKeys(Keys.ENTER);
-
+        builder2.sendKeys(textField, "third line", Keys.ENTER);
         builder2.perform();
+        waitUntilLoadingIndicatorNotVisible();
 
+        String text = textField.getValue();
+        assertEquals("Unexpected text field content,", "third line", text);
         assertEquals("1. Enter button pressed", getLogRow(0));
     }
 }