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 JavaScript Extension

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

Overview

End-to-end process for extending the Browser library with custom JavaScript keyword modules that run directly in the Playwright page context.

Description

This workflow covers creating JavaScript modules that define custom keyword functions, which are automatically discovered and exposed as Robot Framework keywords when the Browser library is imported with the jsextension parameter. JavaScript keywords execute directly in the Node.js Playwright context, giving access to the Playwright page object, a logger function, and any custom arguments. This is the simplest way to extend the Browser library for page-level automation not covered by built-in keywords.

Usage

Execute this workflow when you need custom browser automation capabilities that require direct Playwright page API access, such as custom mouse gestures, complex DOM manipulations, or interactions with browser APIs (WebGL, Web Audio, etc.) not exposed by the built-in keywords.

Execution Steps

Step 1: Create JavaScript Module

Create a JavaScript file with exported async functions. Each exported function becomes a Robot Framework keyword. Functions receive custom arguments first, followed by logger and page parameters injected by the Browser library. Use CommonJS module syntax (exports.functionName = functionName).

Key considerations:

  • Functions must be async (return a Promise)
  • Parameter order: custom args first, then logger, then page
  • The page parameter provides the full Playwright Page API
  • The logger function writes to Robot Framework's log
  • Set .rfdoc property on functions to provide keyword documentation
  • Use exports.__esModule = true for module compatibility

Step 2: Transpile ES2015+ Modules (If Needed)

If using modern JavaScript syntax (import/export, arrow functions in module scope, etc.), transpile the source to CommonJS format using Babel with the @babel/plugin-transform-modules-commonjs plugin. The Browser library requires CommonJS exports for keyword discovery.

Key considerations:

  • Install Babel: npm install --save-dev @babel/core @babel/cli @babel/plugin-transform-modules-commonjs
  • Configure babel.config.json with the modules plugin
  • Run npx babel src --out-dir lib to transpile
  • Reference the transpiled output (lib/) in the library import, not the source

Step 3: Import Extension in Library

Import the Browser library with the jsextension parameter pointing to the JavaScript module file. Multiple JS files can be provided as a comma-separated list. Keywords from the JS module are discovered during library initialization and become available alongside built-in keywords.

Key considerations:

  • Use ${CURDIR} variable for relative paths in Robot Framework
  • Multiple extensions: jsextension=${CURDIR}/module1.js,${CURDIR}/module2.js
  • JS keywords are discovered after built-in keywords but before plugin keywords
  • Function names are converted to Robot Framework keyword naming convention

Step 4: Use Custom Keywords in Tests

Call the JavaScript-defined keywords from Robot Framework test cases like any other keyword. Arguments are passed positionally and converted to appropriate JavaScript types. Return values are converted back to Robot Framework types (strings, numbers, lists, dicts).

Key considerations:

  • Keyword names follow Robot Framework conventions (spaces between words)
  • Return values from JavaScript are automatically serialized
  • Errors thrown in JavaScript propagate as Robot Framework failures
  • The page object gives access to all Playwright methods (mouse, keyboard, evaluate, etc.)

Execution Diagram

GitHub URL

Workflow Repository