You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ColorPickerPreviewElement.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.testbench.elements;
  17. import java.util.List;
  18. import org.openqa.selenium.Keys;
  19. import org.openqa.selenium.WebElement;
  20. import com.vaadin.testbench.By;
  21. import com.vaadin.testbench.elementsbase.ServerClass;
  22. @ServerClass("com.vaadin.ui.components.colorpicker.ColorPickerPreview")
  23. public class ColorPickerPreviewElement extends CssLayoutElement {
  24. /**
  25. * Get whether TextField in ColorPickerPreview has validation errors.
  26. *
  27. * @return true if field has errors, false otherwise
  28. *
  29. * @since
  30. */
  31. public boolean getColorFieldContainsErrors() {
  32. List<WebElement> caption = findElements(
  33. By.className("v-caption-v-colorpicker-preview-textfield"));
  34. boolean noCaption = caption.isEmpty();
  35. return noCaption ? noCaption
  36. : caption.get(0).findElements(By.className("v-errorindicator"))
  37. .isEmpty();
  38. }
  39. /**
  40. * Get the value of the input element TextField in ColorPickerPreview.
  41. *
  42. * @return the value of the attribute 'value' of the input element
  43. *
  44. * @since
  45. */
  46. public String getColorFieldValue() {
  47. return getColorTextField().getAttribute("value");
  48. }
  49. /**
  50. * Set value of TextField in ColorPickerPreview. Any existing value in the
  51. * field is replaced.
  52. *
  53. * @param value
  54. * text to insert
  55. *
  56. * @since
  57. */
  58. public void setColorTextFieldValue(String value) {
  59. // Select all text
  60. getColorTextField().sendKeys(Keys.chord(Keys.CONTROL, "a"));
  61. getColorTextField().sendKeys(value);
  62. }
  63. /**
  64. * @return <code>WebElement</code> representing TextField in
  65. * ColorPickerPreviewComponent
  66. *
  67. * @since
  68. */
  69. public WebElement getColorTextField() {
  70. return findElement(By.className("v-colorpicker-preview-textfield"));
  71. }
  72. }