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.

Workflow:MarketSquare Robotframework browser Plugin Development

From Leeroopedia
Knowledge Sources
Domains Browser_Automation, Plugin_Development, Extensibility
Last Updated 2026-02-12 04:00 GMT

Overview

End-to-end process for creating, importing, and using a custom Python plugin to extend the robotframework-browser library with new keywords and capabilities.

Description

This workflow covers the Plugin API for the Browser library, which allows developers to create Python classes that add new keywords or modify existing library behavior. Plugins inherit from LibraryComponent and gain access to the Browser library's public API, including the gRPC channel to Playwright, assertion engine, and all existing keywords. Plugins can also integrate custom JavaScript modules for direct Playwright page access.

Usage

Execute this workflow when the built-in Browser library keywords are insufficient for your testing needs and you require custom keywords that combine multiple Browser operations, access Playwright features not yet exposed as keywords, or integrate with external systems during browser testing.

Execution Steps

Step 1: Create Plugin Class

Create a Python class that inherits from Browser.base.librarycomponent.LibraryComponent. The constructor must accept a library parameter (the Browser library instance) and call super().__init__(library). This grants access to the library's public API including self.library for calling any Browser keyword.

Key considerations:

  • The plugin class must inherit from LibraryComponent
  • The __init__ method must accept at least the library argument
  • Optional arguments can be passed via semicolons in the import statement
  • Variable-length and keyword arguments are supported

Step 2: Implement Keyword Methods

Define methods decorated with @keyword from robot.api.deco to expose them as Robot Framework keywords. Methods can call any Browser library keyword via self.library.<keyword_name>() syntax, access the gRPC channel for direct Playwright communication, or use self.call_js_keyword() to invoke custom JavaScript functions.

Key considerations:

  • Use the @keyword decorator to mark methods as RF keywords
  • Access the gRPC channel via self.grpc_channel() for direct Playwright communication
  • Call existing Browser keywords via self.library.<method_name>()
  • Plugin keywords are automatically tagged with plugin for documentation filtering

Step 3: Add JavaScript Extension (Optional)

If the plugin requires direct Playwright page-level access beyond what gRPC exposes, create a JavaScript module with exported async functions. Initialize it in the plugin's __init__ using self.initialize_js_extension(path). The JS functions receive page, logger, and custom arguments.

Key considerations:

  • JavaScript functions must be async and exported as CommonJS modules
  • Functions receive (args..., logger, page) as parameters
  • Call JS functions from Python via self.call_js_keyword("functionName", ...)
  • ES2015 modules must be transpiled to CommonJS (e.g., via Babel)

Step 4: Import Plugin in Test Suite

Import the plugin by specifying it in the Browser library's plugins argument. Plugins can be referenced by physical file path or by module name (following Robot Framework's library search path). Multiple plugins are separated by commas. Plugin arguments are separated by semicolons.

Key considerations:

  • Plugin names are case-sensitive and cannot contain spaces
  • Multiple plugins can be imported: plugins=PluginA, PluginB
  • Plugin arguments follow the plugin name with semicolons: plugins=Plugin;arg1;arg2
  • The last plugin to modify a method/keyword wins in case of conflicts

Step 5: Generate Documentation and Test

Generate keyword documentation using libdoc with the plugins argument to include plugin keywords. Test the plugin keywords in Robot Framework test suites. Plugin keywords appear alongside native Browser keywords and are tagged with plugin for identification.

Key considerations:

  • Generate docs: libdoc Browser::plugins=/path/to/Plugin.py Browser.html
  • Plugin failures during import will fail the entire library import
  • Plugin keywords participate in the run-on-failure mechanism
  • Test plugins in isolation before integrating into larger suites

Execution Diagram

GitHub URL

Workflow Repository