Change-Id: I586c6b624f16969868be1affeac4707db18f5136tags/7.4.8
*/ | */ | ||||
package com.vaadin.tests.components.grid.basicfeatures; | package com.vaadin.tests.components.grid.basicfeatures; | ||||
import org.openqa.selenium.Dimension; | |||||
import java.util.List; | |||||
import org.openqa.selenium.WebElement; | import org.openqa.selenium.WebElement; | ||||
import org.openqa.selenium.interactions.Actions; | |||||
import com.vaadin.testbench.By; | import com.vaadin.testbench.By; | ||||
import com.vaadin.testbench.TestBenchElement; | import com.vaadin.testbench.TestBenchElement; | ||||
@Override | @Override | ||||
protected void selectMenu(String menuCaption) { | 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( | return getDriver().findElement( | ||||
By.xpath("//td[text() = '" + menuCaption + "']")); | 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 | @Override | ||||
protected GridElement getGridElement() { | protected GridElement getGridElement() { | ||||
if (composite) { | if (composite) { |
import java.util.List; | import java.util.List; | ||||
import org.openqa.selenium.By; | import org.openqa.selenium.By; | ||||
import org.openqa.selenium.Dimension; | |||||
import org.openqa.selenium.JavascriptExecutor; | import org.openqa.selenium.JavascriptExecutor; | ||||
import org.openqa.selenium.WebDriver; | import org.openqa.selenium.WebDriver; | ||||
import org.openqa.selenium.WebElement; | import org.openqa.selenium.WebElement; | ||||
return GridBasicFeatures.class; | 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) { | 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 GridElement getGridElement() { | protected GridElement getGridElement() { |
assertFalse("Exception should not exist", | assertFalse("Exception should not exist", | ||||
isElementPresent(NotificationElement.class)); | isElementPresent(NotificationElement.class)); | ||||
assertEquals("There should be no editor error message", null, | assertEquals("There should be no editor error message", null, | ||||
editor.getErrorMessage()); | |||||
getGridElement().getEditor().getErrorMessage()); | |||||
} | } | ||||
@Test | @Test |
// String. | // String. | ||||
// Click header twice to sort descending | // Click header twice to sort descending | ||||
GridCellElement header = grid.getHeaderCell(0, 9); | |||||
header.click(); | |||||
clickHeader(grid.getHeaderCell(0, 9)); | |||||
assertLastSortIsUserOriginated(true); | assertLastSortIsUserOriginated(true); | ||||
assertColumnsAreSortedAs(_(9, 1, SortDirection.ASCENDING)); | assertColumnsAreSortedAs(_(9, 1, SortDirection.ASCENDING)); | ||||
grid.getHeaderCell(0, 9).click(); | |||||
clickHeader(grid.getHeaderCell(0, 9)); | |||||
assertColumnsAreSortedAs(_(9, 1, SortDirection.DESCENDING)); | assertColumnsAreSortedAs(_(9, 1, SortDirection.DESCENDING)); | ||||
// First cells for first 3 rows are (9, 0), (99, 0) and (999, 0) | // First cells for first 3 rows are (9, 0), (99, 0) and (999, 0) | ||||
"Auto"); | "Auto"); | ||||
// Column 10 is random numbers from Random with seed 13334 | // Column 10 is random numbers from Random with seed 13334 | ||||
// Click header to sort ascending | // Click header to sort ascending | ||||
grid.getHeaderCell(0, 10).click(); | |||||
clickHeader(grid.getHeaderCell(0, 10)); | |||||
assertColumnsAreSortedAs(_(10, 1, SortDirection.ASCENDING)); | assertColumnsAreSortedAs(_(10, 1, SortDirection.ASCENDING)); | ||||
for (int i = 0; i < 5; ++i) { | for (int i = 0; i < 5; ++i) { | ||||
// Column 7 is row index as a number. Last three row are original rows | // Column 7 is row index as a number. Last three row are original rows | ||||
// 2, 1 and 0. | // 2, 1 and 0. | ||||
// Click header twice to sort descending | // Click header twice to sort descending | ||||
grid.getHeaderCell(0, 7).click(); | |||||
clickHeader(grid.getHeaderCell(0, 7)); | |||||
assertColumnsAreSortedAs(_(7, 1, SortDirection.ASCENDING)); | assertColumnsAreSortedAs(_(7, 1, SortDirection.ASCENDING)); | ||||
grid.getHeaderCell(0, 7).click(); | |||||
clickHeader(grid.getHeaderCell(0, 7)); | |||||
assertColumnsAreSortedAs(_(7, 1, SortDirection.DESCENDING)); | assertColumnsAreSortedAs(_(7, 1, SortDirection.DESCENDING)); | ||||
for (int i = 0; i < 3; ++i) { | for (int i = 0; i < 3; ++i) { | ||||
} | } | ||||
private void clickHeader(GridCellElement headerCell) { | |||||
new Actions(getDriver()).moveToElement(headerCell, 5, 5).click() | |||||
.perform(); | |||||
} | |||||
private void sendKey(Keys seq) { | private void sendKey(Keys seq) { | ||||
new Actions(getDriver()).sendKeys(seq).perform(); | new Actions(getDriver()).sendKeys(seq).perform(); | ||||
} | } |