From 24982416e270e2d1c5799739999770e54867a4ee Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 29 Jan 2015 18:54:35 +0200 Subject: [PATCH] Converted ValidationOfRequiredEmptyFields to TB4 Change-Id: Ifab3d891115b30ef2d3f7542cd57ac7215653fe5 --- .../com/vaadin/tests/tb3/AbstractTB3Test.java | 6 + .../ValidationOfRequiredEmptyFields.java | 44 +++--- .../ValidationOfRequiredEmptyFieldsTest.java | 105 +++++++++++++ .../ValidationOfRequiredEmptyFields.html | 147 ------------------ 4 files changed, 134 insertions(+), 168 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/validation/ValidationOfRequiredEmptyFieldsTest.java delete mode 100644 uitest/tb2/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index ef32d9a067..a95def5983 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -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")); diff --git a/uitest/src/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java b/uitest/src/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java index e70a980d70..4fa6eda5c3 100644 --- a/uitest/src/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java +++ b/uitest/src/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java @@ -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 index 0000000000..ab77ba6b26 --- /dev/null +++ b/uitest/src/com/vaadin/tests/validation/ValidationOfRequiredEmptyFieldsTest.java @@ -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() { + + @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 index 62d972e89f..0000000000 --- a/uitest/tb2/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - -New Test - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
New Test
open/run/com.vaadin.tests.validation.ValidationOfRequiredEmptyFields?restartApplication
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VCheckBox[0]/domChild[0]11,8
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTextField[0]60,11
enterCharactervaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTextField[0]The field is required
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]0,0
screenCapturerequired-message
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]13,5
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]28,13
enterCharactervaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]a
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]34,186
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]0,0
screenCaptureerror-must-be-int
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]45,9
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]0,0
waitForVisiblevaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::Root/VTooltip[0]/FlowPanel[0]/VErrorMessage[0]/HTML[0]/domChild[0]/domChild[1]
screenCaptureerror-must-be-int-and-5-to-10-chars
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]0,0
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]12,7
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]124,12
typevaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VCheckBox[0]/domChild[0]8,10
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]13,7
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]0,0
waitForVisiblevaadin=runcomvaadintestsvalidationValidationOfRequiredEmptyFields::Root/VTooltip[0]/FlowPanel[0]/VErrorMessage[0]/HTML[0]/domChild[0]/domChild[1]
screenCaptureempty-invalid-not-required
- - -- 2.39.5