Class BrowserActions

java.lang.Object
allurium.browser.BrowserActions

public class BrowserActions extends Object
A utility class for performing various browser-related actions and interactions.

The `BrowserActions` class provides a collection of static methods to manage browser logs, manipulate DOM elements, handle cookies and local storage, and switch between iframes or tabs. It utilizes Selenide and WebDriver to perform operations, enhancing testing and debugging capabilities.

Purpose:

  • Provide a centralized utility for browser-related actions.
  • Enhance test debugging through detailed log analysis.
  • Simplify common browser interactions with reusable methods.
  • Constructor Details

    • BrowserActions

      public BrowserActions()
  • Method Details

    • getConsoleLogEntries

      public static org.openqa.selenium.logging.LogEntries getConsoleLogEntries()
      Retrieves the browser console log entries.
      Returns:
      LogEntries object containing all console log entries from the browser.
    • getConsoleLogs

      public static String getConsoleLogs()
      Retrieves the browser console logs as a formatted string.
      Returns:
      A string of concatenated console log entries.
    • getConsoleLogs

      public static String getConsoleLogs(List<String> exclusions)
      Retrieves browser console logs, excluding specified log entries.
      Parameters:
      exclusions - A list of strings representing log entry substrings to exclude.
      Returns:
      A string of filtered console log entries.
    • removeElement

      public static void removeElement(UIElement element)
      Removes an element from the DOM using its UIElement wrapper.
      Parameters:
      element - The UIElement to be removed.
    • removeElement

      public static void removeElement(org.openqa.selenium.By element)
      Removes an element from the DOM using its Selenium By locator.
      Parameters:
      element - The By locator of the element to be removed.
    • getCookie

      public static org.openqa.selenium.Cookie getCookie(String nameCookie)
      Retrieves a cookie by its name.
      Parameters:
      nameCookie - The name of the cookie to retrieve.
      Returns:
      The Cookie object if found, null otherwise.
    • getValueFromLocalStorage

      public static String getValueFromLocalStorage(String key)
      Retrieves a value from the browser's local storage.
      Parameters:
      key - The key for the value in local storage.
      Returns:
      The value as a string, or null if not found or on failure.
    • errorInBrowserConsole

      public static StringBuilder errorInBrowserConsole()
      Retrieves error logs from the browser console, excluding certain log types.
      Returns:
      A StringBuilder containing filtered console error logs.
    • switchFrame

      public void switchFrame(String id)
      Switches to a specific iframe by its ID.
      Parameters:
      id - The ID of the iframe to switch to.
    • switchTo

      public void switchTo(int id)
      Switches to a specific iframe by its index.
      Parameters:
      id - The index of the iframe to switch to.