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 Assertion Formatter

From Leeroopedia
Knowledge Sources
Domains Assertion, Formatting
Last Updated 2026-02-12 05:40 GMT

Overview

Provides the Formatter class that manages assertion formatters for text transformations applied to keyword return values before assertion evaluation.

Description

The Formatter class inherits from both ASFormatter (from the assertionengine package) and LibraryComponent. It exposes two Robot Framework keywords: Set Assertion Formatter (for setting formatters on individual keywords) and Set Assertion Formatters (for setting formatters on multiple keywords at once via a dictionary). Formatters are text transformation functions such as strip, normalize spaces, and case insensitive that are applied to assertion values before comparison. Formatters can be scoped at Global, Suite, or Test level. Custom lambda functions can also be provided as formatters. The class manages a formatter stack that tracks active formatters per keyword and scope, and provides methods for clearing formatters, converting between formatter representations, and retrieving the active formatter list for a given keyword.

Usage

Use this class when you need to apply text transformations to assertion values before comparison. This is particularly useful when dealing with whitespace variations, case sensitivity, or custom string normalization needs in your Browser library assertions.

Code Reference

Source Location

Signature

class Formatter(ASFormatter, LibraryComponent):

    def set_assertion_formatter(
        self,
        keyword: FormatterKeywords | None = None,
        *formatters: FormatingRules | LambdaFunction,
        scope: Scope = Scope.Global,
    ) -> dict[str, list[str]]:

    def set_assertion_formatters(
        self, formatters: FormatterTypes, scope: Scope = Scope.Suite
    ) -> dict[str, list[str]]:

Import

from Browser.keywords.assertion_formatter import Formatter

I/O Contract

Inputs

Name Type Required Description
keyword FormatterKeywords or None No The name of the keyword where the assertion formatter is applied. None clears all formatters from all keywords.
formatters FormatingRules, LambdaFunction, or FormatterTypes No Formatter rules to apply. Can be built-in rules (e.g., strip, normalize spaces), lambda functions, or a dictionary mapping keyword names to lists of formatters.
scope Scope No Defines the lifetime of the formatter. Possible values are Global, Suite, and Test. Defaults to Global for set_assertion_formatter and Suite for set_assertion_formatters.

Outputs

Name Type Description
old_formatters dict[str, list[str]] Dictionary mapping keyword names to their previous list of formatter names that were replaced.

Usage Examples

Robot Framework

*** Test Cases ***
Set Strip Formatter For Get Text
    Set Assertion Formatters    {"Get Text": ["strip", "normalize spaces"]}
    Get Text    id=myElement    ==    expected text

Set Lambda Formatter For Get Title
    Set Assertion Formatters    {"Get Title": ["apply to expected", "lambda x: x.replace(' ', '')"]}
    Get Title    ==    ExpectedTitle

Clear All Formatters
    Set Assertion Formatters    {}

Related Pages

Page Connections

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