package com.vaadin.tests.components.combobox;
-import org.junit.Assert;
+import static org.junit.Assert.assertFalse;
+
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import com.vaadin.testbench.elements.MenuBarElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
import com.vaadin.tests.tb3.newelements.ComboBoxElement;
+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();
MenuBarElement menuBar = selectMenuBar();
menuBar.click();
- Assert.assertFalse("Combobox popup items are visible",
+ 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();
- Assert.assertFalse("Combobox popup items are visible",
+ 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")));
}
combobox.openPopup();
combobox.focus();
- 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();
+ }
}
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) {
+ doubleClick(getTreeNodeByCaption(caption));
+ assertLogText("Double Click " + caption);
+ }
}
private void changeImmediate() {
.findElement(By.xpath("//span[text() = '" + caption + "']"));
}
- private void doubleClick(WebElement element) {
+ private void doubleClick(WebElement element) throws InterruptedException {
new Actions(getDriver()).doubleClick(element).build().perform();
-
+ sleep(100);
}
private void assertLogText(String text) {
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;
import com.vaadin.testbench.elements.TextFieldElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
-import static org.junit.Assert.assertEquals;
-
/**
* Tests that the TextArea widget correctly stops ENTER events from propagating.
*
@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(Keys.ENTER);
- builder.sendKeys(textArea, "second line jkl;");
+ builder.sendKeys(textArea, "first line asdf", Keys.ENTER,
+ "second line jkl;");
builder.perform();
+ waitUntilLoadingIndicatorNotVisible();
+ 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.sendKeys(Keys.ESCAPE);
- 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() throws InterruptedException {
+ 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.sendKeys(Keys.ENTER);
- sleep(100);
- builder2.sendKeys(Keys.ESCAPE);
- sleep(100);
+ builder2.sendKeys(textField, "third line", Keys.ESCAPE);
builder2.perform();
- sleep(100);
+ 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.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));
}
}