Skip to content Skip to sidebar Skip to footer

User Keyword's Robot.running.model.keyword Object Children Attribute Returns Empty List In Prerunmodifier Start_suite Function

I have a simple prerunmodifier that implements the start_suite function in which it gets the suite setup keyword from the suite variable and prints its attributes. The object is an

Solution 1:

I have managed to find the relevant part in Robot Framework's API documentation. What I am trying to achieve is not possible.

Visitors make it easy to modify test suite structures or to collect information from them. They work both with the executable model and the result model, but the objects passed to the visitor methods are slightly different depending on the model they are used with. The maindifferences are that on the execution side keywords do not have childkeywords nor messages, and that only the result objects have status related attributes like status and starttime.

Solution 2:

With Robot Framework 4.0 it is possible if the keyword that is used as a suite setup is implemented within the suite itself, aka if the suite owns the keyword. The robot.running.model.TestSuiteresource attribute's doc says:

ResourceFile instance containing imports, variables and keywords the suite owns. When data is parsed from the file system, this data comes from the same test case file that creates the suite.

So the children keywords and their args can be found in suite.resource.keywords object list.

from robot.api import SuiteVisitor

classVisitor(SuiteVisitor):
    
    defstart_suite(self, suite):
        for keyword in suite.resource.keywords:
            if suite.setup.name == keyword.name:
                for item in keyword.body:
                    print(f'{item.name} - {item.args} - {item.type}')

                if keyword.teardown.name:
                    print(f'{keyword.teardown.name} - {keyword.teardown.args} - {keyword.teardown.type}')

This prints:

Log - ('1st child',) - KEYWORD
Log Many - ('2nd', 'child') - KEYWORD
No Operation - () - KEYWORD
My Keyword Teardown - () - TEARDOWN

Again, this does not work if the user keyword is implemented in an imported resource file and not in the suite file itself.

Post a Comment for "User Keyword's Robot.running.model.keyword Object Children Attribute Returns Empty List In Prerunmodifier Start_suite Function"