PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/atlassian-pageobjects-elements/src/main/java/com/atlassian/pageobjects/elements/PageElement.java

https://bitbucket.org/atlassian/atlassian-selenium
Java | 226 lines | 57 code | 27 blank | 142 comment | 0 complexity | 860cf50c7d22f3062639899af339abb8 MD5 | raw file
  1. package com.atlassian.pageobjects.elements;
  2. import com.atlassian.annotations.PublicApi;
  3. import com.atlassian.pageobjects.elements.search.PageElementSearch;
  4. import com.atlassian.pageobjects.elements.timeout.TimeoutType;
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.Dimension;
  7. import org.openqa.selenium.Point;
  8. import org.openqa.selenium.WebElement;
  9. import javax.annotation.Nonnull;
  10. import javax.annotation.Nullable;
  11. import java.util.List;
  12. import java.util.Set;
  13. /**
  14. * Represents an HTML element that is expected on a DOM of a page.
  15. *
  16. * @since 2.0
  17. */
  18. @PublicApi
  19. public interface PageElement extends PageElementFinder, PageElementSearch
  20. {
  21. /**
  22. * Obtain the underlying {@link WebElement}.
  23. *
  24. * @return the underlying {@link WebElement}.
  25. * @since 3.0
  26. */
  27. WebElement asWebElement();
  28. /**
  29. * Whether this element is currently on the DOM of the page
  30. *
  31. * @return True if this element tag exists in the DOM, false otherwise.
  32. */
  33. boolean isPresent();
  34. /**
  35. * Whether this element is visible on the page
  36. *
  37. * @return true if this element is visible on the page, false otherwise.
  38. */
  39. boolean isVisible();
  40. /**
  41. * Whether this element is enabled on the page
  42. *
  43. * @return True if this element is enabled, false otherwise.
  44. */
  45. boolean isEnabled();
  46. /**
  47. * Whether this element is selected on the page. Useful on checkboxes and radio buttons.
  48. * For checkboxes, returns {@code true} if the checkbox is checked.
  49. * For radio buttons, returns {@code true}
  50. * if the radio button this class represents is selected.
  51. *
  52. * @return {@code true} if this element is selected, {@code false} otherwise.
  53. */
  54. boolean isSelected();
  55. /**
  56. * @return value of the "id" attribute of this element, or {@code null} if the "id" attribute is not defined
  57. *
  58. * @since 2.3
  59. */
  60. @Nullable
  61. String getId();
  62. /**
  63. * Get a set of CSS classes associated with this element.
  64. *
  65. * @return CSS classes of this element, or an empty set
  66. * @since 2.3
  67. */
  68. @Nonnull
  69. Set<String> getCssClasses();
  70. /**
  71. * Whether this element has the given class set
  72. *
  73. * @param className The name of the class to check
  74. * @return true if this element's class attribute contains the given classname, false otherwise.
  75. */
  76. boolean hasClass(@Nonnull String className);
  77. /**
  78. * Get the value of the given attribute of this element.
  79. *
  80. * @param name The name of the attribute.
  81. * @return The attribute's current value, or null if the value is not set
  82. */
  83. @Nullable
  84. String getAttribute(@Nonnull String name);
  85. /**
  86. * Whether this element has an attribute set to a specific value
  87. * @param name The attribute name
  88. * @param value The expected value
  89. * @return true if attribute is set to the specific value, false otherwise or if attribute is not present
  90. */
  91. boolean hasAttribute(@Nonnull String name, @Nullable String value);
  92. /**
  93. * Get the visible innerText of this element, including sub-elements, without any leading or trailing whitespaces.
  94. *
  95. * @return The innerText of this element.
  96. */
  97. @Nonnull
  98. String getText();
  99. /**
  100. * Get the tag name of this element
  101. * @return The tag name
  102. */
  103. @Nonnull
  104. String getTagName();
  105. /**
  106. * Get the value of this element's "value" attribute.
  107. *
  108. * @return The value of this element's "value" attribute, or null if the value is not set.
  109. */
  110. @Nullable
  111. String getValue();
  112. /**
  113. * Location of this element on the page (top-left corner)
  114. *
  115. * @return location of the element on the page
  116. */
  117. @Nonnull
  118. Point getLocation();
  119. /**
  120. * Dimension of this element on the page
  121. *
  122. * @return size of the element on the page
  123. */
  124. @Nonnull
  125. Dimension getSize();
  126. /**
  127. * Click this element
  128. *
  129. * @return The eleemnt that got clicked.
  130. */
  131. @Nonnull
  132. PageElement click();
  133. /**
  134. * Simulate typing into this element. This will append the keystrokes to the end of the text entry element.
  135. *
  136. * @param keys keys to type
  137. * @return The Element that got typed in.
  138. */
  139. @Nonnull
  140. PageElement type(CharSequence... keys);
  141. /**
  142. * Select an element. This method will work against radio buttons, "option" elements within a "select" and checkboxes
  143. *
  144. * @return The Element that got selected
  145. */
  146. @Nonnull
  147. PageElement select();
  148. /**
  149. * Clear the value of the text entry element.
  150. *
  151. * @return The Element that got cleared.
  152. */
  153. @Nonnull
  154. PageElement clear();
  155. /**
  156. * Returns a list of element's that match the given locator within this element
  157. * @param locator The locator mechanism
  158. * @return A list of elements that are located within this element.
  159. */
  160. @Nonnull
  161. List<PageElement> findAll(@Nonnull By locator);
  162. /**
  163. * <p>
  164. * Returns an element that will match the given locator within this element.
  165. * </p>
  166. *
  167. * <p>
  168. * This method will <i>always</i> return an element instance. Use {@link #isPresent()}
  169. * to check whether a corresponding element on the page actually exists.
  170. * </p>
  171. *
  172. * @param locator The locator mechanism
  173. * @return An element that will be located within this element.
  174. */
  175. @Nonnull
  176. PageElement find(@Nonnull By locator);
  177. /**
  178. * Creates a timed element based on this element's locator.
  179. *
  180. * @return A TimedElement that is based on this element's locator.
  181. */
  182. @Nonnull
  183. TimedElement timed();
  184. /**
  185. * Gets a <tt>PageElementJavascript</tt> for this element
  186. *
  187. * @return API to execute javascript on this element.
  188. */
  189. @Nonnull
  190. PageElementJavascript javascript();
  191. /**
  192. * Returns an instance equivalent to this element, with a changed <tt>timeoutType</tt>.
  193. *
  194. * @param timeoutType new timeout
  195. * @return new element with given <tt>timeoutType</tt>
  196. */
  197. @Nonnull
  198. PageElement withTimeout(@Nonnull TimeoutType timeoutType);
  199. }