From bd08ad12af93da9d14793209d528dfb5e6a1441a Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Tue, 19 May 2015 15:32:03 +0300 Subject: [PATCH] Fix Grid test failures on various browsers Change-Id: I4f28fce512ddb547477f9752ad5f4a602ee13489 --- .../GridBasicClientFeaturesTest.java | 25 +++------------- .../basicfeatures/GridBasicFeaturesTest.java | 30 +++++++++++++------ .../basicfeatures/server/GridEditorTest.java | 2 +- .../basicfeatures/server/GridSortingTest.java | 17 +++++++---- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java index 754529d10d..5d15e53a20 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java @@ -17,9 +17,7 @@ package com.vaadin.tests.components.grid.basicfeatures; import java.util.List; -import org.openqa.selenium.Dimension; import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; import com.vaadin.testbench.By; import com.vaadin.testbench.TestBenchElement; @@ -55,31 +53,16 @@ public abstract class GridBasicClientFeaturesTest extends GridBasicFeaturesTest @Override protected void selectMenu(String menuCaption) { - WebElement menuElement = getMenuElement(menuCaption); - Dimension size = menuElement.getSize(); - new Actions(getDriver()).moveToElement(menuElement, size.width - 10, - size.height / 2).perform(); + // GWT menu does not need to be clicked. + selectMenu(menuCaption, false); } - private WebElement getMenuElement(String menuCaption) { + @Override + protected WebElement getMenuElement(String menuCaption) { return getDriver().findElement( By.xpath("//td[text() = '" + menuCaption + "']")); } - @Override - protected void selectMenuPath(String... menuCaptions) { - new Actions(getDriver()).moveToElement(getMenuElement(menuCaptions[0])) - .click().perform(); - for (int i = 1; i < menuCaptions.length - 1; ++i) { - selectMenu(menuCaptions[i]); - new Actions(getDriver()).moveByOffset(20, 0).perform(); - } - new Actions(getDriver()) - .moveToElement( - getMenuElement(menuCaptions[menuCaptions.length - 1])) - .click().perform(); - } - @Override protected CustomGridElement getGridElement() { if (composite) { diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java index 469bf37c2f..aea2892e3e 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; import org.openqa.selenium.By; +import org.openqa.selenium.Dimension; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -50,21 +51,32 @@ public abstract class GridBasicFeaturesTest extends MultiBrowserTest { return GridBasicFeatures.class; } - protected void selectSubMenu(String menuCaption) { - selectMenu(menuCaption); - new Actions(getDriver()).moveByOffset(100, 0).build().perform(); + protected void selectMenu(String menuCaption) { + selectMenu(menuCaption, true); } - protected void selectMenu(String menuCaption) { - getDriver().findElement( - By.xpath("//span[text() = '" + menuCaption + "']")).click(); + protected void selectMenu(String menuCaption, boolean click) { + WebElement menuElement = getMenuElement(menuCaption); + Dimension size = menuElement.getSize(); + new Actions(getDriver()).moveToElement(menuElement, size.width - 10, + size.height / 2).perform(); + if (click) { + new Actions(getDriver()).click().perform(); + } + } + + protected WebElement getMenuElement(String menuCaption) { + return getDriver().findElement( + By.xpath("//span[text() = '" + menuCaption + "']")); } protected void selectMenuPath(String... menuCaptions) { - selectMenu(menuCaptions[0]); - for (int i = 1; i < menuCaptions.length; i++) { - selectSubMenu(menuCaptions[i]); + selectMenu(menuCaptions[0], true); + for (int i = 1; i < menuCaptions.length - 1; i++) { + selectMenu(menuCaptions[i]); + new Actions(getDriver()).moveByOffset(40, 0).build().perform(); } + selectMenu(menuCaptions[menuCaptions.length - 1], true); } protected CustomGridElement getGridElement() { diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java index f37a94358a..2d9d4018e6 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java @@ -230,7 +230,7 @@ public class GridEditorTest extends GridBasicFeaturesTest { assertFalse("Exception should not exist", isElementPresent(NotificationElement.class)); assertEquals("There should be no editor error message", null, - editor.getErrorMessage()); + getGridElement().getEditor().getErrorMessage()); } @Test diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java index 2d6f7acffd..b06644f0c8 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java @@ -141,12 +141,12 @@ public class GridSortingTest extends GridBasicFeaturesTest { // String. // Click header twice to sort descending - GridCellElement header = grid.getHeaderCell(0, 9); - header.click(); + clickHeader(grid.getHeaderCell(0, 9)); + assertLastSortIsUserOriginated(true); assertColumnsAreSortedAs(_(9, 1, SortDirection.ASCENDING)); - grid.getHeaderCell(0, 9).click(); + clickHeader(grid.getHeaderCell(0, 9)); assertColumnsAreSortedAs(_(9, 1, SortDirection.DESCENDING)); // First cells for first 3 rows are (9, 0), (99, 0) and (999, 0) @@ -163,7 +163,7 @@ public class GridSortingTest extends GridBasicFeaturesTest { "Auto"); // Column 10 is random numbers from Random with seed 13334 // Click header to sort ascending - grid.getHeaderCell(0, 10).click(); + clickHeader(grid.getHeaderCell(0, 10)); assertColumnsAreSortedAs(_(10, 1, SortDirection.ASCENDING)); for (int i = 0; i < 5; ++i) { @@ -181,9 +181,9 @@ public class GridSortingTest extends GridBasicFeaturesTest { // Column 7 is row index as a number. Last three row are original rows // 2, 1 and 0. // Click header twice to sort descending - grid.getHeaderCell(0, 7).click(); + clickHeader(grid.getHeaderCell(0, 7)); assertColumnsAreSortedAs(_(7, 1, SortDirection.ASCENDING)); - grid.getHeaderCell(0, 7).click(); + clickHeader(grid.getHeaderCell(0, 7)); assertColumnsAreSortedAs(_(7, 1, SortDirection.DESCENDING)); for (int i = 0; i < 3; ++i) { @@ -195,6 +195,11 @@ public class GridSortingTest extends GridBasicFeaturesTest { } + private void clickHeader(GridCellElement headerCell) { + new Actions(getDriver()).moveToElement(headerCell, 5, 5).click() + .perform(); + } + private void sendKey(Keys seq) { new Actions(getDriver()).sendKeys(seq).perform(); } -- 2.39.5