Class AsyncElementActions

java.lang.Object
com.shaft.driver.internal.FluentWebDriverAction
com.shaft.gui.element.AsyncElementActions

@Beta public class AsyncElementActions extends FluentWebDriverAction
Provides asynchronous (non-blocking) variants of common ElementActions operations.

Each action method schedules the underlying ElementActions call on a new virtual thread and returns this immediately, allowing the caller to queue multiple actions in parallel before waiting for them all to finish via synchronize(), join(), or sync().

Thread safety: each AsyncElementActions instance maintains its own internal list of virtual threads, so instances must not be shared across test threads.

Example usage:

driver.async().element()
    .type(firstNameField, "John")
    .type(lastNameField,  "Doe")
    .click(submitButton)
    .synchronize();
See Also:
  • Constructor Details

    • AsyncElementActions

      public AsyncElementActions(DriverFactoryHelper helper)
      Constructs a new AsyncElementActions bound to the given driver helper.

      Example:

      AsyncElementActions asyncActions = new AsyncElementActions(driverFactoryHelper);
      
      Parameters:
      helper - the DriverFactoryHelper that provides access to the underlying WebDriver session
  • Method Details

    • type

      public AsyncElementActions type(org.openqa.selenium.By elementLocator, String text)
      Asynchronously types the given text into the element identified by elementLocator.

      The action is executed on a new virtual thread; the current thread is not blocked.

      Example:

      asyncActions.type(By.id("username"), "testUser");
      
      Parameters:
      elementLocator - the By locator used to find the target element
      text - the text to type into the element
      Returns:
      this AsyncElementActions instance for fluent chaining
    • click

      public AsyncElementActions click(org.openqa.selenium.By elementLocator)
      Asynchronously clicks the element identified by elementLocator.

      Example:

      asyncActions.click(By.id("submitButton"));
      
      Parameters:
      elementLocator - the By locator used to find the target element
      Returns:
      this AsyncElementActions instance for fluent chaining
    • select

      public AsyncElementActions select(org.openqa.selenium.By elementLocator, String text)
      Asynchronously selects the option matching text in the drop-down element identified by elementLocator.

      Example:

      asyncActions.select(By.id("countryDropdown"), "Egypt");
      
      Parameters:
      elementLocator - the By locator used to find the <select> element
      text - the visible text of the option to select
      Returns:
      this AsyncElementActions instance for fluent chaining
    • clear

      public AsyncElementActions clear(org.openqa.selenium.By elementLocator)
      Asynchronously clears the content of the element identified by elementLocator.

      Example:

      asyncActions.clear(By.id("searchInput"));
      
      Parameters:
      elementLocator - the By locator used to find the target element
      Returns:
      this AsyncElementActions instance for fluent chaining
    • doubleClick

      public AsyncElementActions doubleClick(org.openqa.selenium.By elementLocator)
      Asynchronously double-clicks the element identified by elementLocator.

      Example:

      asyncActions.doubleClick(By.id("editableCell"));
      
      Parameters:
      elementLocator - the By locator used to find the target element
      Returns:
      this AsyncElementActions instance for fluent chaining
    • clickUsingJavascript

      public AsyncElementActions clickUsingJavascript(org.openqa.selenium.By elementLocator)
      Asynchronously clicks the element identified by elementLocator using JavaScript.

      Useful when native WebDriver click is intercepted by overlapping elements.

      Example:

      asyncActions.clickUsingJavascript(By.id("hiddenButton"));
      
      Parameters:
      elementLocator - the By locator used to find the target element
      Returns:
      this AsyncElementActions instance for fluent chaining
    • clipboardActions

      public AsyncElementActions clipboardActions(org.openqa.selenium.By elementLocator, ClipboardAction action)
      Asynchronously performs the specified clipboard action (e.g., copy, paste, cut) on the element identified by elementLocator.

      Example:

      asyncActions.clipboardActions(By.id("textArea"), ClipboardAction.COPY);
      
      Parameters:
      elementLocator - the By locator used to find the target element
      action - the ClipboardAction to perform (e.g., COPY, PASTE, CUT)
      Returns:
      this AsyncElementActions instance for fluent chaining
    • captureScreenshot

      public AsyncElementActions captureScreenshot(org.openqa.selenium.By elementLocator)
      Asynchronously captures a screenshot of the element identified by elementLocator and attaches it to the Allure report.

      Example:

      asyncActions.captureScreenshot(By.id("chart"));
      
      Parameters:
      elementLocator - the By locator used to find the target element
      Returns:
      this AsyncElementActions instance for fluent chaining
    • hover

      public AsyncElementActions hover(org.openqa.selenium.By elementLocator)
      Asynchronously moves the mouse cursor over the element identified by elementLocator, triggering any hover-based UI state (e.g., tooltips, drop-down menus).

      Example:

      asyncActions.hover(By.id("menuItem"));
      
      Parameters:
      elementLocator - the By locator used to find the target element
      Returns:
      this AsyncElementActions instance for fluent chaining
    • typeAppend

      public AsyncElementActions typeAppend(org.openqa.selenium.By elementLocator, String text)
      Asynchronously appends the given text to the current value of the element identified by elementLocator without clearing its existing content first.

      Example:

      asyncActions.typeAppend(By.id("notes"), " additional text");
      
      Parameters:
      elementLocator - the By locator used to find the target element
      text - the text to append to the element's current value
      Returns:
      this AsyncElementActions instance for fluent chaining
    • clickAndHold

      public AsyncElementActions clickAndHold(org.openqa.selenium.By elementLocator)
      Asynchronously clicks and holds the mouse button down on the element identified by elementLocator without releasing it, which is useful for drag operations or long-press interactions.

      Example:

      asyncActions.clickAndHold(By.id("draggableHandle"));
      
      Parameters:
      elementLocator - the By locator used to find the target element
      Returns:
      this AsyncElementActions instance for fluent chaining
    • setValueUsingJavaScript

      public AsyncElementActions setValueUsingJavaScript(org.openqa.selenium.By elementLocator, String value)
      Asynchronously sets the value attribute of the element identified by elementLocator directly via JavaScript, bypassing normal input events.

      This is useful for read-only or JavaScript-rendered input fields that cannot be interacted with through the standard WebDriver API.

      Example:

      asyncActions.setValueUsingJavaScript(By.id("hiddenInput"), "injectedValue");
      
      Parameters:
      elementLocator - the By locator used to find the target element
      value - the value to assign to the element's value attribute
      Returns:
      this AsyncElementActions instance for fluent chaining
    • typeSecure

      public AsyncElementActions typeSecure(org.openqa.selenium.By elementLocator, String text)
      Asynchronously types the given text into the element identified by elementLocator in a secure manner, masking the typed characters in logs and reports to protect sensitive data such as passwords.

      Example:

      asyncActions.typeSecure(By.id("passwordField"), "s3cr3tP@ssword");
      
      Parameters:
      elementLocator - the By locator used to find the target element
      text - the sensitive text to type (will be masked in reports)
      Returns:
      this AsyncElementActions instance for fluent chaining
    • submitFormUsingJavaScript

      public AsyncElementActions submitFormUsingJavaScript(org.openqa.selenium.By elementLocator)
      Asynchronously submits the form that contains the element identified by elementLocator using JavaScript, bypassing standard form-submission validation.

      Example:

      asyncActions.submitFormUsingJavaScript(By.id("loginForm"));
      
      Parameters:
      elementLocator - the By locator used to find an element within the target form
      Returns:
      this AsyncElementActions instance for fluent chaining
    • typeFileLocationForUpload

      public AsyncElementActions typeFileLocationForUpload(org.openqa.selenium.By elementLocator, String filePath)
      Asynchronously types the absolute path of a local file into the file-upload input element identified by elementLocator, triggering the browser's file selection mechanism.

      Example:

      asyncActions.typeFileLocationForUpload(By.id("fileInput"), "/home/user/documents/report.pdf");
      
      Parameters:
      elementLocator - the By locator used to find the file-input element
      filePath - the absolute path to the file to upload
      Returns:
      this AsyncElementActions instance for fluent chaining
    • dragAndDrop

      public AsyncElementActions dragAndDrop(org.openqa.selenium.By sourceElementLocator, org.openqa.selenium.By destinationElementLocator)
      Asynchronously drags the element identified by sourceElementLocator and drops it onto the element identified by destinationElementLocator.

      Example:

      asyncActions.dragAndDrop(By.id("draggableCard"), By.id("dropZone"));
      
      Parameters:
      sourceElementLocator - the By locator used to find the element to drag
      destinationElementLocator - the By locator used to find the drop target
      Returns:
      this AsyncElementActions instance for fluent chaining
    • join

      public AsyncElementActions join()
      Alias for synchronize(). Blocks the calling thread until all queued asynchronous actions have completed.

      Example:

      asyncActions.type(firstField, "value1")
                  .click(submitButton)
                  .join();
      
      Returns:
      this AsyncElementActions instance for fluent chaining
      See Also:
    • synchronize

      public AsyncElementActions synchronize()
      Blocks the calling thread until all previously queued asynchronous actions have finished executing on their respective virtual threads.

      Any InterruptedException thrown while waiting for a thread to join is caught and logged via SHAFT's internal reporting utilities.

      Example:

      asyncActions.type(firstField, "value1")
                  .type(secondField, "value2")
                  .synchronize();
      
      Returns:
      this AsyncElementActions instance for fluent chaining
      See Also:
    • sync

      public AsyncElementActions sync()
      Alias for synchronize(). Blocks the calling thread until all queued asynchronous actions have completed.

      Example:

      asyncActions.type(firstField, "value1")
                  .click(submitButton)
                  .sync();
      
      Returns:
      this AsyncElementActions instance for fluent chaining
      See Also: