Python Library Keyword Failure HTML Message Duplication in Test Message and Keyword

I would like to include some HTML tables as embedded error messages when a python library keyword fails. For example:

foo.robot:

*** Settings ***
Library    foo.py

*** Test Cases ***
Doit
    Tab

foo.py:

def tab():
    html = "*HTML* "
    for table in ["bar", "baz"]:
        html += f"<b>Modified: {table}</b>\n"
        html += "<table border=1 style='border-collapse: collapse;'>\n"
        html += "<tr><th>ID<td>Name\n"
        html += "<tr><td>1<td>Bob\n"
        html += "<tr><td>2<td>Trev\n"
        html += "</table>\n"
    raise AssertionError(html)

This works but there are some nice tweaks I’d like. In the Log the html given in the assertion is repeated in the Test Message and again in the Keyword:
image

Also the html is repeated in the Report Message:

It’s also repeated in the console:
image

If there is a large amount in the Message it is truncated in the middle with [ Message content over the limit has been removed. ]

It would be nice if the error Message was a summary line, for my example something like Modified: bar, baz and then only the Keyword has he full error HTML.

For example if from python I could raise the assertion like:

def tab():
    summary  "Modified: "
    html = "*HTML* "
    for table in ["bar", "baz"]:
        summary += f" {table}"
        html += f"<b>Modified: {table}</b>\n"
        html += "<table border=1 style='border-collapse: collapse;'>\n"
        html += "<tr><th>ID<td>Name\n"
        html += "<tr><td>1<td>Bob\n"
        html += "<tr><td>2<td>Trev\n"
        html += "</table>\n"
    raise AssertionError(summary, html)
1 Like

I came up with the following:

def tab():
    summary = "Modified: "
    html = "*HTML* "
    for table in ["bar", "baz"]:
        summary += f" {table}"
        html += f"<b>Modified: {table}</b>\n"
        html += "<table border=1 style='border-collapse: collapse;'>\n"
        html += "<tr><th>ID<td>Name\n"
        html += "<tr><td>1<td>Bob\n"
        html += "<tr><td>2<td>Trev\n"
        html += "</table>\n"
    print(html)
    raise AssertionError(summary)

By printing the detailed html before the exception is raised, the effect is pretty much as desired. Only the summary appears in the console and the Test Case Message field, with the detailed html provided as an INFO log entry:

image

image

1 Like