]> source.dussan.org Git - vaadin-framework.git/commitdiff
Refactor tests to make them less likely to have timing issues
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Mon, 19 May 2014 08:37:36 +0000 (11:37 +0300)
committerVaadin Code Review <review@vaadin.com>
Tue, 20 May 2014 19:31:22 +0000 (19:31 +0000)
Change-Id: Idf24ab4f7c2c48f8246f0c38906d2b8a46f46587

uitest/src/com/vaadin/tests/components/popupview/PopupViewResizeWhileOpenTest.java
uitest/src/com/vaadin/tests/components/table/TableSortingIndicatorTest.java

index 52ffc6b7298bf714149dd3f8656060b24d9a7f53..0c6f0abf3c125f353a1d9c87e9a402cbadf872f7 100644 (file)
@@ -23,7 +23,6 @@ import static org.hamcrest.Matchers.lessThan;
 import org.junit.Test;
 import org.openqa.selenium.By;
 import org.openqa.selenium.Dimension;
-import org.openqa.selenium.WebElement;
 
 import com.vaadin.testbench.elements.ButtonElement;
 import com.vaadin.testbench.elements.PopupViewElement;
@@ -45,21 +44,18 @@ public class PopupViewResizeWhileOpenTest extends MultiBrowserTest {
         // Open PopupView
         $(PopupViewElement.class).first().click();
 
-        // Shadow element
-        WebElement shadow = findElement(By.className("v-shadow"));
-        WebElement vl = $(VerticalLayoutElement.class).id("content-vl");
-
         // Sanity check
-        assertShadowSize(vl, shadow);
+        assertShadowSize();
 
         // Resize
         $(ButtonElement.class).first().click();
-        assertShadowSize(vl, shadow);
+        assertShadowSize();
     }
 
-    private void assertShadowSize(WebElement layout, WebElement shadow) {
-        Dimension shadowSize = shadow.getSize();
-        Dimension layoutSize = layout.getSize();
+    private void assertShadowSize() {
+        Dimension shadowSize = findElement(By.className("v-shadow")).getSize();
+        Dimension layoutSize = $(VerticalLayoutElement.class).id("content-vl")
+                .getSize();
 
         assertThat(shadowSize.height, is(greaterThan(layoutSize.height)));
         assertThat(shadowSize.height, is(lessThan(layoutSize.height + 10)));
index 36a51b35e3b914a2a7cf1baef1f519d682838e7c..8453f5d67f3c55576574c27504494a9af85345a4 100644 (file)
@@ -17,9 +17,9 @@ package com.vaadin.tests.components.table;
 
 import org.junit.Assert;
 import org.junit.Test;
-import org.openqa.selenium.WebElement;
 
-import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.TableElement;
 import com.vaadin.tests.tb3.MultiBrowserTest;
 
 /**
@@ -36,30 +36,35 @@ public class TableSortingIndicatorTest extends MultiBrowserTest {
     public void testTableSortingIndicatorIsVisibleAfterServersideSort() {
         openTestURL();
 
+        ButtonElement button = $(ButtonElement.class).caption("Sort").first();
+        TableElement table = $(TableElement.class).first();
+
         Assert.assertFalse("Descending indicator was prematurely visible",
-                isElementPresent(By.className(TABLE_HEADER_DESC_INDICATOR)));
+                getHeaderClasses(table).contains(TABLE_HEADER_DESC_INDICATOR));
         Assert.assertFalse("Ascending indicator was prematurely visible",
-                isElementPresent(By.className(TABLE_HEADER_ASC_INDICATOR)));
-        WebElement button = driver.findElement(By
-                .vaadin("//Button[caption=\"Sort\"]"));
+                getHeaderClasses(table).contains(TABLE_HEADER_ASC_INDICATOR));
+
         button.click();
         Assert.assertTrue("Indicator did not become visible",
-                isElementPresent(By.className(TABLE_HEADER_DESC_INDICATOR)));
-
+                getHeaderClasses(table).contains(TABLE_HEADER_DESC_INDICATOR));
         Assert.assertFalse("Ascending sort indicator was wrongly visible",
-                isElementPresent(By.className(TABLE_HEADER_ASC_INDICATOR)));
-        WebElement manualSort = driver.findElement(By
-                .className(TABLE_HEADER_DESC_INDICATOR));
-        manualSort.click();
+                getHeaderClasses(table).contains(TABLE_HEADER_ASC_INDICATOR));
+
+        table.getHeaderCell(0).click();
         Assert.assertFalse("Table sort indicator didn't change",
-                isElementPresent(By.className(TABLE_HEADER_DESC_INDICATOR)));
+                getHeaderClasses(table).contains(TABLE_HEADER_DESC_INDICATOR));
         Assert.assertTrue("Ascending sort indicator didn't become visible",
-                isElementPresent(By.className(TABLE_HEADER_ASC_INDICATOR)));
+                getHeaderClasses(table).contains(TABLE_HEADER_ASC_INDICATOR));
+
         button.click();
         Assert.assertTrue(
                 "Descending sort indicator didn't appear on the second serverside sort.",
-                isElementPresent(By.className(TABLE_HEADER_DESC_INDICATOR)));
+                getHeaderClasses(table).contains(TABLE_HEADER_DESC_INDICATOR));
         Assert.assertFalse("Ascending sort indicator didn't disappear",
-                isElementPresent(By.className(TABLE_HEADER_ASC_INDICATOR)));
+                getHeaderClasses(table).contains(TABLE_HEADER_ASC_INDICATOR));
+    }
+
+    private String getHeaderClasses(TableElement table) {
+        return table.getHeaderCell(0).getAttribute("class");
     }
 }