User Keyword's Robot.running.model.keyword Object Children Attribute Returns Empty List In Prerunmodifier Start_suite Function
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 theresult 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 likestatus
andstarttime
.
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.TestSuite
resource
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"