Skip to content

Rebot does not preserve order of keywords and messages in output.xml #1867

Closed

Description

@terokinnunen

I have a simple listener, a_logger.py:

from robot.api import logger

ROBOT_LISTENER_API_VERSION = 2

def start_keyword(name, attrs):
    logger.info("Running " + name)

and a sample test case FlatMe.txt:

*** Test Cases ***
Flat
    Keyword 1

*** Keywords ***
Keyword 1
    Keyword 2

Keyword 2
    No operation

Then I run the following sequence:

call pybot --listener a_logger --output output-orig.xml FlatMe.txt 
call rebot --output output-rebot.xml output-orig.xml 
call rebot --flattenkeywords NAME:* --log flat-from-orig.html  output-orig.xml 
call rebot --flattenkeywords NAME:* --log flat-from-rebot.html output-rebot.xml 

I would expect the two log files flat-from-orig.html and flat-from-rebot.html be the same. Instead, the order of log messages in flat-from-rebot.html is incorrect.

flat-from-orig.html (as expected):

18:41:36.899    INFO    Running Keyword 1   
18:41:36.899    INFO    Running Keyword 2   
18:41:36.900    INFO    Running BuiltIn.No Operation

flat-from-rebot.html (unexpected order)

18:41:36.900    INFO    Running BuiltIn.No Operation    
18:41:36.899    INFO    Running Keyword 2   
18:41:36.899    INFO    Running Keyword 1

Activity

  1. pekkaklarck commented on Dec 10, 2014

    @pekkaklarck
    Member

    I can reproduce the problem. It caused a limitation in Robot's internal result model that also causes other issues. For example, if you look at logs from your execution, inside Keyword 1 you first see Keyword 2 and only then message Running Keyword 1. The message was logged before running Keyword 2 so it should be first.

    The limitation in the model is that keywords and messages a keyword has are stored separately. Keywords and messages themselves have an order, but the relative order between keywords and messages is not stored. When keywords and messages are written to a log or to a Rebot generated output.xml, keywords are always written first and messages second. In your case this means that output-orig.xml and output-rebot.xml have messages/keywords in different order.

    The main reason that keyword/message order is not stored is that most of the time keywords only contain either keywords or messages and thus such order doesn't matter. Additionally, you typically can understand the log file anyway also in those somewhat rare cases where keywords have both messages and keywords. For example, you didn't complain that the order in log is wrong in both cases. Using --FlattenKeywords removes the keyword structure and thus the problem gets much worse.

    This is definitely an issue I'd like to see fixed. The problem I'm not sure what would be the best approach to fix it, and knowing the code I know it's not going to be easy. We also need to be extra careful with performance when modifying code related to XML parsing and log creation.

  2. pekkaklarck commented on Dec 10, 2014

    @pekkaklarck
    Member

    I prototyped this and keeping the keyword/message order turned out to be doable. I added new children attribute to keywords that returns a list containing keywords and messages in order they have been defined. It was also easy to change Rebot to write output.xml so that it uses this new children attribute. My current prototype code basically fixes the original reported problem. It needs a little clean-up and more tests, but I don't see why I couldn't get it into 2.8.7.

    Fixing message/keyword order in logs is a separate task. I briefly looked at it, and it seems to require changes both to log files own Javascript code to Python code that generates the Javascript model used by logs. I'll take a second look at it later, but it will be a topic of a separate issue anyway.

  3. added this to the 2.8.7 milestone on Dec 10, 2014
  4. self-assigned this
    on Dec 10, 2014
  5. changed the title [-]Rebot changes listener log message order[/-] [+]Rebot does not preserve order of keywords and messages in output.xml[/+] on Dec 10, 2014
  6. terokinnunen commented on Dec 10, 2014

    @terokinnunen
    ContributorAuthor

    I see, so the flattening strips the structure first and then writes the log output, that is why the order remains right from the original xml. It is true that the order in the logs is keywords first, then output but in non-flattened log it is not that confusing, not even close. Maybe you could even say it looks intentional. But now that you mentioned it, it is true that it would be nicer to preserve the right order in the non-flattened log as well, but I agree that is a separate issue.

    Nice to hear that you were able to find a reasonable resolution for rebot maintaining the order, thanks!

  7. added theissue type on Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions