From 33c2cb153cc26ed664af93440b4260e9c9ad9dee Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Tue, 2 Dec 2014 15:31:46 +0200 Subject: [PATCH] Fix Escalator testing with assert enabled on PhantomJS (#13334) Change-Id: I6a5eb39c44873932bdde3a229f7ed52bc7c4df8c --- .../com/vaadin/client/ui/grid/Escalator.java | 3 +- .../EscalatorBasicClientFeaturesTest.java | 88 +++++++++---------- .../{ => escalator}/EscalatorBasicsTest.java | 7 +- .../{ => escalator}/EscalatorColspanTest.java | 4 +- .../EscalatorColumnFreezingTest.java | 10 ++- .../EscalatorRowColumnTest.java | 11 ++- .../{ => escalator}/EscalatorScrollTest.java | 4 +- .../EscalatorUpdaterUiTest.java | 5 +- 8 files changed, 73 insertions(+), 59 deletions(-) rename uitest/src/com/vaadin/tests/components/grid/basicfeatures/{ => escalator}/EscalatorBasicsTest.java (87%) rename uitest/src/com/vaadin/tests/components/grid/basicfeatures/{ => escalator}/EscalatorColspanTest.java (94%) rename uitest/src/com/vaadin/tests/components/grid/basicfeatures/{ => escalator}/EscalatorColumnFreezingTest.java (90%) rename uitest/src/com/vaadin/tests/components/grid/basicfeatures/{ => escalator}/EscalatorRowColumnTest.java (95%) rename uitest/src/com/vaadin/tests/components/grid/basicfeatures/{ => escalator}/EscalatorScrollTest.java (91%) rename uitest/src/com/vaadin/tests/components/grid/basicfeatures/{ => escalator}/EscalatorUpdaterUiTest.java (95%) diff --git a/client/src/com/vaadin/client/ui/grid/Escalator.java b/client/src/com/vaadin/client/ui/grid/Escalator.java index bb4ca6ba78..64b0e31f84 100644 --- a/client/src/com/vaadin/client/ui/grid/Escalator.java +++ b/client/src/com/vaadin/client/ui/grid/Escalator.java @@ -1556,7 +1556,7 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker private void paintInsertCells(final TableRowElement tr, int logicalRowIndex, final int offset, final int numberOfCells) { - assert Document.get().isOrHasChild(tr) : "The row must be attached to the document"; + assert root.isOrHasChild(tr) : "The row must be attached to the document"; flyweightRow.setup(tr, logicalRowIndex, columnConfiguration.getCalculatedColumnWidths()); @@ -1581,6 +1581,7 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker } else { referenceCell = null; } + for (FlyweightCell cell : cells) { referenceCell = insertAfterReferenceAndUpdateIt(tr, cell.getElement(), referenceCell); diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java index 31a142d556..0b2a7a7358 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java @@ -22,14 +22,14 @@ import static org.junit.Assert.fail; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; +import com.vaadin.testbench.TestBenchElement; import com.vaadin.tests.annotations.TestCategory; import com.vaadin.tests.tb3.MultiBrowserTest; -@TestCategory("grid") +@TestCategory("escalator") public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest { protected static final String COLUMNS_AND_ROWS = "Columns and Rows"; @@ -69,12 +69,12 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest return EscalatorBasicClientFeatures.class; } - protected WebElement getEscalator() { - try { - return getDriver().findElement(By.className("v-escalator")); - } catch (NoSuchElementException e) { - return null; + protected TestBenchElement getEscalator() { + By className = By.className("v-escalator"); + if (isElementPresent(className)) { + return (TestBenchElement) findElement(className); } + return null; } /** @@ -83,7 +83,7 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest * calculation starts from the end (-1 is the last, -2 is the * second-to-last etc) */ - protected WebElement getHeaderRow(int row) { + protected TestBenchElement getHeaderRow(int row) { return getRow("thead", row); } @@ -93,7 +93,7 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest * calculation starts from the end (-1 is the last, -2 is the * second-to-last etc) */ - protected WebElement getBodyRow(int row) { + protected TestBenchElement getBodyRow(int row) { return getRow("tbody", row); } @@ -103,7 +103,7 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest * calculation starts from the end (-1 is the last, -2 is the * second-to-last etc) */ - protected WebElement getFooterRow(int row) { + protected TestBenchElement getFooterRow(int row) { return getRow("tfoot", row); } @@ -113,7 +113,7 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest * calculation starts from the end (-1 is the last, -2 is the * second-to-last etc) */ - protected WebElement getHeaderCell(int row, int col) { + protected TestBenchElement getHeaderCell(int row, int col) { return getCell("thead", row, col); } @@ -123,7 +123,7 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest * calculation starts from the end (-1 is the last, -2 is the * second-to-last etc) */ - protected WebElement getBodyCell(int row, int col) { + protected TestBenchElement getBodyCell(int row, int col) { return getCell("tbody", row, col); } @@ -133,7 +133,7 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest * calculation starts from the end (-1 is the last, -2 is the * second-to-last etc) */ - protected WebElement getFooterCell(int row, int col) { + protected TestBenchElement getFooterCell(int row, int col) { return getCell("tfoot", row, col); } @@ -143,17 +143,13 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest * calculation starts from the end (-1 is the last, -2 is the * second-to-last etc) */ - private WebElement getCell(String sectionTag, int row, int col) { - WebElement rowElement = getRow(sectionTag, row); - if (rowElement != null) { - try { - return rowElement.findElement(By.xpath("*[" + (col + 1) + "]")); - } catch (NoSuchElementException e) { - return null; - } - } else { - return null; + private TestBenchElement getCell(String sectionTag, int row, int col) { + TestBenchElement rowElement = getRow(sectionTag, row); + By xpath = By.xpath("*[" + (col + 1) + "]"); + if (rowElement != null && rowElement.isElementPresent(xpath)) { + return (TestBenchElement) rowElement.findElement(xpath); } + return null; } /** @@ -162,35 +158,35 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest * calculation starts from the end (-1 is the last, -2 is the * second-to-last etc) */ - private WebElement getRow(String sectionTag, int row) { - WebElement escalator = getEscalator(); + private TestBenchElement getRow(String sectionTag, int row) { + TestBenchElement escalator = getEscalator(); WebElement tableSection = escalator.findElement(By.tagName(sectionTag)); + By xpath; - try { - if (row >= 0) { - int fromFirst = row + 1; - return tableSection.findElement(By.xpath("tr[" + fromFirst - + "]")); - } else { - int fromLast = Math.abs(row + 1); - return tableSection.findElement(By.xpath("tr[last() - " - + fromLast + "]")); - } - } catch (NoSuchElementException e) { - return null; + if (row >= 0) { + int fromFirst = row + 1; + xpath = By.xpath("tr[" + fromFirst + "]"); + } else { + int fromLast = Math.abs(row + 1); + xpath = By.xpath("tr[last() - " + fromLast + "]"); + } + if (tableSection != null + && ((TestBenchElement) tableSection).isElementPresent(xpath)) { + return (TestBenchElement) tableSection.findElement(xpath); } + return null; } protected void selectMenu(String menuCaption) { - WebElement menuElement = getMenuElement(menuCaption); + TestBenchElement menuElement = getMenuElement(menuCaption); Dimension size = menuElement.getSize(); new Actions(getDriver()).moveToElement(menuElement, size.width - 10, size.height / 2).perform(); } - private WebElement getMenuElement(String menuCaption) { - return getDriver().findElement( - By.xpath("//td[text() = '" + menuCaption + "']")); + private TestBenchElement getMenuElement(String menuCaption) { + return (TestBenchElement) findElement(By.xpath("//td[text() = '" + + menuCaption + "']")); } protected void selectMenuPath(String... menuCaptions) { @@ -217,7 +213,7 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest } private String getLogText() { - WebElement log = getDriver().findElement(By.cssSelector("#log")); + WebElement log = findElement(By.cssSelector("#log")); return log.getText(); } @@ -240,8 +236,8 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest executeScript("arguments[0].scrollTop = " + px, getVeticalScrollbar()); } - private WebElement getVeticalScrollbar() { - return getEscalator().findElement( + private TestBenchElement getVeticalScrollbar() { + return (TestBenchElement) getEscalator().findElement( By.className("v-escalator-scroller-vertical")); } @@ -250,8 +246,8 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest getHorizontalScrollbar()); } - private WebElement getHorizontalScrollbar() { - return getEscalator().findElement( + private TestBenchElement getHorizontalScrollbar() { + return (TestBenchElement) getEscalator().findElement( By.className("v-escalator-scroller-horizontal")); } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicsTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorBasicsTest.java similarity index 87% rename from uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicsTest.java rename to uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorBasicsTest.java index bac5c24fbe..95ed6ab3ff 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicsTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorBasicsTest.java @@ -13,14 +13,17 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.grid.basicfeatures; +package com.vaadin.tests.components.grid.basicfeatures.escalator; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; +import java.io.IOException; + import org.junit.Test; import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; public class EscalatorBasicsTest extends EscalatorBasicClientFeaturesTest { @@ -34,7 +37,7 @@ public class EscalatorBasicsTest extends EscalatorBasicClientFeaturesTest { } @Test - public void testDetachingASemiPopulatedEscalator() { + public void testDetachingASemiPopulatedEscalator() throws IOException { setDebug(true); openTestURL(); diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColspanTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColspanTest.java similarity index 94% rename from uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColspanTest.java rename to uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColspanTest.java index 3c3e16e65a..01247e31f7 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColspanTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColspanTest.java @@ -13,13 +13,15 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.grid.basicfeatures; +package com.vaadin.tests.components.grid.basicfeatures.escalator; import static org.junit.Assert.assertEquals; import org.junit.Test; import org.openqa.selenium.WebElement; +import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; + public class EscalatorColspanTest extends EscalatorBasicClientFeaturesTest { private static final int NO_COLSPAN = 1; diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColumnFreezingTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java similarity index 90% rename from uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColumnFreezingTest.java rename to uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java index 2ea0d8638b..6b9e36b235 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorColumnFreezingTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.grid.basicfeatures; +package com.vaadin.tests.components.grid.basicfeatures.escalator; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -25,6 +25,8 @@ import java.util.regex.Pattern; import org.junit.Test; import org.openqa.selenium.WebElement; +import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; + public class EscalatorColumnFreezingTest extends EscalatorBasicClientFeaturesTest { @@ -42,12 +44,12 @@ public class EscalatorColumnFreezingTest extends + "\\((\\d+)px," // any end of the string - + ".*"); + + ".*", Pattern.CASE_INSENSITIVE); // @formatter:on - private final static Pattern LEFT_PATTERN = Pattern - .compile(".*left: (\\d+)px.*"); + private final static Pattern LEFT_PATTERN = Pattern.compile( + ".*left: (\\d+)px.*", Pattern.CASE_INSENSITIVE); private static final int NO_FREEZE = -1; diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorRowColumnTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorRowColumnTest.java similarity index 95% rename from uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorRowColumnTest.java rename to uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorRowColumnTest.java index 831524b4fb..392a901463 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorRowColumnTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorRowColumnTest.java @@ -13,16 +13,19 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.grid.basicfeatures; +package com.vaadin.tests.components.grid.basicfeatures.escalator; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import org.junit.Test; import org.openqa.selenium.By; +import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; + public class EscalatorRowColumnTest extends EscalatorBasicClientFeaturesTest { /** @@ -175,7 +178,8 @@ public class EscalatorRowColumnTest extends EscalatorBasicClientFeaturesTest { scrollVerticallyTo(2000); // more like 1857, but this should be enough. // if not found, an exception is thrown here - findElement(By.xpath("//td[text()='Cell: 9,99']")); + assertTrue("Wanted cell was not visible", + isElementPresent(By.xpath("//td[text()='Cell: 9,99']"))); } @Test @@ -186,7 +190,8 @@ public class EscalatorRowColumnTest extends EscalatorBasicClientFeaturesTest { scrollVerticallyTo(2000); // more like 1857, but this should be enough. // if not found, an exception is thrown here - findElement(By.xpath("//td[text()='Cell: 9,99']")); + assertTrue("Wanted cell was not visible", + isElementPresent(By.xpath("//td[text()='Cell: 9,99']"))); } @Test diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorScrollTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorScrollTest.java similarity index 91% rename from uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorScrollTest.java rename to uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorScrollTest.java index d2be88b557..91527504a5 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorScrollTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorScrollTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.grid.basicfeatures; +package com.vaadin.tests.components.grid.basicfeatures.escalator; import static org.junit.Assert.assertEquals; @@ -21,6 +21,8 @@ import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; +import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; + public class EscalatorScrollTest extends EscalatorBasicClientFeaturesTest { /** diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorUpdaterUiTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorUpdaterUiTest.java similarity index 95% rename from uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorUpdaterUiTest.java rename to uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorUpdaterUiTest.java index c1c3a31b77..85d3fc0bac 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorUpdaterUiTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorUpdaterUiTest.java @@ -13,10 +13,13 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.tests.components.grid.basicfeatures; +package com.vaadin.tests.components.grid.basicfeatures.escalator; import org.junit.Test; +import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; +import com.vaadin.tests.components.grid.basicfeatures.EscalatorUpdaterUi; + public class EscalatorUpdaterUiTest extends EscalatorBasicClientFeaturesTest { @Override protected Class getUIClass() { -- 2.39.5