Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:MarketSquare Robotframework browser Print Version

From Leeroopedia
Knowledge Sources
Domains Testing, Installation
Last Updated 2026-02-12 04:00 GMT

Overview

Concrete tool for displaying version information of all installed components provided by the robotframework-browser library's rfbrowser --version CLI flag.

Description

The print_version function is a Click callback that is invoked when the --version flag is passed to the rfbrowser CLI. It queries three separate version sources and displays a consolidated version report.

The function operates as follows:

  1. Browser Library Version: Reads the Browser/version.py file and extracts the version string using the regex pattern "\d+\.\d+.\d+". The current version is 19.12.5.
  2. Robot Framework Version: Calls the helper function get_rf_version() (defined at lines 29-33) which runs python -m robot --version as a subprocess and parses the version number from the third whitespace-separated token of stdout.
  3. Playwright Version: Calls the helper function get_pw_version() (defined at lines 43-59) which:
    • Runs npm list playwright in the Browser/wrapper/ directory
    • If the command succeeds (exit code 0), parses the version from the @version suffix in the output
    • If the command fails (e.g., Node.js not installed or node_modules missing), falls back to reading the version directly from Browser/wrapper/package.json
    • Returns a Version dataclass with the version string and a from_cmd boolean indicating whether it came from npm (True) or package.json (False)

The output distinguishes between Installed Playwright (confirmed via npm) and Required Playwright (parsed from package.json), which helps diagnose whether the Node.js side has been properly initialized.

The function is registered as an eager Click callback on the --version option of the cli command group, meaning it executes before any subcommand processing.

Usage

This function is invoked via the rfbrowser --version CLI command. It can also be called programmatically to retrieve version information for diagnostics or logging.

Code Reference

Source Location

Signature

def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> None:

Helper Functions

# Browser/entry/get_versions.py, lines 29-33
def get_rf_version() -> str:
    process = subprocess.run(
        [sys.executable, "-m", "robot", "--version"], capture_output=True, check=False
    )
    return process.stdout.decode("utf-8").split(" ")[2]

# Browser/entry/get_versions.py, lines 43-59
def get_pw_version() -> Version:
    process = subprocess.run(
        ["npm", "list", "playwright"],
        capture_output=True,
        check=False,
        shell=True,
        cwd=INSTALLATION_DIR,
    )
    if process.returncode != 0:
        return Version(_get_version_from_package_json(), False)
    std_out = process.stdout.decode("utf-8")
    if match := re.search(r"((?:@[^@]*))$", std_out):
        version_string = match.group(0)
        version_string = version_string.replace("@", "")
        return Version(version_string.replace("\r", "").replace("\n", ""), True)
    return Version(_get_version_from_package_json(), False)

Import

from Browser.entry.get_versions import print_version

I/O Contract

Inputs

Name Type Required Description
ctx click.Context Yes The Click context object; used to check ctx.resilient_parsing for tab-completion scenarios
param click.Parameter Yes The Click parameter descriptor for the --version option
value bool Yes Whether the --version flag was provided; if False or during resilient parsing, the function returns immediately without output

Outputs

Name Type Description
return None The function produces no return value; version information is printed to stdout and the rfbrowser log file
stdout/log output text Three lines of version information: Browser library version, Robot Framework version, and Playwright version (either "Installed" or "Required")

Usage Examples

Basic Example

$ rfbrowser --version

======================================================================
Installed Browser library version is: "19.12.5"
Installed Robot Framework version: "7.2"
Installed Playwright is: "1.52.0"
======================================================================

When Node.js Dependencies Are Not Initialized

$ rfbrowser --version

======================================================================
Installed Browser library version is: "19.12.5"
Installed Robot Framework version: "7.2"
Required Playwright is: "1.52.0"
======================================================================

Note the output says Required instead of Installed when npm cannot confirm the Playwright version, indicating that rfbrowser init has not been run yet.

Programmatic Usage

from Browser.entry.get_versions import get_rf_version, get_pw_version

# Get individual version components
rf_ver = get_rf_version()
pw_ver = get_pw_version()

print(f"Robot Framework: {rf_ver}")
print(f"Playwright: {pw_ver.version} (installed: {pw_ver.from_cmd})")

Related Pages

Implements Principle

Page Connections

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