Class UIElement

java.lang.Object
allurium.primitives.UIElement
All Implemented Interfaces:
AlluriumElement, ListComponent, WebElementMeta
Direct Known Subclasses:
AbstractInputElement, AbstractSwitcher, AbstractWidget, Cell, Header, Icon, Image, Label, Line, Link, ListItem, MenuItem, Partition, Row, Select, Symbol, Tab, Text, TextLine, Title, UploadField, Value

public class UIElement extends Object implements AlluriumElement, ListComponent
Represents a wrapper around a Selenide element, providing utility methods for interaction and validation. The `UIElement` class integrates with Allure for step logging and reporting.

Supports custom naming, parent-child relationships, and dynamic attribute-based assertions. Includes methods for handling visibility, existence, and text content checks with retry mechanisms.

Features:

  • Custom initialization using locators or Selenide elements
  • Allure integration for logging steps and generating reports
  • Support for retry mechanisms during assertions
  • Convenience methods for common UI interactions (e.g., click, hover, assert visibility)

Example Usage:


 UIElement element = UIElement.$uiElement(By.id("example"));
 element.click();
 element.assertVisible();
 
See Also:
  • SelenideElement
  • Allure
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
    Method used to assign a name to the element dynamically (e.g., "text", "href").
    protected String
    A description of the element for additional context.
    protected String
    The unique identifier of this element.
    The parent widget or component containing this UIElement, if any.
    protected com.codeborne.selenide.SelenideElement
    The root Selenide element represented by this UIElement.
    protected boolean
     
    protected boolean
     
    protected String
    Name of the UI element.
    protected String
    Type of the UI element (e.g., "button", "link").
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    UIElement(com.codeborne.selenide.SelenideElement selenideElement)
     
    protected
    UIElement(com.codeborne.selenide.SelenideElement selenideElement, String name)
     
    protected
    UIElement(String selenideLocator)
    Initializes a UIElement using a Selenide locator (CSS selector).
    protected
    UIElement(String selenideLocator, String name)
    Initializes a UIElement using a Selenide locator (CSS selector) and assigns a name.
    protected
    UIElement(org.openqa.selenium.By locator)
    Creates a UIElement from a Selenium locator.
    protected
    UIElement(org.openqa.selenium.By locator, String name)
    Creates a UIElement from a Selenium locator and assigns a name.
  • Method Summary

    Modifier and Type
    Method
    Description
    static UIElement
     
    static UIElement
    $uiElement(com.codeborne.selenide.SelenideElement selenideElement)
     
    static UIElement
    $uiElement(com.codeborne.selenide.SelenideElement selenideElement, String name)
     
    static UIElement
    $uiElement(String selenideLocator)
     
    static UIElement
    $uiElement(String selenideLocator, String name)
     
    static UIElement
    $uiElement(org.openqa.selenium.By locator)
    Creates a UIElement from a Selenium locator.
    static UIElement
    $uiElement(org.openqa.selenium.By locator, String name)
    Creates a UIElement from a Selenium locator and assigns a name.
    protected void
     
    void
    applyName(String method)
    Assigns a name to the element using a specified method.
    <T> T
    as(String name)
     
    void
    Asserts that the element is empty.
    void
    = Step: Processed by Aspect =
    void
    Asserts that the element exists in the DOM.
    void
    assertExists(boolean logAsStepOrNot)
    Asserts that the element exists in the DOM, with optional logging to a report.
    void
    Asserts that the element has the specified CSS class.
    void
    assertHasCssClass(String clazz, int duringSeconds)
    Asserts that the element has the specified CSS class within the specified duration.
    void
    Asserts that the element does not have the specified CSS class.
    void
    assertHasNotCssClass(String clazz, boolean logAsStepOrNot)
    Asserts that the element does not have the specified CSS class, with optional logging to a report.
    void
    assertHasNotCssClass(String clazz, int duringSeconds)
    Asserts that the element does not have the specified CSS class within the specified duration.
    void
    Asserts that the element's text contains the specified substring.
    void
    Asserts that the element is not empty.
    void
    Asserts that the element does not exist in the DOM.
    void
    assertNotExist(boolean logAsStepOrNot)
     
    void
    Asserts that the element is not visible.
    void
    assertNotVisible(boolean logAsStepOrNot)
    Asserts that the element is not visible, with optional logging to a report.
    void
    assertNotVisible(String uniqueStepText)
    Asserts that the element is not visible, logging the specified step text.
    void
    Verifies that the element's text matches the specified value.
    void
    Asserts that the element is visible.
    void
    assertVisible(boolean logAsStepOrNot)
    Asserts that the element is visible, with optional logging to a report.
    void
    assertVisible(int durationSeconds)
    Asserts that the element is visible within the specified duration.
    void
    assertVisible(String uniqueStepText)
    Asserts that the element is visible, logging the specified step text.
    void
    Asserts that the element is visible in the viewport.
    void
    Clicks on the element.
    void
    click(boolean logAsStepOrNot)
    Performs a click action on the element with optional logging to Allure reports.
    void
    click(com.codeborne.selenide.ClickOptions clickOptions)
    Clicks on the element.
    void
    click(com.codeborne.selenide.ClickOptions clickOptions, boolean logAsStepOrNot)
    Clicks on the element.
    void
    click(String uniqueStepText)
    Performs a click action on the element and logs the step with a custom message in Allure reports.
    void
    clickAndHold(long milliseconds)
    Clicks on the element and holds the click for the specified duration in milliseconds, then releases the click.
    void
    clickAndHold(long milliseconds, boolean logAsStepOrNot)
    Clicks on the element and holds the click for the specified duration in milliseconds with optional logging to Allure reports
    void
    clickAndHold(long milliseconds, String uniqueStepText)
    the custom message to log in the Allure report for the click and hold action.
    void
    Performs a context click (right-click) action on the element.
    void
    contextClick(boolean logAsStepOrNot)
    Performs a context click (right-click) action on the element with optional logging to Allure reports.
    void
    contextClick(String uniqueStepText)
    Performs a context click (right-click) action on the element and logs the step with a custom message in Allure reports.
    void
    Performs double click on the element.
    void
    doubleClick(boolean logAsStepOrNot)
    Performs a double click action on the element with optional logging to Allure reports
    void
    doubleClick(String uniqueStepText)
    Performs a double click action on the element with optional logging to Allure reports.
    com.codeborne.selenide.SelenideElement
    get()
     
    getAllureCompiledStep(String stepName, org.apache.commons.lang3.tuple.Pair<String,String>... additionalPatterns)
    Compiles a step text for Allure reports.
    getAttribute(String attribute)
     
    int
    Retrieves the height of the element in pixels.
    Retrieves the unique identifier of the element.
    getStepText(String stepName)
     
    Gets the name of the UI element.
    int
    Retrieves the width of the element in pixels.
    void
    Performs a hover action on the element.
    void
    hover(boolean logAsStepOrNot)
    Performs a hover action on the element with optional logging to Allure reports.
    void
    hover(String uniqueStepText)
    Performs a hover action on the element and logs the step with a custom message in Allure reports.
    boolean
    Checks if the element is displayed.
    protected void
    logStep(String stepText)
    Logs a step for reporting purposes.
    void
    Logs a step to the report with a custom step name.
    void
    logStepToReport(String stepName, org.apache.commons.lang3.tuple.Pair<String,String>... additionalPatterns)
     
    void
    Scrolls the element into view.
    void
    scrollTo(boolean logAsStepOrNot)
    Scrolls the element into view with optional logging to Allure reports.
    void
    scrollTo(String uniqueStepText)
    Scrolls the element into view and logs the step with a custom message in Allure reports.
    void
    setRoot(com.codeborne.selenide.SelenideElement selenideElement)
     
    void
    setRoot(org.openqa.selenium.By locator)
     
    Retrieves the text content of the element.
    void
    Performs a soft assertion to check if the element is empty, logging the result.
    void
    Performs a soft assertion to check if the element is not empty, logging the result.
    Wraps the element's name for reporting purposes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface allurium.interfaces.AlluriumElement

    getRoot
  • Field Details

    • root

      protected com.codeborne.selenide.SelenideElement root
      The root Selenide element represented by this UIElement. Initialized via constructor or factory methods.
    • id

      protected String id
      The unique identifier of this element. Fallbacks to the text content if not explicitly set.
    • uiElementType

      protected String uiElementType
      Type of the UI element (e.g., "button", "link"). Useful for logging and reporting.
    • uiElementName

      protected String uiElementName
      Name of the UI element. If not explicitly set, it may be derived dynamically based on attributes.
    • assignNameMethod

      protected String assignNameMethod
      Method used to assign a name to the element dynamically (e.g., "text", "href").
    • description

      protected String description
      A description of the element for additional context.
    • parent

      protected Optional<AbstractWidget> parent
      The parent widget or component containing this UIElement, if any.
    • stepsConsoleLoggingEnabled

      protected boolean stepsConsoleLoggingEnabled
    • stepsReportLoggingEnabled

      protected boolean stepsReportLoggingEnabled
  • Constructor Details

    • UIElement

      protected UIElement(String selenideLocator)
      Initializes a UIElement using a Selenide locator (CSS selector).
      Parameters:
      selenideLocator - the CSS selector to locate the element
    • UIElement

      protected UIElement(String selenideLocator, String name)
      Initializes a UIElement using a Selenide locator (CSS selector) and assigns a name.
      Parameters:
      selenideLocator - the CSS selector to locate the element
      name - the name to assign to the element
    • UIElement

      protected UIElement(org.openqa.selenium.By locator)
      Creates a UIElement from a Selenium locator.
      Parameters:
      locator - the Selenium locator (e.g., By.id, By.xpath)
    • UIElement

      protected UIElement(org.openqa.selenium.By locator, String name)
      Creates a UIElement from a Selenium locator and assigns a name.
      Parameters:
      locator - the Selenium locator
      name - the name to assign to the element
    • UIElement

      public UIElement(com.codeborne.selenide.SelenideElement selenideElement)
    • UIElement

      protected UIElement(com.codeborne.selenide.SelenideElement selenideElement, String name)
  • Method Details

    • $uiElement

      public static UIElement $uiElement(org.openqa.selenium.By locator)
      Creates a UIElement from a Selenium locator.
      Parameters:
      locator - the Selenium locator (e.g., By.id, By.xpath)
      Returns:
      a new UIElement instance
    • $uiElement

      public static UIElement $uiElement(org.openqa.selenium.By locator, String name)
      Creates a UIElement from a Selenium locator and assigns a name.
      Parameters:
      locator - the Selenium locator
      name - the name to assign to the element
      Returns:
      a new UIElement instance
    • $uiElement

      public static UIElement $uiElement(com.codeborne.selenide.SelenideElement selenideElement)
    • $uiElement

      public static UIElement $uiElement(com.codeborne.selenide.SelenideElement selenideElement, String name)
    • $uiElement

      public static UIElement $uiElement(String selenideLocator)
    • $uiElement

      public static UIElement $uiElement(String selenideLocator, String name)
    • _$uiElement

      public static UIElement _$uiElement(String xpath)
    • setRoot

      public void setRoot(org.openqa.selenium.By locator)
    • setRoot

      public void setRoot(com.codeborne.selenide.SelenideElement selenideElement)
    • as

      public <T> T as(String name)
    • getId

      public String getId()
      Retrieves the unique identifier of the element.
      Specified by:
      getId in interface ListComponent
      Returns:
      the ID if explicitly set; otherwise, the text content of the root element
    • getWidth

      public int getWidth()
      Retrieves the width of the element in pixels.
      Returns:
      the width of the element
    • getHeight

      public int getHeight()
      Retrieves the height of the element in pixels.
      Returns:
      the height of the element
    • getAttribute

      public String getAttribute(String attribute)
    • logStep

      protected void logStep(String stepText)
      Logs a step for reporting purposes.
      Parameters:
      stepText - the text to log for the step
    • getStepText

      public String getStepText(String stepName)
    • getAllureCompiledStep

      public String getAllureCompiledStep(String stepName, org.apache.commons.lang3.tuple.Pair<String,String>... additionalPatterns)
      Compiles a step text for Allure reports.
      Parameters:
      stepName - the name of the step
      additionalPatterns - additional placeholder-value pairs for substitution
      Returns:
      the compiled step text
    • logStepToReport

      public void logStepToReport(String stepName)
      Logs a step to the report with a custom step name.
      Parameters:
      stepName - the name of the step
    • logStepToReport

      public void logStepToReport(String stepName, org.apache.commons.lang3.tuple.Pair<String,String>... additionalPatterns)
    • getUiElementName

      public String getUiElementName()
      Description copied from interface: WebElementMeta
      Gets the name of the UI element.
      Specified by:
      getUiElementName in interface WebElementMeta
      Returns:
      the name of the UI element
    • applyName

      protected void applyName()
    • applyName

      public void applyName(String method)
      Assigns a name to the element using a specified method.
      Parameters:
      method - the method to use (e.g., "text", "href", "id")
    • wrappedName

      public String wrappedName()
      Wraps the element's name for reporting purposes.
      Returns:
      the wrapped name
    • get

      public com.codeborne.selenide.SelenideElement get()
      Returns:
      native selenide element, which is used as a core of the UiElement
    • text

      public String text()
      Retrieves the text content of the element.
      Returns:
      the text content
    • isDisplayed

      public boolean isDisplayed()
      Checks if the element is displayed.
      Returns:
      true if the element is visible; false otherwise
    • click

      public void click()
      Clicks on the element. = Processed by Aspect = method is overridable
    • click

      public void click(com.codeborne.selenide.ClickOptions clickOptions)
      Clicks on the element. Supports additional logging options. = Step: Processed by Aspect =
      Parameters:
      clickOptions - click options for customization
    • click

      public void click(boolean logAsStepOrNot)
      Performs a click action on the element with optional logging to Allure reports.
      Parameters:
      logAsStepOrNot - whether to log the click action as a step in Allure reports. If true, the click action is logged.
    • click

      public void click(String uniqueStepText)
      Performs a click action on the element and logs the step with a custom message in Allure reports.
      Parameters:
      uniqueStepText - the custom message to log in the Allure report for this click action.
    • click

      public void click(com.codeborne.selenide.ClickOptions clickOptions, boolean logAsStepOrNot)
      Clicks on the element. Supports additional logging options.
      Parameters:
      clickOptions - click options for customization
      logAsStepOrNot - whether to log the step in the report
    • doubleClick

      public void doubleClick()
      Performs double click on the element. = Step: Processed by Aspect =
    • doubleClick

      public void doubleClick(boolean logAsStepOrNot)
      Performs a double click action on the element with optional logging to Allure reports
      Parameters:
      logAsStepOrNot - whether to log the double click action as a step in Allure reports. If true, the action is logged.
    • doubleClick

      public void doubleClick(String uniqueStepText)
      Performs a double click action on the element with optional logging to Allure reports.
      Parameters:
      uniqueStepText - the custom message to log in the Allure report for the double click action.
    • clickAndHold

      public void clickAndHold(long milliseconds)
      Clicks on the element and holds the click for the specified duration in milliseconds, then releases the click. = Step: Processed by Aspect =
      Parameters:
      milliseconds - click holding period
    • clickAndHold

      public void clickAndHold(long milliseconds, boolean logAsStepOrNot)
      Clicks on the element and holds the click for the specified duration in milliseconds with optional logging to Allure reports
      Parameters:
      milliseconds - click holding period
      logAsStepOrNot - whether to log the click and hold action as a step in Allure reports. If true, the action is logged.
    • clickAndHold

      public void clickAndHold(long milliseconds, String uniqueStepText)
      the custom message to log in the Allure report for the click and hold action.
      Parameters:
      milliseconds - click holding period
      uniqueStepText - the custom message to log in the Allure report for the click and hold action.
    • contextClick

      public void contextClick()
      Performs a context click (right-click) action on the element. = Step: Processed by Aspect =
    • contextClick

      public void contextClick(boolean logAsStepOrNot)
      Performs a context click (right-click) action on the element with optional logging to Allure reports.
      Parameters:
      logAsStepOrNot - whether to log the context click action as a step in Allure reports. If true, the action is logged.
    • contextClick

      public void contextClick(String uniqueStepText)
      Performs a context click (right-click) action on the element and logs the step with a custom message in Allure reports.
      Parameters:
      uniqueStepText - the custom message to log in the Allure report for the context click action.
    • hover

      public void hover()
      Performs a hover action on the element. = Step: Processed by Aspect =
    • hover

      public void hover(boolean logAsStepOrNot)
      Performs a hover action on the element with optional logging to Allure reports.
      Parameters:
      logAsStepOrNot - whether to log the hover action as a step in Allure reports. If true, the action is logged.
    • hover

      public void hover(String uniqueStepText)
      Performs a hover action on the element and logs the step with a custom message in Allure reports.
      Parameters:
      uniqueStepText - the custom message to log in the Allure report for this hover action.
    • scrollTo

      public void scrollTo()
      Scrolls the element into view. = Step: Processed by Aspect =
    • scrollTo

      public void scrollTo(boolean logAsStepOrNot)
      Scrolls the element into view with optional logging to Allure reports.
      Parameters:
      logAsStepOrNot - whether to log the scroll action as a step in Allure reports. If true, the action is logged.
    • scrollTo

      public void scrollTo(String uniqueStepText)
      Scrolls the element into view and logs the step with a custom message in Allure reports.
      Parameters:
      uniqueStepText - the custom message to log in the Allure report for this scroll action.
    • assertText

      public void assertText(String text)
      Verifies that the element's text matches the specified value. = Step: Processed by Aspect =
      Parameters:
      text - the expected text
    • assertHasText

      public void assertHasText(String text)
      Asserts that the element's text contains the specified substring. = Step: Processed by Aspect =
      Parameters:
      text - the substring that the element's text should contain
      Throws:
      AssertionError - if the element's text does not contain the specified substring
    • assertVisibleInViewport

      public void assertVisibleInViewport()
      Asserts that the element is visible in the viewport. = Step: Processed by Aspect =
      Throws:
      AssertionError - if the element is not visible
    • assertVisible

      public void assertVisible()
      Asserts that the element is visible. = Step: Processed by Aspect =
    • assertVisible

      public void assertVisible(String uniqueStepText)
      Asserts that the element is visible, logging the specified step text. = Step: Processed by Aspect =
      Parameters:
      uniqueStepText - the step text to log
    • assertVisible

      public void assertVisible(boolean logAsStepOrNot)
      Asserts that the element is visible, with optional logging to a report. = Step: Processed by Aspect =
      Parameters:
      logAsStepOrNot - whether to log the assertion as a step
    • assertNotVisible

      public void assertNotVisible()
      Asserts that the element is not visible. = Step: Processed by Aspect =
    • assertNotVisible

      public void assertNotVisible(String uniqueStepText)
      Asserts that the element is not visible, logging the specified step text. = Step: Processed by Aspect =
      Parameters:
      uniqueStepText - the step text to log
    • assertNotVisible

      public void assertNotVisible(boolean logAsStepOrNot)
      Asserts that the element is not visible, with optional logging to a report. = Step: Processed by Aspect =
      Parameters:
      logAsStepOrNot - whether to log the assertion as a step
    • assertVisible

      public void assertVisible(int durationSeconds)
      Asserts that the element is visible within the specified duration. = Step: Processed by Aspect =
      Parameters:
      durationSeconds - the duration in seconds
    • assertExists

      public void assertExists()
      Asserts that the element exists in the DOM. = Step: Processed by Aspect =
    • assertExists

      public void assertExists(boolean logAsStepOrNot)
      Asserts that the element exists in the DOM, with optional logging to a report.
      Parameters:
      logAsStepOrNot - whether to log the assertion as a step
    • assertNotExist

      public void assertNotExist()
      Asserts that the element does not exist in the DOM. = Step: Processed by Aspect =
    • assertNotExist

      public void assertNotExist(boolean logAsStepOrNot)
      Parameters:
      logAsStepOrNot - show step in report or not
    • assertEquals

      public void assertEquals(Object obj)
      = Step: Processed by Aspect =
      Parameters:
      obj - to compare
    • assertHasCssClass

      public void assertHasCssClass(String clazz)
      Asserts that the element has the specified CSS class. = Step: Processed by Aspect =
      Parameters:
      clazz - the CSS class to check
    • assertHasNotCssClass

      public void assertHasNotCssClass(String clazz)
      Asserts that the element does not have the specified CSS class. = Step: Processed by Aspect =
      Parameters:
      clazz - the CSS class to check
    • assertHasNotCssClass

      public void assertHasNotCssClass(String clazz, boolean logAsStepOrNot)
      Asserts that the element does not have the specified CSS class, with optional logging to a report.
      Parameters:
      clazz - the CSS class to check
      logAsStepOrNot - whether to log the assertion as a step
    • assertHasCssClass

      public void assertHasCssClass(String clazz, int duringSeconds)
      Asserts that the element has the specified CSS class within the specified duration.
      Parameters:
      clazz - the CSS class to check
      duringSeconds - the duration in seconds
    • assertHasNotCssClass

      public void assertHasNotCssClass(String clazz, int duringSeconds)
      Asserts that the element does not have the specified CSS class within the specified duration.
      Parameters:
      clazz - the CSS class to check
      duringSeconds - the duration in seconds
    • assertEmpty

      public void assertEmpty()
      Asserts that the element is empty. = Step: Processed by Aspect =
    • verifyEmpty

      public void verifyEmpty()
      Performs a soft assertion to check if the element is empty, logging the result.
    • assertIsNotEmpty

      public void assertIsNotEmpty()
      Asserts that the element is not empty. = Step: Processed by Aspect =
    • verifyIsNotEmpty

      public void verifyIsNotEmpty()
      Performs a soft assertion to check if the element is not empty, logging the result.