diff options
author | Artur Signell <artur@vaadin.com> | 2015-01-29 18:54:35 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-03-06 11:32:22 +0000 |
commit | bb73827b48e54086e24415df0ae19e44a098ac87 (patch) | |
tree | b1587b6567fd47c0fabd42d0ba2e6b1aa7d9949b /uitest/src | |
parent | 8cc721393c4b6599eccb2e519f56d85dc5285adc (diff) | |
download | vaadin-framework-bb73827b48e54086e24415df0ae19e44a098ac87.tar.gz vaadin-framework-bb73827b48e54086e24415df0ae19e44a098ac87.zip |
Converted ValidationOfRequiredEmptyFields to TB4
Change-Id: Ifab3d891115b30ef2d3f7542cd57ac7215653fe5
Diffstat (limited to 'uitest/src')
3 files changed, 134 insertions, 21 deletions
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<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")); + } + +} |