aboutsummaryrefslogtreecommitdiffstats
path: root/testbench-api/src/main
diff options
context:
space:
mode:
authorKatriHaapalinna <katri@vaadin.com>2018-04-19 15:03:16 +0300
committerIlia Motornyi <elmot@vaadin.com>2018-04-19 15:03:16 +0300
commitbdbb0b4328a36a66bb492973ca72497bfd34f6ad (patch)
tree62272a7e1fbe88f868b2fe13345f2d10fadc2c7e /testbench-api/src/main
parent07c6456da8f15d279340188dc86d7424cee36cd0 (diff)
downloadvaadin-framework-bdbb0b4328a36a66bb492973ca72497bfd34f6ad.tar.gz
vaadin-framework-bdbb0b4328a36a66bb492973ca72497bfd34f6ad.zip
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
Diffstat (limited to 'testbench-api/src/main')
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/ColorPickerPreviewElement.java59
1 files changed, 58 insertions, 1 deletions
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<WebElement> 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 <code>WebElement</code> representing TextField in
+ * ColorPickerPreviewComponent
+ *
+ * @since
+ */
+ public WebElement getColorTextField() {
+ return findElement(By.className("v-colorpicker-preview-textfield"));
+ }
}