Class AbstractBrowser
- All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable
This class centralizes all pure Selenium WebDriver interactions (DOM querying, execution, navigation, and screenshots). Concrete implementations (like Chrome or Firefox) must handle the browser-specific launch protocols, DevTools connections, and process management.
- Author:
- anahata
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<String, BrowserDrone> The centralized registry mapping drone IDs to their stateful objects.Fields inherited from class AnahataToolkit
childrenProviders, propertyChangeSupportFields inherited from class ToolContext
toolkit -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProtected constructor for subclass instantiation. -
Method Summary
Modifier and TypeMethodDescriptionclickElement(String droneId, String identifier) Performs a stateful click by first attempting to locate the element using a multi-strategy search (ID, Name, Link Text, XPath text content).Closes the browser session and removes it from the registry.executeScript(String droneId, String script) Executes arbitrary JavaScript in the current browser session.Fills a web form with the provided data.abstract org.openqa.selenium.WebDriverResolves the active WebDriver for the requested drone.getPageSource(String droneId) Gets the full HTML source of the current page.getPageText(String droneId) Gets the visible text content of the current page.getScreenshot(String droneId, String name) Takes a screenshot of the current page and attaches it to the session.Gets the current status of the browser driver for a specific drone.Navigates back in the browser history.Navigates forward in the browser history.inspectForm(String droneId) Inspects the current page for input fields and buttons.abstract StringkillAll()Closes all active browser processes.Lists all open tabs/windows in the specified drone.protected org.openqa.selenium.WebElementlocateElementGracefully(org.openqa.selenium.WebDriver driver, String identifier) Helper method to safely locate elements using a cascading fallback strategy.Navigates the specified drone to a new URL.openNewTab(String droneId, String url) Refreshes the current page.scrollToElement(String droneId, String identifier) Scrolls the specified element into view.switchToTab(String droneId, int index) Switches the active tab/window by its index.waitForElement(String droneId, String cssSelector, int timeoutSeconds) Safely executes a CSS-based visibility check usingWebDriverWait.Methods inherited from class AnahataToolkit
getChildrenProviders, getDescription, getId, getName, getParentProvider, getPropertyChangeSupport, initialize, isEffectivelyProviding, postActivate, rebindMethods inherited from class ToolContext
addAttachment, addAttachment, addAttachment, error, error, getAgi, getApplicationMap, getAsiContainer, getAsiContainerMap, getCall, getExecutorService, getModelId, getModelMessage, getResourceManager, getResponse, getSessionMap, getThreadSafeLogger, getTool, getToolContext, getToolkit, getToolManager, getTurnMap, isToolExecution, log, peekResponse, runAsyncMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContextProvider
getAgi, getContextPosition, getFlattenedHierarchy, getFullyQualifiedId, getHeader, getIconId, getInstructionsTokenCount, getRagTokenCount, getSystemInstructions, isProviding, populateMessage, setParentProvider, setProvidingMethods inherited from interface Rebindable
rebind
-
Field Details
-
drones
The centralized registry mapping drone IDs to their stateful objects.
-
-
Constructor Details
-
AbstractBrowser
protected AbstractBrowser()Protected constructor for subclass instantiation.
-
-
Method Details
-
getDriver
Resolves the active WebDriver for the requested drone.Implementation details: This is an internal lifecycle method. If the connection is lost, concrete implementations should attempt to re-establish it using the cached port and profile data.
- Parameters:
droneId- The unique ID of the drone.- Returns:
- The active WebDriver, or
nullif it cannot be resolved.
-
getStatus
-
killAll
Closes all active browser processes.- Returns:
- A status message describing the cleanup operations.
-
listTabs
Lists all open tabs/windows in the specified drone.Implementations should ideally use native DevTools protocols to avoid forcing window focus and causing screen flickering.
- Parameters:
droneId- The ID of the drone.- Returns:
- A list of formatted tab titles and URLs.
-
getScreenshot
-
switchToTab
-
openNewTab
-
goBack
-
goForward
-
refresh
-
getPageSource
-
getPageText
-
inspectForm
-
clickElement
Performs a stateful click by first attempting to locate the element using a multi-strategy search (ID, Name, Link Text, XPath text content).- Parameters:
droneId- The ID of the drone.identifier- The ID, Name, or visible text of the element.- Returns:
- A status message indicating success or failure.
-
scrollToElement
-
waitForElement
Safely executes a CSS-based visibility check usingWebDriverWait.- Parameters:
droneId- The ID of the drone.cssSelector- The CSS selector of the element.timeoutSeconds- The maximum time to wait in seconds.- Returns:
- A status message confirming visibility.
-
executeScript
-
fillForm
-
close
-
locateElementGracefully
protected org.openqa.selenium.WebElement locateElementGracefully(org.openqa.selenium.WebDriver driver, String identifier) Helper method to safely locate elements using a cascading fallback strategy.Execution order: ID -> Name -> Link Text -> XPath (text contains). This avoids throwing raw
NoSuchElementExceptions and allows the caller to handle missing elements gracefully.- Parameters:
driver- The active WebDriver instance.identifier- The ID, Name, or visible text to search for.- Returns:
- The located
WebElement, ornullif not found.
-

