Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:MarketSquare Robotframework browser LibraryComponent Init

From Leeroopedia

LibraryComponent.__init__

Type

API Doc

Source

Browser/base/librarycomponent.py, lines 43-51

Import

from Browser.base import LibraryComponent

Or equivalently:

from Browser.base.librarycomponent import LibraryComponent

Constructor Signature

class LibraryComponent:
    def __init__(self, library: "Browser") -> None:
        """Base class exposing attributes from the common context.

        :param library: The library itself as a context object.
        """
        self.library = library
        self._crypto: Any | None = None
        self.browser_arg_mapping: dict[int, str] = {}

Parameters

Parameter Type Description
library Browser The fully initialized Browser library instance. This is the central context object from which all properties and methods are delegated.

Provided Properties

After construction, the following properties and methods are available on the LibraryComponent instance. All of these delegate to the underlying self.library object:

Core Access

Property/Method Type Description
self.library Browser Direct reference to the Browser library instance. Allows calling any library method or accessing any library attribute.
self.playwright Playwright The Playwright gRPC wrapper. Use self.playwright.grpc_channel() to open a channel to the Node.js process.

Configuration Properties (Scope-Aware)

These properties read from scope-aware SettingsStack objects, meaning they respect the current test/suite/global scope:

Property Type Description
self.timeout float Current timeout in milliseconds.
self.strict_mode bool Whether strict mode is enabled (selectors must match exactly one element).
self.selector_prefix str Prefix automatically prepended to selectors.
self.retry_assertions_for float Duration in milliseconds for retrying assertions.
self.run_on_failure_keyword DelayedKeyword The keyword to run when a keyword fails.
self.show_keyword_call_banner bool Whether to display keyword call banners in the browser.
self.highlight_on_failure bool Whether to highlight elements on failure.

Output Paths

Property Type Description
self.outputdir str Robot Framework output directory path.
self.browser_output Path Directory for browser-specific output files.
self.screenshots_output Path Directory for screenshot files.
self.video_output Path Directory for video recordings.
self.traces_output Path Directory for trace files.
self.coverage_ouput Path Directory for coverage output (note: property name retains the typo from source).

Cache and State

Property Type Description
self.context_cache ContextCache Cache of browser contexts, pages, and browser instances. Used to look up the current active page or context.
self.unresolved_promises set[Future] Set of unresolved promise futures from async keyword operations.

Utility Methods

Method Signature Description
resolve_selector None) -> str Resolves a selector by prepending self.selector_prefix if applicable. Handles the !prefix escape and element= prefix bypass.
get_timeout None) -> float Returns the timeout in milliseconds. If timeout is None, returns the current default timeout from the settings stack.
convert_timeout float, to_ms: bool = True) -> float Converts a timeout value to milliseconds (or seconds if to_ms=False).
millisecs_to_timestr (timeout: float) -> str Converts milliseconds to a human-readable time string.
resolve_secret (secret_variable: Any, arg_name: str) -> str Resolves a secret variable, supporting CryptoLibrary integration and environment variable expansion.
initialize_js_extension str) -> Response.Keywords Loads a JavaScript extension file into the Node.js process. Returns keyword metadata.
call_js_keyword (keyword_name: str, **args) -> Any Calls a previously loaded JavaScript keyword by name, passing keyword arguments.

Usage Example: Minimal Plugin

<syntaxhighlight lang="python"> from Browser import Browser from Browser.base import LibraryComponent from robot.api.deco import keyword


class MyPlugin(LibraryComponent):

   def __init__(self, library: Browser) -> None:
       super().__init__(library)
   @keyword
   def my_custom_keyword(self, selector: str) -> str:
       """A plugin keyword that uses the library's selector resolution."""
       resolved = self.resolve_selector(selector)
       timeout = self.get_timeout(None)
       # Use the gRPC channel for direct Playwright calls
       with self.playwright.grpc_channel() as stub:
           response = stub.GetText(
               Request().ElementSelector(selector=resolved, timeout=timeout)
           )
       return response.body

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment