]> source.dussan.org Git - vaadin-framework.git/commitdiff
ComboBoxSlow test upgrade (#14292)
authorAnna Koskinen <anna@vaadin.com>
Tue, 5 Aug 2014 15:03:43 +0000 (18:03 +0300)
committerHeikki Ohinmaa <heikki@vaadin.com>
Tue, 19 Aug 2014 16:33:34 +0000 (16:33 +0000)
Change-Id: Ic2e1bfd300a6b18aeddd4c4895c7bb11fec5bb8b

uitest/src/com/vaadin/tests/components/combobox/ComboBoxSlow.java
uitest/src/com/vaadin/tests/components/combobox/ComboBoxSlowTest.java

index 13066854bf9f676ecdf5dac8e8e5f96e560a2fdf..3668637846ccd98563c6772ea8c95d8dab7f2b71 100644 (file)
@@ -2,10 +2,11 @@ package com.vaadin.tests.components.combobox;
 
 import com.vaadin.data.Property.ValueChangeEvent;
 import com.vaadin.data.Property.ValueChangeListener;
-import com.vaadin.tests.components.TestBase;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
 import com.vaadin.tests.util.Log;
 
-public class ComboBoxSlow extends TestBase {
+public class ComboBoxSlow extends AbstractTestUI {
 
     private Log log = new Log(5);
 
@@ -15,19 +16,19 @@ public class ComboBoxSlow extends TestBase {
     }
 
     @Override
-    protected String getDescription() {
+    protected String getTestDescription() {
         return "The ComboBox artificially introduces a server delay to more easily spot problems";
     }
 
     @Override
-    protected void setup() {
+    protected void setup(VaadinRequest request) {
         addComponent(log);
         final SlowComboBox cb = new SlowComboBox();
         cb.setImmediate(true);
         for (int i = 0; i <= 1000; i++) {
             cb.addItem("Item " + i);
         }
-        cb.addListener(new ValueChangeListener() {
+        cb.addValueChangeListener(new ValueChangeListener() {
             @Override
             public void valueChange(ValueChangeEvent event) {
                 log.log("Value changed to " + cb.getValue());
index f030c0f5a0589713c6cb3c3dadfd0296dbeaec2f..e547e68fc11fe2b09a6e0600d4fccea3cf3395dc 100644 (file)
@@ -23,8 +23,10 @@ import java.util.List;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.support.ui.ExpectedCondition;
 
 import com.vaadin.testbench.By;
 import com.vaadin.tests.tb3.MultiBrowserTest;
@@ -58,21 +60,44 @@ public class ComboBoxSlowTest extends MultiBrowserTest {
         sleep(250);
         typeString("Item 12");
 
-        assertEquals(10, getNumberOfSuggestions());
+        final WebElement popup = driver.findElement(By
+                .className("v-filterselect-suggestpopup"));
+        List<WebElement> filteredItems = getFilteredItems(popup);
+        assertEquals("unexpected amount of suggestions found on first page",
+                10, filteredItems.size());
+        assertEquals("wrong filtering result", "Item 12", filteredItems.get(0)
+                .getText());
+        assertEquals("wrong filtering result", "Item 128", filteredItems.get(9)
+                .getText());
+
         assertTrue(isPagingActive());
         goToNextPage();
 
-        sleep(500);
-        assertEquals(1, getNumberOfSuggestions());
-
+        waitUntil(new ExpectedCondition<Boolean>() {
+            @Override
+            public Boolean apply(WebDriver input) {
+                List<WebElement> filteredItems = getFilteredItems(popup);
+                return filteredItems.size() == 1
+                        && "Item 129".equals(filteredItems.get(0).getText());
+            }
+        });
     }
 
     @Test
     public void testTwoMatchesNoPaging() {
         clickComboBoxTextArea();
         typeString("Item 100");
-        assertEquals(2, getNumberOfSuggestions());
         assertFalse(isPagingActive());
+
+        WebElement popup = driver.findElement(By
+                .className("v-filterselect-suggestpopup"));
+        List<WebElement> filteredItems = getFilteredItems(popup);
+        assertEquals("unexpected amount of suggestions found", 2,
+                filteredItems.size());
+        assertEquals("wrong filtering result", "Item 100", filteredItems.get(0)
+                .getText());
+        assertEquals("wrong filtering result", "Item 1000", filteredItems
+                .get(1).getText());
     }
 
     private void clickComboBoxTextArea() {
@@ -105,4 +130,12 @@ public class ComboBoxSlowTest extends MultiBrowserTest {
                 By.className("v-filterselect-nextpage"));
         nextPage.click();
     }
+
+    /*
+     * Gets the list of filtered items from the combobox popup.
+     */
+    private List<WebElement> getFilteredItems(final WebElement popup) {
+        return popup.findElement(By.className("v-filterselect-suggestmenu"))
+                .findElements(By.className("gwt-MenuItem"));
+    }
 }