Implementation:MarketSquare Robotframework browser Browser Init
| Property | Value |
|---|---|
| Implementation Name | Browser Init |
| Type | API Doc |
| Domains | Test_Automation, Configuration |
| Workflow | Browser_Test_Authoring |
| Repository | MarketSquare/robotframework-browser |
Overview
Concrete tool for configuring the Browser library at import time provided by robotframework-browser.
Description
The Browser.__init__ method is the constructor of the Browser library class. When Robot Framework processes a Library Browser statement in a suite's Settings section, it instantiates the Browser class and passes any keyword arguments to this constructor. The constructor accepts keyword-only arguments (no positional arguments are allowed) that establish global defaults for the entire test execution session.
Key responsibilities of the constructor:
- Initializes internal component libraries (PlaywrightState, Control, Interaction, Getters, Promises, Waiter, etc.)
- Creates a SettingsStack for each configurable parameter (timeout, retry_assertions_for, strict_mode, run_on_failure, selector_prefix, etc.)
- Configures Playwright debug logging behavior
- Loads optional JavaScript extensions and Python plugins
- Sets up the presenter mode for visual debugging
- Registers the library as its own Robot Framework listener for lifecycle events
Usage
Use this API when importing the Browser library in a Robot Framework suite file. All parameters are optional and have sensible defaults. Configuration is typically done once per project in a resource file or suite initialization file.
Code Reference
Source Location
- Repository: robotframework-browser
- File:
Browser/browser.py(Lines 796-939)
Signature
def __init__(
self,
*_,
auto_closing_level: AutoClosingLevel = AutoClosingLevel.TEST,
auto_delete_passed_tracing: bool = False,
enable_playwright_debug: PlaywrightLogTypes | bool = PlaywrightLogTypes.library,
enable_presenter_mode: HighLightElement | bool = False,
external_browser_executable: dict[SupportedBrowsers, str] | None = None,
highlight_on_failure: bool = False,
jsextension: list[str] | str | None = None,
language: str | None = None,
playwright_process_host: str | None = None,
playwright_process_port: int | None = None,
plugins: list[str] | str | None = None,
retry_assertions_for: timedelta = timedelta(seconds=1),
run_on_failure: str = "Take Screenshot fail-screenshot-{index}",
selector_prefix: str | None = None,
show_keyword_call_banner: bool | None = None,
strict: bool = True,
timeout: timedelta = timedelta(seconds=10),
tracing_group_mode: TracingGroupMode = TracingGroupMode.Full,
) -> None
Import
# Python import
from Browser import Browser
# Robot Framework import (in *** Settings ***)
# Library Browser
I/O Contract
| Parameter | Type | Default | Description |
|---|---|---|---|
auto_closing_level |
AutoClosingLevel | TEST | Configure automatic closing of contexts and pages. Options: TEST, SUITE, MANUAL. |
auto_delete_passed_tracing |
bool | False | If True, traces of passed tests are not saved when auto_closing_level is SUITE or TEST. |
enable_playwright_debug |
PlaywrightLogTypes or bool | PlaywrightLogTypes.library | Enable low-level Playwright debug logging. True enables playwright-level logs; False uses library-level only. |
enable_presenter_mode |
HighLightElement or bool | False | Highlights interacted elements with configurable duration, width, style, and color. |
external_browser_executable |
dict or None | None | Maps browser type to custom executable path (currently only chromium supported). |
highlight_on_failure |
bool | False | If True, highlights the failing element in failure screenshots. |
jsextension |
list[str] or str or None | None | Path(s) to CommonJS modules exposed as extra keywords. |
language |
str or None | None | Language code for translating keyword names and documentation. |
plugins |
list[str] or str or None | None | External Python classes that extend the Browser library. |
retry_assertions_for |
timedelta | 1 second | How long assertion keywords retry polling after the first failure. |
run_on_failure |
str | "Take Screenshot fail-screenshot-{index}" | Keyword to execute automatically when any Browser keyword fails. |
selector_prefix |
str or None | None | Prefix prepended to all selectors (useful for iframe-prefixed selectors). |
show_keyword_call_banner |
bool or None | None | Show a banner with keyword name at page bottom. None means only with presenter mode. |
strict |
bool | True | If True, selectors matching multiple elements cause keyword failure. |
timeout |
timedelta | 10 seconds | Default timeout for element-based keyword operations. |
tracing_group_mode |
TracingGroupMode | Full | How Robot Framework keyword calls are logged in Playwright trace. Options: Full, Stack. |
| Returns | Description |
|---|---|
| None | The constructor does not return a value. The library instance is registered with Robot Framework. |
Usage Examples
*** Settings ***
Library Browser timeout=30s retry_assertions_for=5s strict=True
*** Test Cases ***
Example With Default Config
New Page https://example.com
Get Title == Example Domain
*** Settings ***
# Full configuration example
Library Browser
... timeout=15s
... retry_assertions_for=3s
... strict=True
... auto_closing_level=TEST
... run_on_failure=Take Screenshot failure-{index} fullPage=True
... enable_presenter_mode=False
... highlight_on_failure=True
*** Settings ***
# Headless CI configuration with minimal timeout
Library Browser timeout=5s run_on_failure=NONE
*** Settings ***
# Using plugins and JavaScript extensions
Library Browser
... plugins=my_plugin.MyPlugin
... jsextension=my_custom_keywords.js
Related Pages
Implements Principle
Requires Environment
- Environment:MarketSquare_Robotframework_browser_Python_Runtime
- Environment:MarketSquare_Robotframework_browser_Node_Runtime