]> source.dussan.org Git - vaadin-framework.git/commitdiff
Converted ValidationOfRequiredEmptyFields to TB4
authorArtur Signell <artur@vaadin.com>
Thu, 29 Jan 2015 16:54:35 +0000 (18:54 +0200)
committerVaadin Code Review <review@vaadin.com>
Fri, 6 Mar 2015 11:32:22 +0000 (11:32 +0000)
Change-Id: Ifab3d891115b30ef2d3f7542cd57ac7215653fe5

uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
uitest/src/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java
uitest/src/com/vaadin/tests/validation/ValidationOfRequiredEmptyFieldsTest.java [new file with mode: 0644]
uitest/tb2/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html [deleted file]

index ef32d9a0675cf48914492bf6e3c5a9e01f95c3c4..a95def5983684b8ce50b74d029cb02234cfb9dce 100644 (file)
@@ -158,6 +158,12 @@ public abstract class AbstractTB3Test extends ParallelTest {
         }
     }
 
+    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"));
index e70a980d70386a542c45d448186f43375c3774db..4fa6eda5c3c82ec18afa98508e4023301d0d927a 100644 (file)
@@ -5,11 +5,13 @@ import com.vaadin.data.Property.ValueChangeListener;
 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;
@@ -23,10 +25,10 @@ public class ValidationOfRequiredEmptyFields extends TestBase {
     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());
@@ -35,16 +37,16 @@ public class ValidationOfRequiredEmptyFields extends TestBase {
 
         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) {
@@ -55,20 +57,20 @@ public class ValidationOfRequiredEmptyFields extends TestBase {
                 }
             }
         });
-        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);
@@ -86,8 +88,8 @@ public class ValidationOfRequiredEmptyFields extends TestBase {
     }
 
     @Override
-    protected String getDescription() {
-        return null;
+    protected String getTestDescription() {
+        return "Tests that the lower textfield's tooltip displays validation error messages correctly.";
     }
 
     @Override
diff --git a/uitest/src/com/vaadin/tests/validation/ValidationOfRequiredEmptyFieldsTest.java b/uitest/src/com/vaadin/tests/validation/ValidationOfRequiredEmptyFieldsTest.java
new file mode 100644 (file)
index 0000000..ab77ba6
--- /dev/null
@@ -0,0 +1,105 @@
+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"));
+    }
+
+}
diff --git a/uitest/tb2/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html b/uitest/tb2/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html
deleted file mode 100644 (file)
index 62d972e..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-<?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>