}
}
+ protected WebElement getTooltipErrorElement() {
+ WebElement tooltip = getDriver().findElement(
+ com.vaadin.testbench.By.className("v-tooltip"));
+ return tooltip.findElement(By.className("v-errormessage"));
+ }
+
protected WebElement getTooltipElement() {
return getDriver().findElement(
com.vaadin.testbench.By.className("v-tooltip-text"));
import com.vaadin.data.Validator;
import com.vaadin.data.validator.IntegerValidator;
import com.vaadin.data.validator.StringLengthValidator;
-import com.vaadin.tests.components.TestBase;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.TextField;
-public class ValidationOfRequiredEmptyFields extends TestBase {
+@SuppressWarnings("deprecation")
+public class ValidationOfRequiredEmptyFields extends AbstractTestUI {
private TextField tf;
private CheckBox requiredInput;
private CheckBox stringLengthValidatorInput;
@Override
- protected void setup() {
+ protected void setup(VaadinRequest request) {
requiredInput = new CheckBox("Field required");
requiredInput.setImmediate(true);
- requiredInput.addListener(new ValueChangeListener() {
+ requiredInput.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
tf.setRequired(requiredInput.getValue());
requiredErrorInput = new TextField("Required error message");
requiredErrorInput.setImmediate(true);
- requiredErrorInput.addListener(new ValueChangeListener() {
+ requiredErrorInput.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
tf.setRequiredError(requiredErrorInput.getValue());
}
});
- integerValidatorInput = new CheckBox("Integer.parseInt validator");
+ integerValidatorInput = new CheckBox("Integer validator");
integerValidatorInput.setImmediate(true);
- integerValidatorInput.addListener(new ValueChangeListener() {
+ integerValidatorInput.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
}
}
});
- stringLengthValidatorInput = new CheckBox(
- "stringLength.parseInt validator");
+ stringLengthValidatorInput = new CheckBox("String length validator");
stringLengthValidatorInput.setImmediate(true);
- stringLengthValidatorInput.addListener(new ValueChangeListener() {
+ stringLengthValidatorInput
+ .addValueChangeListener(new ValueChangeListener() {
- @Override
- public void valueChange(ValueChangeEvent event) {
- if (stringLengthValidatorInput.getValue()) {
- tf.addValidator(stringLengthValidator);
- } else {
- tf.removeValidator(stringLengthValidator);
- }
- }
- });
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ if (stringLengthValidatorInput.getValue()) {
+ tf.addValidator(stringLengthValidator);
+ } else {
+ tf.removeValidator(stringLengthValidator);
+ }
+ }
+ });
tf = new TextField();
tf.setImmediate(true);
}
@Override
- protected String getDescription() {
- return null;
+ protected String getTestDescription() {
+ return "Tests that the lower textfield's tooltip displays validation error messages correctly.";
}
@Override
--- /dev/null
+package com.vaadin.tests.validation;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+
+import com.vaadin.testbench.elements.CheckBoxElement;
+import com.vaadin.testbench.elements.TextFieldElement;
+import com.vaadin.testbench.elements.VerticalLayoutElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class ValidationOfRequiredEmptyFieldsTest extends MultiBrowserTest {
+
+ @Override
+ protected boolean requireWindowFocusForIE() {
+ return true;
+ }
+
+ @Test
+ public void requiredErrorMessage() throws Exception {
+ openTestURL();
+ getRequiredCheckbox().click();
+ getRequiredMessageField().click();
+ getRequiredMessageField().sendKeys("The field is required", Keys.TAB);
+ assertTooltipError("The field is required");
+ }
+
+ @Test
+ public void integerValidatorErrorMessage() {
+ openTestURL();
+ getRequiredCheckbox().click();
+ getIntegerValidatorCheckbox().click();
+ getTargetTextField().sendKeys("a", Keys.SHIFT, Keys.TAB);
+ assertTooltipError("Must be an integer");
+ }
+
+ @Test
+ public void requiredWithIntegerAndLengthValidatorErrorMessage() {
+ openTestURL();
+ getRequiredCheckbox().click();
+ getIntegerValidatorCheckbox().click();
+ getLengthValidatorCheckbox().click();
+ getTargetTextField().sendKeys("a", Keys.SHIFT, Keys.TAB);
+ assertTooltipError("Must be an integer\nMust be 5-10 chars");
+ }
+
+ @Test
+ public void integerAndLengthValidatorErrorMessage() {
+ openTestURL();
+ getIntegerValidatorCheckbox().click();
+ getLengthValidatorCheckbox().click();
+ getTargetTextField().sendKeys("a", Keys.SHIFT, Keys.TAB);
+ assertTooltipError("Must be an integer\nMust be 5-10 chars");
+ }
+
+ private void assertTooltipError(final String message) {
+ TextFieldElement e = getTargetTextField();
+ testBenchElement(e).showTooltip();
+ waitUntil(new ExpectedCondition<Boolean>() {
+
+ @Override
+ public Boolean apply(WebDriver input) {
+ return message.equals(getTooltipErrorElement().getText());
+ }
+
+ @Override
+ public String toString() {
+ return "tooltip to be '" + message + "' (was: '"
+ + getTooltipErrorElement().getText() + "')";
+ }
+ });
+ hideTooltip();
+ }
+
+ private void hideTooltip() {
+ $(VerticalLayoutElement.class).first().click();
+ }
+
+ private TextFieldElement getRequiredMessageField() {
+ return $(TextFieldElement.class).all().get(0);
+ }
+
+ private TextFieldElement getTargetTextField() {
+ return $(TextFieldElement.class).all().get(1);
+ }
+
+ private WebElement getRequiredCheckbox() {
+ return $(CheckBoxElement.class).caption("Field required").first()
+ .findElement(By.xpath("input"));
+ }
+
+ private WebElement getIntegerValidatorCheckbox() {
+ return $(CheckBoxElement.class).caption("Integer validator").first()
+ .findElement(By.xpath("input"));
+ }
+
+ private WebElement getLengthValidatorCheckbox() {
+ return $(CheckBoxElement.class).caption("String length validator")
+ .first().findElement(By.xpath("input"));
+ }
+
+}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head profile="http://selenium-ide.openqa.org/profiles/test-case">
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<link rel="selenium.base" href="" />
-<title>New Test</title>
-</head>
-<body>
-<table cellpadding="1" cellspacing="1" border="1">
-<thead>
-<tr><td rowspan="1" colspan="3">New Test</td></tr>
-</thead><tbody>
-<tr>
- <td>open</td>
- <td>/run/com.vaadin.tests.validation.ValidationOfRequiredEmptyFields?restartApplication</td>
- <td></td>
-</tr>
-<tr>
- <td>mouseClick</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VCheckBox[0]/domChild[0]</td>
- <td>11,8</td>
-</tr>
-<tr>
- <td>mouseClick</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTextField[0]</td>
- <td>60,11</td>
-</tr>
-<tr>
- <td>enterCharacter</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTextField[0]</td>
- <td>The field is required</td>
-</tr>
-<tr>
- <td>showTooltip</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]</td>
- <td>0,0</td>
-</tr>
-<tr>
- <td>screenCapture</td>
- <td></td>
- <td>required-message</td>
-</tr>
-<tr>
- <td>mouseClick</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
- <td>13,5</td>
-</tr>
-<tr>
- <td>mouseClick</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]</td>
- <td>28,13</td>
-</tr>
-<tr>
- <td>enterCharacter</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]</td>
- <td>a</td>
-</tr>
-<tr>
- <td>mouseClick</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]</td>
- <td>34,186</td>
-</tr>
-<tr>
- <td>showTooltip</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]</td>
- <td>0,0</td>
-</tr>
-<tr>
- <td>screenCapture</td>
- <td></td>
- <td>error-must-be-int</td>
-</tr>
-<!-- Dummy command to remove the tooltip -->
-<tr>
- <td>showTooltip</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>mouseClick</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]</td>
- <td>45,9</td>
-</tr>
-<tr>
- <td>showTooltip</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]</td>
- <td>0,0</td>
-</tr>
-<tr>
- <td>waitForVisible</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::Root/VTooltip[0]/FlowPanel[0]/VErrorMessage[0]/HTML[0]/domChild[0]/domChild[1]</td>
- <td></td>
-</tr>
-<tr>
- <td>screenCapture</td>
- <td></td>
- <td>error-must-be-int-and-5-to-10-chars</td>
-</tr>
-<tr>
- <td>showTooltip</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]</td>
- <td>0,0</td>
-</tr>
-<tr>
- <td>mouseClick</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]</td>
- <td>12,7</td>
-</tr>
-<tr>
- <td>mouseClick</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]</td>
- <td>124,12</td>
-</tr>
-<tr>
- <td>type</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]</td>
- <td></td>
-</tr>
-<tr>
- <td>mouseClick</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VCheckBox[0]/domChild[0]</td>
- <td>8,10</td>
-</tr>
-<tr>
- <td>mouseClick</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]</td>
- <td>13,7</td>
-</tr>
-<tr>
- <td>showTooltip</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]</td>
- <td>0,0</td>
-</tr>
-<tr>
- <td>waitForVisible</td>
- <td>vaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::Root/VTooltip[0]/FlowPanel[0]/VErrorMessage[0]/HTML[0]/domChild[0]/domChild[1]</td>
- <td></td>
-</tr>
-<tr>
- <td>screenCapture</td>
- <td></td>
- <td>empty-invalid-not-required</td>
-</tr>
-</tbody></table>
-</body>
-</html>