Repository navigation
Description
As we observed during RED debugger implementation everytime RF during test execution meets keyword, which are :FOR loop, the type attribute in start_keyword attributes dictionary/map is set to Test For and the same is done when loop keyword is end. For corresponding items inside loop the type is set to Test Foritem. We are strongly base on this contract for present user, which line is currently executed by RF. This works completly correct, when the loop is made from Library keywords or simple user keywords (here I mean without loop inside).
When we made test case like below (LoopInLoop.robot), where Nested Loop Keyword contains inside also internal :FOR loop we get wrong about type of Nested Loop Keyword in case of end_keyword function from listener API - the type is Keyword instead of Test Foritem. The same problem shows also for next loop item \ Log 'End for: ' ${x}, but for both start_keyword and end_keyword.
Listener output for LoopInLoop.robot execution (see lines: 16-18 and 32-34)
1 {start_keyword, name=BuiltIn.Log, type=Keyword}
2 {end_keyword, name=BuiltIn.Log, type=Keyword}
3 {start_keyword, name=${x} IN RANGE [ 0 | 2 ], type=Test For}
4 {start_keyword, name=${x} = 0, type=Test Foritem}
5 {start_keyword, name=BuiltIn.Log, type=Test Foritem}
6 {end_keyword, name=BuiltIn.Log, type=Test Foritem}
7 {start_keyword, name=Nested Loop Keyword, type=Test Foritem}
8 {start_keyword, name=BuiltIn.Log, type=Test Foritem}
9 {end_keyword, name=BuiltIn.Log, type=Test Foritem}
10 {start_keyword, name=${y} IN RANGE [ 0 | 1 ], type=Test For}
11 {start_keyword, name=${y} = 0, type=Test Foritem}
12 {start_keyword, name=BuiltIn.Log, type=Test Foritem}
13 {end_keyword, name=BuiltIn.Log, type=Test Foritem}
14 {end_keyword, name=${y} = 0, type=Test Foritem}
15 {end_keyword, name=${y} IN RANGE [ 0 | 1 ], type=Test For}
16 {end_keyword, name=Nested Loop Keyword, type=Keyword}
17 {start_keyword, name=BuiltIn.Log, type=Keyword}
18 {end_keyword, name=BuiltIn.Log, type=Keyword}
19 {end_keyword, name=${x} = 0, type=Test Foritem}
20 {start_keyword, name=${x} = 1, type=Test Foritem}
21 {start_keyword, name=BuiltIn.Log, type=Test Foritem}
22 {end_keyword, name=BuiltIn.Log, type=Test Foritem}
23 {start_keyword, name=Nested Loop Keyword, type=Test Foritem}
24 {start_keyword, name=BuiltIn.Log, type=Test Foritem}
25 {end_keyword, name=BuiltIn.Log, type=Test Foritem}
26 {start_keyword, name=${y} IN RANGE [ 0 | 1 ], type=Test For}
27 {start_keyword, name=${y} = 0, type=Test Foritem}
28 {start_keyword, name=BuiltIn.Log, type=Test Foritem}
29 {end_keyword, name=BuiltIn.Log, type=Test Foritem}
30 {end_keyword, name=${y} = 0, type=Test Foritem}
31 {end_keyword, name=${y} IN RANGE [ 0 | 1 ], type=Test For}
32 {end_keyword, name=Nested Loop Keyword, type=Keyword}
33 {start_keyword, name=BuiltIn.Log, type=Keyword}
34 {end_keyword, name=BuiltIn.Log, type=Keyword}
35 {end_keyword, name=${x} = 1, type=Test Foritem}
36 {end_keyword, name=${x} IN RANGE [ 0 | 2 ], type=Test For}
37 {start_keyword, name=BuiltIn.Log, type=Keyword}
38 {end_keyword, name=BuiltIn.Log, type=Keyword}
DATA TO REPRODUCE
LoopInLoop.robot file content:
*** Test Cases ***
ForTest
Log start
:FOR ${x} IN RANGE 0 2
\ Log 'Start for: ' ${x}
\ Nested Loop Keyword ${x}
\ Log 'End for: ' ${x}
Log end
*** Keywords ***
Nested Loop Keyword
[Arguments] ${got}
Log ${got}
:FOR ${y} IN RANGE 0 1
\ Log ${y}MyListener.py file content used to collect data as RF execution listener via option --listener:
import os.path
import tempfile
class MyListener(object):
ROBOT_LISTENER_API_VERSION = 2
def __init__(self, filename='listen.txt'):
self.output_path = os.path.join(tempfile.gettempdir(), filename)
print 'Communication stored in: ' + str(self.output_path)
self.outfile = open(self.output_path, 'w')
self.line_number = 0
def start_keyword(self, name, attributes):
self.line_number += 1
self.outfile.write(str(self.line_number) + ' {start_keyword, name=' + str(name) + ', type=' + str(attributes['type']) + '}')
self.outfile.write('\n')
def end_keyword(self, name, attributes):
self.line_number += 1
self.outfile.write(str(self.line_number) + ' {end_keyword, name=' + str(name) + ', type=' + str(attributes['type']) + '}')
self.outfile.write('\n')
def close(self):
self.outfile.close()The problem also show up on the newest RF 3.0a1 version.
Activity
pekkaklarck commentedon Nov 23, 2015
Interesting bug, thanks for the report. The problem actually is that the code setting keyword types in listeners doesn't take for loops into account at all. It tries to return
KeywordorSuite/Test Setup/Teardownto make it possible to know is a normal keyword or setup/teardown executed. As you can see from the code, it totally ignores the possibility that type can also befororforitem:https://github.com/robotframework/robotframework/blob/master/src/robot/output/listeners.py#L129
This is easy to fix but we need to first decide how to fix it. Should we set type to
FororFor Loopwhen a for loop starts? Should we use the same when different iterations start or should we then use something likeFor ItemorFor Loop Iteration?[-]RF wrongly notify test execution listener in case :FOR loop inside other :FOR loop exists in test case[/-][+]Keyword type passed to listeners is wrong then keyword is for loop[/+]adam-wypych commentedon Nov 23, 2015
In my opinion only the first
:FORshould get typeforand anything inside this loop include other:FORshould get type asforitem. In our case and I think in most cases listener is not able to judgment what new iterations will brings and the fact that to get:FORin:FORwe need to bring this nested loop to other keyword is enough to get where we are now.jussimalinen commentedon Nov 23, 2015
Internally foritem is a bad name for one iteration of the loop. (You will see this in the log file).
So considering this input:
We would suggest renaming the foritem to for loop and the listener would then get the following events:
How does this seem to you?
adam-wypych commentedon Nov 23, 2015
Can you describe Your proposal (events, which will we get) base on below test case:
Thanks in advance for your prompt responses.
jussimalinen commentedon Nov 23, 2015
We talked with @pekkaklarck that the per loop item could be called "for loop" and each iteration "for iteration".
So like this:
adam-wypych commentedon Nov 23, 2015
The most important for us is to get the same
typeattribute in theend_keywordas we will get instart_keywordlistener API function - without this information we will be blind. The second information is to clear indicate that RF execute currently repeat/iterate action - here:forloop. For me seems that we can meet this goal with this new two types, but it will be nice to do not mix oldTest foritemwith new types for loop iteration proposed by You.pekkaklarck commentedon Nov 23, 2015
OK, will go with the design illustrated by @jussimalinen above. I guess type names
For LoopandFor Iterationare good enough. OldTest foritemetc. were just bugs, they won't appear as types once we get this fixed.adam-wypych commentedon Nov 23, 2015
OK thanks for both of You.
pekkaklarck commentedon Nov 23, 2015
Actually, would it be enough if the type would just be
Keyword? After studying this a bit more (including issue #859 that introduced thetypeattribute), I noticed that type isSuite/Test Setup/Teardownnot only with the top level keyword uses as setup/teardown has but also with all keywords it uses. It would be more consistent to use same type everywhere.adam-wypych commentedon Nov 23, 2015
Yes type
keywordis enough for keywords inside other keywords, if main keyword will give much information where is executed - meansSuite/Test Setup/Teardown/Testor:FORloop.9 remaining items
adam-wypych commentedon Dec 1, 2015
Ok as I understand the implementation will have 3 types only
setup\keyword\teardownif yes then is acceptable.pekkaklarck commentedon Dec 1, 2015
My plan was to have types
keyword,setup,teardown,for loopandfor iteration(exact spelling/casing not yet decided). I wouldn't mind usingkeywordalso with for loops, but somehow using the actual type sounds better to me.adam-wypych commentedon Dec 1, 2015
@pekkaklarck for me its totaly ok with those 3 types (
keyword,setup,teardown) minimum and maximum 5pekkaklarck commentedon Dec 6, 2015
Submitted #2248 about changes that we are going to do keyword type reporting. Problems initially reported here will be fixed as part of it, so I'll close this issue as its duplicate.
pekkaklarck commentedon Dec 11, 2015
Have you @adam-wypych had a change to test alpha 2 and how types work there? We can still do modifications before the final version if needed.
adam-wypych commentedon Dec 11, 2015
@Mateosy could you comment since is your nice feature ;) ?
Mateosy commentedon Dec 30, 2015
Hi, It works fine for me.
sathishj-gh1 commentedon Nov 5, 2018
Hi Pekkaklarck,
if only the top level keyword has the type of Setup/Teardown, how do i know when Setup/Teardown keywords finishes and the Test keyword begins in case of nested keywords in the setup/teardown?
Thanks
Sathish
adam-wypych commentedon Nov 9, 2018
@sathishj-gh1 you need to simple
a) implement your stack for getting notify about keywords executed so far
b) in listener API http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#id780 you have end_keyword message - then you need to check the type 'type: String Keyword for normal keywords, Setup or Teardown for the top level keyword used as setup/teardown, For for for loops, and For Item for individual for loop iterations. NOTE: Keyword type reporting was changed in RF 3.0. See issue #2248 for details.'
The b option is so far the best one ;)