From bdbb0b4328a36a66bb492973ca72497bfd34f6ad Mon Sep 17 00:00:00 2001 From: KatriHaapalinna Date: Thu, 19 Apr 2018 15:03:16 +0300 Subject: Colorpicker validation handling (#10821) * ColorTextField, helper methods, and regex for validating and handling text input * Refactored structure to avoid creating new component for validation * Style to adapt to error indicator * Tests for validating input in ColorPickerPreview component's TextField * Merge branch 'master' into colorpicker_validation * Fix path to server class * Fix test: Submit the new value * Fix test: ignore Phantom JS * Fix hsl+hsla validation patterns to accept '%', test value tweaking * Merge branch 'master' of github.com:vaadin/framework into colorpicker_validation * Fix: remove warning when color is updated from elsewhere * Revisions: input validation only once, Logging level WARN * Revisions: unit tests for color pattern matching * Revisions: moved parsing to utility class, tests for parsing all accepted input formats * Fixed import in tests, comments * Revisions: Logger as constant, ignore utility class in serialization test * Corner case tests * Revisions: protected method for parsing error text, fix to test * Revisions: NPE fix --- .../elements/ColorPickerPreviewElement.java | 59 +++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'testbench-api/src') diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/ColorPickerPreviewElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/ColorPickerPreviewElement.java index 03f10ecc7c..d733e7a531 100644 --- a/testbench-api/src/main/java/com/vaadin/testbench/elements/ColorPickerPreviewElement.java +++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/ColorPickerPreviewElement.java @@ -15,9 +15,66 @@ */ package com.vaadin.testbench.elements; +import java.util.List; + +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; import com.vaadin.testbench.elementsbase.ServerClass; -@ServerClass("com.vaadin.ui.ColorPickerPreview") +@ServerClass("com.vaadin.ui.components.colorpicker.ColorPickerPreview") public class ColorPickerPreviewElement extends CssLayoutElement { + /** + * Get whether TextField in ColorPickerPreview has validation errors. + * + * @return true if field has errors, false otherwise + * + * @since + */ + public boolean getColorFieldContainsErrors() { + List caption = findElements( + By.className("v-caption-v-colorpicker-preview-textfield")); + boolean noCaption = caption.isEmpty(); + return noCaption ? noCaption + : caption.get(0).findElements(By.className("v-errorindicator")) + .isEmpty(); + } + + /** + * Get the value of the input element TextField in ColorPickerPreview. + * + * @return the value of the attribute 'value' of the input element + * + * @since + */ + public String getColorFieldValue() { + return getColorTextField().getAttribute("value"); + } + + /** + * Set value of TextField in ColorPickerPreview. Any existing value in the + * field is replaced. + * + * @param value + * text to insert + * + * @since + */ + public void setColorTextFieldValue(String value) { + // Select all text + getColorTextField().sendKeys(Keys.chord(Keys.CONTROL, "a")); + getColorTextField().sendKeys(value); + } + + /** + * @return WebElement representing TextField in + * ColorPickerPreviewComponent + * + * @since + */ + public WebElement getColorTextField() { + return findElement(By.className("v-colorpicker-preview-textfield")); + } } -- cgit v1.2.3