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 New Browser New Context New Page

From Leeroopedia
Property Value
Implementation Name New Browser, New Context, New Page
Type API Doc
Domains Browser_Automation, Test_Isolation
Workflow Browser_Test_Authoring
Repository MarketSquare/robotframework-browser

Overview

Concrete tools for creating and managing the Browser, Context, and Page hierarchy provided by robotframework-browser.

Description

These three keywords form the core resource creation API of the Browser library:

  • New Browser: Launches a new browser process (chromium, firefox, or webkit). Returns a stable browser identifier. Supports headless/headed mode, proxy configuration, slow motion, and browser-specific options. Uses reuse_existing=True by default to avoid launching duplicate browser instances with identical configuration.
  • New Context: Creates a new isolated browser context within the active browser. Returns a stable context identifier. Contexts control cookies, storage, viewport, geolocation, HTTP credentials, and many other session-scoped settings. If no browser is open, one is automatically created with defaults.
  • New Page: Opens a new page (tab) within the active context, optionally navigating to a URL. Returns a NewPageDetails dictionary with page_id and video_path keys. If no browser or context is open, both are automatically created with defaults.

Usage

Use these keywords at the beginning of test cases or suite setup to establish the browser environment. For simple tests, calling only New Page with a URL is sufficient since it auto-creates the browser and context. For tests requiring specific browser configuration, viewport settings, or authentication, call all three keywords explicitly.

Code Reference

Source Location

  • Repository: robotframework-browser
  • File: Browser/keywords/playwright_state.py
    • new_browser: Lines 418-487
    • new_context: Lines 576-692
    • new_page: Lines 959-1009

Signature

# New Browser
def new_browser(
    self,
    browser: SupportedBrowsers = SupportedBrowsers.chromium,
    headless: bool = True,
    *,
    args: list[str] | None = None,
    channel: str | None = None,
    chromiumSandbox: bool = False,
    devtools: bool = False,
    downloadsPath: str | None = None,
    env: dict | None = None,
    executablePath: str | None = None,
    firefoxUserPrefs: dict[str, str | int | float | bool] | None = None,
    handleSIGHUP: bool = True,
    handleSIGINT: bool = True,
    handleSIGTERM: bool = True,
    ignoreDefaultArgs: list[str] | bool | None = None,
    proxy: Proxy | None = None,
    reuse_existing: bool = True,
    slowMo: timedelta = timedelta(seconds=0),
    timeout: timedelta = timedelta(seconds=30),
) -> str

# New Context
def new_context(
    self,
    *,
    acceptDownloads: bool = True,
    baseURL: str | None = None,
    bypassCSP: bool = False,
    clientCertificates: list[ClientCertificate] | None = None,
    colorScheme: ColorScheme | None = None,
    defaultBrowserType: SupportedBrowsers | None = None,
    deviceScaleFactor: float | None = None,
    extraHTTPHeaders: dict[str, str] | None = None,
    forcedColors: ForcedColors = ForcedColors.none,
    geolocation: GeoLocation | None = None,
    hasTouch: bool | None = None,
    httpCredentials: HttpCredentials | None = None,
    ignoreHTTPSErrors: bool = False,
    isMobile: bool | None = None,
    javaScriptEnabled: bool = True,
    locale: str | None = None,
    offline: bool = False,
    permissions: list[Permission] | None = None,
    proxy: Proxy | None = None,
    recordHar: RecordHar | None = None,
    recordVideo: RecordVideo | None = None,
    reducedMotion: ReduceMotion = ReduceMotion.no_preference,
    screen: dict[str, int] | None = None,
    serviceWorkers: ServiceWorkersPermissions | None = ServiceWorkersPermissions.allow,
    storageState: str | None = None,
    timezoneId: str | None = None,
    tracing: bool | Path | None = None,
    userAgent: str | None = None,
    viewport: ViewportDimensions | None = ViewportDimensions(width=1280, height=720),
) -> str

# New Page
def new_page(
    self,
    url: str | None = None,
    wait_until: PageLoadStates = PageLoadStates.load,
) -> NewPageDetails

Import

# These are Robot Framework keywords exposed by the Browser library.
# No direct Python import is needed for typical usage.

# Robot Framework usage (in *** Settings ***):
# Library    Browser

I/O Contract

New Browser

Parameter Type Default Description
browser SupportedBrowsers chromium Browser engine: chromium, firefox, or webkit.
headless bool True Set to False to display the browser GUI.
args list[str] or None None Additional command-line arguments for the browser process.
channel str or None None Use stock Chrome or Edge instead of bundled Chromium.
chromiumSandbox bool False Enable Chromium sandboxing.
devtools bool False Auto-open Developer Tools panel for each tab (Chromium only).
proxy Proxy or None None Network proxy settings: {server, bypass, username, password}.
reuse_existing bool True Reuse an existing browser with matching configuration.
slowMo timedelta 0s Delay between Playwright operations.
timeout timedelta 30s Maximum time to wait for browser to start.
Returns Description
str Stable identifier for the created (or reused) browser instance.

New Context

Parameter Type Default Description
acceptDownloads bool True Automatically download all attachments.
baseURL str or None None Base URL for relative navigation.
bypassCSP bool False Bypass Content-Security-Policy.
colorScheme ColorScheme or None None Emulate prefers-color-scheme: light, dark, no-preference.
extraHTTPHeaders dict or None None Additional HTTP headers sent with every request.
httpCredentials HttpCredentials or None None Credentials for HTTP authentication.
ignoreHTTPSErrors bool False Ignore HTTPS certificate errors.
viewport ViewportDimensions or None 1280x720 Emulated viewport size. None disables default viewport.
tracing bool or Path or None None Enable Playwright tracing to capture detailed execution logs.
storageState str or None None Restore storage state from a file saved by Save Storage State.
Returns Description
str Stable identifier for the created context.

New Page

Parameter Type Default Description
url str or None None URL to navigate to. Should include protocol (e.g., https://).
wait_until PageLoadStates load When navigation is considered complete: domcontentloaded, load, networkidle, or commit.
Returns Description
NewPageDetails Dictionary with page_id (str) and video_path (str, empty if no video).

Usage Examples

*** Settings ***
Library    Browser

*** Test Cases ***
Simple Page Open (Auto-Creates Browser And Context)
    New Page    https://example.com
    Get Title    ==    Example Domain

Explicit Full Hierarchy
    New Browser    chromium    headless=True
    New Context    viewport={'width': 1920, 'height': 1080}
    New Page       https://example.com

Multiple Isolated Contexts For Multi-User Testing
    New Browser    chromium    headless=True
    # User A logs in
    New Context    httpCredentials={'username': 'userA', 'password': 'passA'}
    New Page       https://myapp.com/dashboard
    # User B logs in with separate session
    New Context    httpCredentials={'username': 'userB', 'password': 'passB'}
    New Page       https://myapp.com/dashboard

Cross-Browser Testing
    New Browser    chromium    headless=True
    New Page       https://example.com
    Get Title      ==    Example Domain
    Close Browser
    New Browser    firefox    headless=True
    New Page       https://example.com
    Get Title      ==    Example Domain

Mobile Device Emulation
    ${device}=    Get Device    iPhone X
    New Context    &{device}
    New Page       https://example.com

Context With Tracing And Video Recording
    New Browser    chromium
    New Context
    ...    tracing=True
    ...    recordVideo={'dir': '${OUTPUT_DIR}/videos'}
    ...    viewport={'width': 1280, 'height': 720}
    New Page    https://example.com

Related Pages

Implements Principle

Page Connections

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