Add tags to keywords of builtin library based on configuration

i may not get the point, but was curious and tested with copilot. the result is a example test case like:

** Settings ***
Library    CustomListener.py

*** Test Cases ***
TEST A
    Log To Console    HI test A will pass

E2E_TEST B
    Log To Console    HI test B will Fail
    Should Be Equal As Strings    1    2
    Should Contain    "Hello"    "World"
    Log To Console    Hi test B still continues

TEST C
    Log To Console    Hi test C will Pass

now, using a listener you can dynamically update the tags or keywords, but depends of course if you can name the test cases where you want to add “robot:continue-on-failure” and if all your “should” assertions are ment to be conditinaly soft asserted and hence updated, or just some of “shoulds…” but if yes, you may try with listener where basically the “should” assertions will be “prefixed/wrapped” with Run keyword and continue on failure, hence test will not fail here.

from robot.libraries.BuiltIn import BuiltIn

class CustomListener:
ROBOT_LISTENER_API_VERSION = 3

def start_test(self, data, result):
    """Dynamically add 'robot:continue-on-failure' tag to test cases starting with 'E2E_'."""
    if data.name.startswith("E2E_"):
        BuiltIn().run_keyword("Set Tags", "robot:continue-on-failure")
        print(f"🔹 Added 'robot:continue-on-failure' tag to test: {data.name}")

def start_keyword(self, data, result):
    """Wrap assertion keywords in 'Run Keyword And Continue On Failure'."""
    assertion_keywords = ["Should Be Equal", "Should Be True", "Should Contain",
                          "Should Not Be Equal", "Should Not Be Empty"]

    if any(data.name.startswith(kw) for kw in assertion_keywords):
        print(f"⚠️ Wrapping '{data.name}' with continue-on-failure")

        # Modify the keyword to run within "Run Keyword And Continue On Failure"
        data.name = "BuiltIn.Run Keyword And Continue On Failure"
        data.args = ["BuiltIn." + data.name] + list(data.args)

def end_test(self, data, result):
    """Log test result."""
    print(f"✅ Finished test: {data.name} | Status: {result.status} | Tags: {', '.join(data.tags)}")

so running robot --listener CustomListener.py test.robot adds tag to “E2E” test case and updates “should…” keywords

2 Likes