package com.vaadin.v7.tests.components.grid;
+import com.vaadin.server.UserError;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.tests.util.PersonContainer;
+import com.vaadin.ui.Button;
import com.vaadin.v7.ui.Grid;
+@SuppressWarnings("deprecation")
public class GridWithoutRenderer extends AbstractTestUI {
@Override
Grid grid = new Grid();
grid.setContainerDataSource(PersonContainer.createWithTestData());
addComponent(grid);
+ addComponent(new Button("Add error",
+ e -> grid.setComponentError(new UserError("fail"))));
}
}
import com.vaadin.testbench.elements.ComboBoxElement;
import com.vaadin.testbench.elements.MenuBarElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
+import com.vaadin.ui.Notification.Type;
/**
* Test that checks whether Combobox popup is closed on click to autoopen
@Test
public void closeComboboxPopupOnClickToMenuBar() {
- setDebug(true);
openTestURL();
openPopup();
menuBar.click();
assertFalse("Combobox popup items are visible",
isElementPresent(By.className("gwt-MenuItem")));
+ }
+
+ @Test
+ public void closeComboboxPopupOnClickToMenuBarItem() {
+ openTestURL();
openPopup();
- menuBar = selectMenuBar();
+ // hover over menubar to open
WebElement menuBarItem = findElement(
By.className("v-menubar-menuitem-caption"));
- Actions actions = new Actions(getDriver());
- actions.moveToElement(menuBarItem).build().perform();
- menuBar.click();
+ moveToElement(menuBarItem);
+
+ // click submenu item
+ findElements(By.className("v-menubar-menuitem-caption")).get(1).click();
+ assertElementPresent(By.className(
+ "v-Notification-" + Type.HUMANIZED_MESSAGE.getStyle()));
+
assertFalse("Combobox popup items are visible",
isElementPresent(By.className("gwt-MenuItem")));
}
ComboBoxElement combobox = $(ComboBoxElement.class).first();
combobox.openPopup();
- Actions actions = new Actions(getDriver());
- actions.moveToElement(
- getDriver().findElement(By.className("gwt-MenuItem"))).build()
- .perform();
+ moveToElement(findElement(By.className("gwt-MenuItem")));
}
private MenuBarElement selectMenuBar() {
MenuBarElement menuBar = $(MenuBarElement.class).first();
menuBar.focus();
- Actions actions = new Actions(getDriver());
- actions.moveToElement(menuBar).build().perform();
+ moveToElement(menuBar);
return menuBar;
}
+ private void moveToElement(WebElement target) {
+ Actions actions = new Actions(driver);
+ actions.moveToElement(target).build().perform();
+ }
}
ButtonElement button = $(ButtonElement.class).first();
String details0 = grid.getDetails(0).getText();
- System.out.println("details: " + details0);
// change the contents
button.click();
package com.vaadin.tests.components.grid;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.util.List;
import org.junit.Test;
import com.vaadin.testbench.parallel.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
@TestCategory("grid")
public class GridEditorMultiselectTest extends MultiBrowserTest {
public void testSelectCheckboxesEnabledBackOnSave() {
openTestURL();
GridElement grid = openEditor();
- grid.getEditor().save();
+ waitForElementPresent(By.className("v-grid-editor-save"));
+ sleep(100); // wait for repositioning
+ findElement(By.className("v-grid-editor-save")).click();
waitForElementNotPresent(By.className("v-grid-editor-cells"));
assertCheckboxesEnabled(grid, true);
}
public void testSelectCheckboxesEnabledBackOnCancel() {
openTestURL();
GridElement grid = openEditor();
- grid.getEditor().cancel();
- sleep(100);
+ waitForElementPresent(By.className("v-grid-editor-cancel"));
+ sleep(100); // wait for repositioning
+ findElement(By.className("v-grid-editor-cancel")).click();
+ waitForElementNotPresent(By.className("v-grid-editor-cells"));
assertCheckboxesEnabled(grid, true);
}
private GridElement openEditor() {
GridElement grid = $(GridElement.class).first();
grid.getRow(0).doubleClick();
+ waitForElementPresent(By.className("v-grid-editor-cells"));
assertTrue("Grid editor should be displayed.",
grid.getEditor().isDisplayed());
return grid;
// Click on "Last Name" menu item
action.click(visibilityToggle).perform();
waitUntilLoadingIndicatorNotVisible();
+ sleep(100); // wait for layouting
// Check if column "Last Name" is visible
headerCells = grid.getHeaderCells(0);
assertFalse("No spacers should be shown at the start",
spacersAreFoundInDom());
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
assertNotNull("Spacer should be shown after setting it", getSpacer(1));
}
@Test
public void closeVisibleSpacer() {
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
+ assertNotNull("Unexpectedly missing spacer from row 1", getSpacer(1));
selectMenuPath(FEATURES, SPACERS, ROW_1, REMOVE);
assertNull("Spacer should not exist after removing it", getSpacer(1));
}
public void spacerPushesVisibleRowsDown() {
double oldTop = getElementTop(getBodyRow(2));
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
double newTop = getElementTop(getBodyRow(2));
assertGreater("Row below a spacer was not pushed down", newTop, oldTop);
selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING);
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
double oldTop = getElementTop(getSpacer(1));
selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING);
double newTop = getElementTop(getSpacer(2));
selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING);
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
double oldTop = getElementTop(getSpacer(1));
selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_END);
double newTop = getElementTop(getSpacer(1));
selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING);
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
double spacerTop = getElementTop(getSpacer(1));
selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_END);
double rowTop = getElementTop(getBodyRow(2));
scrollVerticallyTo(999999);
long oldBottomScrollTop = getScrollTop();
selectMenuPath(FEATURES, SPACERS, ROW_99, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
assertEquals(
"Adding a spacer underneath the current viewport should "
@Test
public void removingRowAboveSpacerMovesSpacerUp() {
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
WebElement spacer = getSpacer(1);
double originalElementTop = getElementTop(spacer);
public void spacersAreFixedInViewport_firstFreezeThenScroll() {
selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_1_COLUMN);
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
assertEquals(
"Spacer's left position should've been 0 at the " + "beginning",
0d, getElementLeft(getSpacer(1)), WidgetUtil.PIXEL_EPSILON);
int scrollTo = 10;
scrollHorizontallyTo(scrollTo);
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
assertEquals(
"Spacer's left position should've been " + scrollTo
+ " after scrolling " + scrollTo + "px",
selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER);
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
WebElement inputElement = getEscalator()
.findElement(By.tagName("input"));
@Test
public void spacersAreInsertedInCorrectDomPosition() {
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
WebElement tbody = getEscalator().findElement(By.tagName("tbody"));
WebElement spacer = getChild(tbody, 2);
public void spacersAreInCorrectDomPositionAfterScroll()
throws InterruptedException {
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
scrollVerticallyTo(40); // roughly two rows' worth
public void spacerOpenedInViewGetsFocus() {
selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER);
selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX);
+ waitForElementPresent(By.className("v-escalator-spacer"));
tryToTabIntoFocusUpdaterElement();
WebElement focusedElement = getFocusedElement();
assertEquals("input", focusedElement.getTagName());
package com.vaadin.tests.components.ui;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.openqa.selenium.Keys;
-import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import com.vaadin.testbench.elements.TextAreaElement;
@Test
public void textAreaEnterEventPropagation() throws InterruptedException {
openTestURL();
- WebElement textArea = $(TextAreaElement.class).first();
+ TextAreaElement textArea = $(TextAreaElement.class).first();
Actions builder = new Actions(driver);
builder.click(textArea);
- builder.sendKeys(textArea, "first line asdf");
+ builder.sendKeys(textArea, "first line asdf", Keys.ENTER,
+ "second line jkl;");
builder.perform();
waitUntilLoadingIndicatorNotVisible();
- builder.sendKeys(Keys.ENTER);
- builder.perform();
- waitUntilLoadingIndicatorNotVisible();
-
- builder.sendKeys(textArea, "second line jkl;");
- builder.perform();
- waitUntilLoadingIndicatorNotVisible();
-
- builder.perform();
-
+ String text = textArea.getValue();
+ assertEquals("Unexpected text area content,",
+ "first line asdf\nsecond line jkl;", text);
// Should not have triggered shortcut
assertEquals(" ", getLogRow(0));
}
public void testTextAreaEscapeEventPropagation()
throws InterruptedException {
openTestURL();
- WebElement textArea = $(TextAreaElement.class).first();
+ TextAreaElement textArea = $(TextAreaElement.class).first();
Actions builder = new Actions(driver);
builder.click(textArea);
- builder.sendKeys(textArea, "first line asdf");
- builder.perform();
- waitUntilLoadingIndicatorNotVisible();
-
- builder.sendKeys(Keys.ESCAPE);
- builder.perform();
- waitUntilLoadingIndicatorNotVisible();
-
- builder.sendKeys(textArea, "second line jkl;");
+ builder.sendKeys(textArea, "first line asdf", Keys.ESCAPE,
+ "second line jkl;");
builder.perform();
waitUntilLoadingIndicatorNotVisible();
+ String text = textArea.getValue();
+ // sendKeys is erratic and can eat some letters after escape, so only
+ // test that beginning and end are present
+ assertTrue("Unexpected text area content: " + text,
+ text.startsWith("first line asdf"));
+ assertTrue("Unexpected text area content: " + text,
+ text.endsWith("nd line jkl;"));
+ assertFalse("Unexpected text area content: " + text,
+ text.contains("\n"));
assertEquals("1. Escape button pressed", getLogRow(0));
}
@Test
public void testTextFieldEscapeEventPropagation() {
openTestURL();
- WebElement textField = $(TextFieldElement.class).first();
+ TextFieldElement textField = $(TextFieldElement.class).first();
Actions builder2 = new Actions(driver);
builder2.click(textField);
- builder2.sendKeys("third line");
- builder2.perform();
- waitUntilLoadingIndicatorNotVisible();
-
- builder2.sendKeys(Keys.ENTER);
- builder2.perform();
- waitUntilLoadingIndicatorNotVisible();
-
- builder2.sendKeys(Keys.ESCAPE);
+ builder2.sendKeys(textField, "third line", Keys.ESCAPE);
builder2.perform();
waitUntilLoadingIndicatorNotVisible();
- assertEquals("1. Enter button pressed", getLogRow(1));
- assertEquals("2. Escape button pressed", getLogRow(0));
+ String text = textField.getValue();
+ assertEquals("Unexpected text field content,", "third line", text);
+ assertEquals("1. Escape button pressed", getLogRow(0));
}
@Test
public void testTextFieldEnterEventPropagation() {
openTestURL();
- WebElement textField = $(TextFieldElement.class).first();
+ TextFieldElement textField = $(TextFieldElement.class).first();
Actions builder2 = new Actions(driver);
builder2.click(textField);
- builder2.sendKeys("third line");
- builder2.perform();
- waitUntilLoadingIndicatorNotVisible();
-
- builder2.sendKeys(Keys.ENTER);
+ builder2.sendKeys(textField, "third line", Keys.ENTER);
builder2.perform();
waitUntilLoadingIndicatorNotVisible();
+ String text = textField.getValue();
+ assertEquals("Unexpected text field content,", "third line", text);
assertEquals("1. Enter button pressed", getLogRow(0));
}
}
package com.vaadin.tests.elements.menubar;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.util.List;
import org.junit.Before;
import com.vaadin.testbench.elements.MenuBarElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
public class MenuBarUITest extends MultiBrowserTest {
@Override
MenuBarElement menuBar = $(MenuBarElement.class).first();
menuBar.clickItem("File");
+ waitForElementPresent(By.className("v-menubar-popup"));
assertTrue(isItemVisible("Export.."));
menuBar.clickItem("Export..");
+ sleep(100);
assertTrue(isItemVisible("As PDF..."));
menuBar.clickItem("File");
+ sleep(100);
assertFalse(isItemVisible("Export.."));
}
MenuBarElement menuBar = $(MenuBarElement.class).first();
menuBar.clickItem("File");
+ waitForElementPresent(By.className("v-menubar-popup"));
assertTrue(isItemVisible("Save As.."));
menuBar.clickItem("Export..");
+ sleep(100);
assertTrue(isItemVisible("As PDF..."));
// The Edit menu will be opened by moving the mouse over the item (done
// by clickItem). The first click then actually closes the menu.
menuBar.clickItem("Edit");
- sleep(100);
+ waitForElementNotPresent(By.className("v-menubar-popup"));
menuBar.clickItem("Edit");
+ waitForElementPresent(By.className("v-menubar-popup"));
assertFalse(isItemVisible("Save As.."));
assertTrue(isItemVisible("Paste"));
menuBar.clickItem("Edit");
+ sleep(100);
assertFalse(isItemVisible("Save As.."));
assertFalse(isItemVisible("Paste"));
menuBar.clickItem("Edit");
+ sleep(100);
assertFalse(isItemVisible("Save As.."));
assertTrue(isItemVisible("Paste"));
// Menu does not contain a submenu, no need to click twice.
menuBar.clickItem("Help");
+ sleep(100);
assertFalse(isItemVisible("Save As.."));
assertFalse(isItemVisible("Paste"));
// No submenu is open, so click only once to open the File menu.
menuBar.clickItem("File");
+ sleep(100);
assertTrue(isItemVisible("Save As.."));
}
public void testMenuBarClickPath() {
MenuBarElement menuBar = $(MenuBarElement.class).first();
menuBar.clickItem("File", "Export..");
+ waitForElementPresent(By.className("v-menubar-popup"));
assertTrue(isItemVisible("As Doc..."));
}
MenuBarElement menuBar = $(MenuBarElement.class).get(2);
menuBar.clickItem("File");
+ waitForElementPresent(By.className("v-menubar-popup"));
assertTrue(isItemVisible("Open2"));
// Close the menu item
menuBar.clickItem("File");
+ waitForElementNotPresent(By.className("v-menubar-popup"));
menuBar = $(MenuBarElement.class).get(1);
menuBar.clickItem("Edit2");
+ waitForElementPresent(By.className("v-menubar-popup"));
assertTrue(isItemVisible("Cut"));
menuBar.clickItem("Edit2");
+ waitForElementNotPresent(By.className("v-menubar-popup"));
menuBar = $(MenuBarElement.class).first();
menuBar.clickItem("File");
+ waitForElementPresent(By.className("v-menubar-popup"));
assertTrue(isItemVisible("Open"));
}
public void testMenuItemTooltips() {
MenuBarElement first = $(MenuBarElement.class).first();
first.clickItem("File");
+ waitForElementPresent(By.className("v-menubar-popup"));
assertTooltip("Open", "<b>Preformatted</b>\ndescription");
assertTooltip("Save", "plain description, <b>HTML</b> is visible");
assertTooltip("Exit", "HTML\ndescription");
return path;
}
- @ServerClass("com.vaadin.tests.widgetset.server.grid.GridClientColumnRenderers.GridController")
+ @ServerClass("com.vaadin.tests.widgetset.server.v7.grid.GridClientColumnRenderers.GridController")
public static class MyClientGridElement extends GridElement {
}
package com.vaadin.v7.tests.components.grid;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
+import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.parallel.TestCategory;
import com.vaadin.tests.tb3.SingleBrowserTest;
@Test
public void ensureNoError() {
openTestURL();
- // WebElement errorIndicator = findElement(By
- // .cssSelector("v-error-indicator"));
- // System.out.println(errorIndicator);
+ waitForElementPresent(By.className("v-grid"));
List<WebElement> errorIndicator = findElements(
- By.xpath("//span[@class='v-errorindicator']"));
+ By.className("v-errorindicator"));
assertTrue("There should not be an error indicator",
errorIndicator.isEmpty());
+
+ // add an error to ensure that the check is correct
+ $(ButtonElement.class).first().click();
+
+ errorIndicator = findElements(By.className("v-errorindicator"));
+ assertFalse("There should be an error indicator",
+ errorIndicator.isEmpty());
}
}
openTestURL();
String caption = "Tree Item 2";
doubleClick(getTreeNodeByCaption(caption));
- assertLogText("Double Click " + caption);
+ try {
+ assertLogText("Double Click " + caption);
+ } catch (AssertionError e) {
+ // double click is flaky, try again
+ doubleClick(getTreeNodeByCaption(caption));
+ assertLogText("Double Click " + caption);
+ }
changeImmediate();
caption = "Tree Item 3";
doubleClick(getTreeNodeByCaption(caption));
- assertLogText("Double Click " + caption);
+ try {
+ assertLogText("Double Click " + caption);
+ } catch (AssertionError e) {
+ // double click is flaky, try again
+ doubleClick(getTreeNodeByCaption(caption));
+ assertLogText("Double Click " + caption);
+ }
}
private void changeImmediate() {
private void doubleClick(WebElement element) {
new Actions(getDriver()).doubleClick(element).build().perform();
-
+ sleep(100);
}
private void assertLogText(String text) {