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.

AbstractComponentElement.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2000-2016 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 org.openqa.selenium.WebElement;
  18. import com.vaadin.testbench.By;
  19. import com.vaadin.testbench.elementsbase.AbstractElement;
  20. import com.vaadin.testbench.elementsbase.ServerClass;
  21. @ServerClass("com.vaadin.ui.AbstractComponent")
  22. public class AbstractComponentElement extends AbstractElement {
  23. /**
  24. * Returns the caption of the Component element
  25. *
  26. * @since 8.0
  27. * @return component caption
  28. */
  29. public String getCaption() {
  30. final String GWT_ID_ATTRIBUTE = "aria-labelledby";
  31. WebElement captElem = null;
  32. String captionId = null;
  33. captionId = getAttribute(GWT_ID_ATTRIBUTE);
  34. // IE8 getAttribute returns empty string instead of null
  35. // when there is no attribute with specified name
  36. if (captionId == null || captionId.equals("")) {
  37. WebElement elem = findElement(
  38. By.xpath(".//*[@" + GWT_ID_ATTRIBUTE + "]"));
  39. captionId = elem.getAttribute(GWT_ID_ATTRIBUTE);
  40. }
  41. // element ids are unique, we can search the whole page
  42. captElem = getDriver().findElement(By.id(captionId));
  43. return captElem.getText();
  44. }
  45. public String getHTML() {
  46. return getWrappedElement().getAttribute("innerHTML");
  47. }
  48. public boolean isReadOnly() {
  49. final String READONLY_CSS_CLASS = "v-readonly";
  50. String readonlyClass = getAttribute("class");
  51. // lookin for READONLY_CSS_CLASS string
  52. String[] cssSelectors = readonlyClass.split("\\s");
  53. for (String selector : cssSelectors) {
  54. if (selector.equals(READONLY_CSS_CLASS)) {
  55. return true;
  56. }
  57. }
  58. return false;
  59. }
  60. protected String getStyleAttribute(WebElement element, String styleName) {
  61. String style = element.getAttribute("style");
  62. String[] styles = style.split(";");
  63. for (String stylePart : styles) {
  64. // IE8 has uppercased styles
  65. String lowercasePart = stylePart.toLowerCase();
  66. if (lowercasePart.startsWith(styleName + ":")) {
  67. return lowercasePart.substring(styleName.length() + 1).trim();
  68. }
  69. }
  70. return null;
  71. }
  72. public class ReadOnlyException extends RuntimeException {
  73. }
  74. }