]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix and optimize TabsheetScrollingTest
authorHenri Sara <hesara@vaadin.com>
Wed, 13 Jul 2016 12:37:13 +0000 (15:37 +0300)
committerMarko Gronroos <magi@vaadin.com>
Wed, 13 Jul 2016 15:52:05 +0000 (18:52 +0300)
The test was based on the assumption that only the visible tabs are
in the DOM of the tab bar. This assumption was no longer true.
Furthermore, the test iterated over all tabs which led to performance
issues especially on IE8.

Change-Id: If8e904418bdb81cf2762475b317adb2b21dcc032

uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetScrollingTest.java

index 47753e09d38b4ae7effdc50a5deb6c2cf0f4d937..42c384dd78f3da01b321f50570909a1cbba7d742 100644 (file)
@@ -18,6 +18,7 @@ package com.vaadin.tests.components.tabsheet;
 import org.junit.Assert;
 import org.junit.Test;
 import org.openqa.selenium.Keys;
+import org.openqa.selenium.Point;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.interactions.Actions;
 
@@ -40,7 +41,7 @@ public class TabsheetScrollingTest extends MultiBrowserTest {
     }
 
     private WebElement getTab(int index) {
-        return getDriver().findElement(By.vaadin("//TabSheet#tab[1]"));
+        return getDriver().findElement(By.vaadin("//TabSheet#tab["+index+"]"));
     }
 
     private String getHideButtonText() {
@@ -52,16 +53,27 @@ public class TabsheetScrollingTest extends MultiBrowserTest {
         new Actions(getDriver()).sendKeys(key).perform();
     }
 
+    private WebElement getTabByCaption(TabSheetElement ts, String caption) {
+        WebElement tabBar = ts.findElement(By.className("v-tabsheet-tabs"));
+        return tabBar.findElement(By.xpath("./tbody/tr/td[./div/div/div[contains(., normalize-space('"+caption+"'))]]"));
+    }
+
+    private boolean isTabVisible(TabSheetElement ts, String tabCaption) {
+        WebElement tab = getTabByCaption(ts, tabCaption);
+        Point location = tab.getLocation();
+        return location.getX() > 0 && location.getX() < ts.getSize().getWidth();
+    }
+
     @Test
     public void serverChangeShouldShowTab() {
         openTestURL();
         $(ButtonElement.class).id(TabsheetScrolling.SELECT_LAST).click();
         TabSheetElement tabsheetFixed = $(TabSheetElement.class).first();
         Assert.assertTrue("Select last should scroll last tab into view",
-                tabsheetFixed.getTabCaptions().contains("Tab 99"));
+                isTabVisible(tabsheetFixed, "Tab 99"));
         $(ButtonElement.class).id(TabsheetScrolling.SELECT_FIRST).click();
         Assert.assertTrue("Select first should scroll first tab into view",
-                tabsheetFixed.getTabCaptions().contains("Tab 1"));
+                isTabVisible(tabsheetFixed, "Tab 1"));
 
     }
 }