diff options
author | Henrik Paul <henrik@vaadin.com> | 2014-09-04 10:33:48 +0300 |
---|---|---|
committer | Henrik Paul <henrik@vaadin.com> | 2014-09-09 08:45:58 +0000 |
commit | 19a66bd5327a3c5b6e96f7741417181d2884cfd8 (patch) | |
tree | 448fb7249ac94229a65df0a8e1c4d59c80a40c9f | |
parent | b6fa10dc8568ba9599535d143a9b6470620e84fa (diff) | |
download | vaadin-framework-19a66bd5327a3c5b6e96f7741417181d2884cfd8.tar.gz vaadin-framework-19a66bd5327a3c5b6e96f7741417181d2884cfd8.zip |
Escalator test base class (#13334)
Change-Id: Ie3670e4d937b437dc11098746fcd4571e850355f
3 files changed, 131 insertions, 2 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java new file mode 100644 index 0000000000..745802a04f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java @@ -0,0 +1,128 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid.basicfeatures; + +import static org.junit.Assert.assertTrue; + +import org.openqa.selenium.By; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.tests.annotations.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest { + protected static final String COLUMNS_AND_ROWS = "Columns and Rows"; + + protected static final String COLUMNS = "Columns"; + protected static final String ADD_ONE_COLUMN_TO_BEGINNING = "Add one column to beginning"; + protected static final String ADD_ONE_ROW_TO_BEGINNING = "Add one row to beginning"; + + protected static final String HEADER_ROWS = "Header Rows"; + protected static final String BODY_ROWS = "Body Rows"; + protected static final String FOOTER_ROWS = "Footer Rows"; + + @Override + protected Class<?> getUIClass() { + return EscalatorBasicClientFeatures.class; + } + + protected WebElement getEscalator() { + return getDriver().findElement(By.className("v-escalator")); + } + + protected WebElement getHeaderRow(int row) { + return getRow("thead", row); + } + + protected WebElement getBodyRow(int row) { + return getRow("tbody", row); + } + + protected WebElement getFooterRow(int row) { + return getRow("tfoot", row); + } + + protected WebElement getHeaderCell(int row, int col) { + return getCell("thead", row, col); + } + + protected WebElement getBodyCell(int row, int col) { + return getCell("tbody", row, col); + } + + protected WebElement getFooterCell(int row, int col) { + return getCell("tfoot", row, col); + } + + 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 WebElement getRow(String sectionTag, int row) { + WebElement escalator = getEscalator(); + WebElement tableSection = escalator.findElement(By.tagName(sectionTag)); + + try { + return tableSection.findElement(By.xpath("tr[" + (row + 1) + "]")); + } catch (NoSuchElementException e) { + return null; + } + } + + 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(); + } + + private WebElement getMenuElement(String menuCaption) { + return getDriver().findElement( + By.xpath("//td[text() = '" + menuCaption + "']")); + } + + 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(); + } + + protected void assertLogContains(String substring) { + WebElement log = getDriver().findElement(By.cssSelector("#log")); + assertTrue("log did not contain: " + substring, + log.getText().contains(substring)); + } +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java index c15815bf0d..068902ef0f 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java @@ -178,6 +178,7 @@ public class EscalatorBasicClientFeaturesWidget extends escalator = getTestedWidget(); ((EscalatorProxy) escalator).setDebugLabel(debugLabel); addNorth(debugLabel, 200); + debugLabel.getElement().setId("log"); final RowContainer header = escalator.getHeader(); header.setEscalatorUpdater(data.createHeaderUpdater()); diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java index bf4e1975b2..5655684b82 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java @@ -228,8 +228,8 @@ public class EscalatorProxy extends Escalator { debugLabel.setHTML( // "Columns: " + columns + "<br>" + // "Header rows: " + headers + "<br>" + // - "Body rows:" + bodys + "<br>" + // - "Footer rows:" + footers + "<br>" + // + "Body rows: " + bodys + "<br>" + // + "Footer rows: " + footers + "<br>" + // logString); } |