You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When modifying a keyword's body via the start_user_keyword listener method, changes do not take effect for the current execution of the keyword. The modified behavior only applies when the keyword is called again in subsequent executions. This prevents real-time keyword suppression/dynamic modification during test runs.
Steps to Reproduce
Create a listener that modifies keyword definitions in start_user_keyword: KeywordSuppresor.py
classKeywordSuppressor:
ROBOT_LISTENER_API_VERSION=3def__init__(self, kw_name):
self.keyword_to_skip=kw_namedefstart_user_keyword(self, data, implementation, result):
ifdata.name==self.keyword_to_skip:
resource=implementation.ownerforkwinresource.keywords:
ifdata.name==kw.name:
kw.body.clear()
kw.body.create_keyword(
"Log",
[
f"ROBOT LISTENER: KeywordSuppressor - the keyword '{kw.name}' is requested to be skipped."
],
)
Create Testcase and Resource file Keyword.resource
A bit more background. The implementation you got is a robot.running.UserKeyword instance that is going to be executed. If you modify its body, changes ought to be taken into account. To avoid this kind of changes affecting subsequent calls of the same keyword, the actual implementation object you get is a copy of the keyword that the resource file contains.
In your code you find the keyword from the resource file and modify that. Also these keywords are robot.running.UserKeyword instances. Due to the reasons explained above, changing them doesn't affect the current keyword but changes the subsequent calls.
Notice also that the data object contains the data that's used in the test and keyword name and arguments are exactly in the format used there. Thus when matching data.name, you should take at least case-sensitivity into account. It would probably be safer to use implementation.name instead.
Problem Description
When modifying a keyword's body via the
start_user_keyword
listener method, changes do not take effect for the current execution of the keyword. The modified behavior only applies when the keyword is called again in subsequent executions. This prevents real-time keyword suppression/dynamic modification during test runs.Steps to Reproduce
Create a listener that modifies keyword definitions in
start_user_keyword
:KeywordSuppresor.py
Create Testcase and Resource file
Keyword.resource
Test.robot
Call
robot --pythonpath . -b rlog --listener ./xxx/KeywordSuppressor.py:'Resource Keyword1' ./xxx/Test.robot
Expected Behavior
Modifications made in
start_user_keyword
should immediately affect the current execution of the keyword being processed.Actual Behavior
Changes only take effect on subsequent calls to the keyword.

Need confirmed if this is intentional design or a limitation of the listener API
Environment
Robotframework 7.1
Python Version 3.9.9
The text was updated successfully, but these errors were encountered: