Skip to content

Commit b0c1923

Browse files
Snooz82pekkaklarck
andauthored
Add GROUP syntax (PR #5275, issue #5257)
Functionality done and tested. Using with templates as well as documentation still missing. --------- Co-authored-by: Pekka Klärck <peke@iki.fi>
1 parent e5cee95 commit b0c1923

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1246
-139
lines changed

atest/resources/TestCheckerLibrary.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from robot.libraries.BuiltIn import BuiltIn
99
from robot.result import (
1010
Break, Continue, Error, ExecutionResult, ExecutionResultBuilder, For,
11-
ForIteration, If, IfBranch, Keyword, Result, ResultVisitor, Return,
11+
ForIteration, Group, If, IfBranch, Keyword, Result, ResultVisitor, Return,
1212
TestCase, TestSuite, Try, TryBranch, Var, While, WhileIteration
1313
)
1414
from robot.result.model import Body, Iterations
@@ -55,6 +55,10 @@ class ATestWhile(While, WithBodyTraversing):
5555
pass
5656

5757

58+
class ATestGroup(Group, WithBodyTraversing):
59+
pass
60+
61+
5862
class ATestIf(If, WithBodyTraversing):
5963
pass
6064

@@ -89,6 +93,7 @@ class ATestBody(Body):
8993
if_class = ATestIf
9094
try_class = ATestTry
9195
while_class = ATestWhile
96+
group_class = ATestGroup
9297
var_class = ATestVar
9398
return_class = ATestReturn
9499
break_class = ATestBreak
@@ -118,7 +123,8 @@ class ATestIterations(Iterations, WithBodyTraversing):
118123

119124
ATestKeyword.body_class = ATestVar.body_class = ATestReturn.body_class \
120125
= ATestBreak.body_class = ATestContinue.body_class \
121-
= ATestError.body_class = ATestBody
126+
= ATestError.body_class = ATestGroup.body_class \
127+
= ATestBody
122128
ATestFor.iterations_class = ATestWhile.iterations_class = ATestIterations
123129
ATestFor.iteration_class = ATestForIteration
124130
ATestWhile.iteration_class = ATestWhileIteration

atest/robot/running/group/group.robot

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
*** Settings ***
2+
Suite Setup Run Tests ${EMPTY} running/group/group.robot
3+
Resource atest_resource.robot
4+
5+
*** Test Cases ***
6+
Simple GROUP
7+
${tc}= Check Test Case ${TESTNAME}
8+
Check Body Item Data ${tc[0]} type=GROUP name=name 1 children=2
9+
Check Body Item Data ${tc[0, 0]} type=KEYWORD name=Log args=low level
10+
Check Body Item Data ${tc[1]} type=GROUP name=name 2 children=1
11+
Check Body Item Data ${tc[1, 0]} type=KEYWORD name=Log
12+
Check Body Item Data ${tc[2]} type=KEYWORD name=Log args=this is the end
13+
14+
GROUP in keywords
15+
${tc}= Check Test Case ${TESTNAME}
16+
Check Body Item Data ${tc[0]} type=KEYWORD name=Keyword With A Group children=4
17+
Check Body Item Data ${tc[0, 0]} type=KEYWORD name=Log args=top level
18+
Check Body Item Data ${tc[0, 1]} type=GROUP name=frist keyword GROUP children=2
19+
Check Body Item Data ${tc[0, 2]} type=GROUP name=second keyword GROUP children=1
20+
Check Body Item Data ${tc[0, 3]} type=KEYWORD name=Log args=this is the end
21+
22+
Anonymous GROUP
23+
${tc}= Check Test Case ${TESTNAME}
24+
Check Body Item Data ${tc[0]} type=GROUP name=${EMPTY} children=1
25+
Check Body Item Data ${tc[0, 0]} type=KEYWORD name=Log args=this group has no name
26+
27+
Test With Vars In GROUP Name
28+
${tc}= Check Test Case ${TESTNAME}
29+
Check Body Item Data ${tc[0]} type=GROUP name=Test is named: Test With Vars In GROUP Name children=1
30+
Check Body Item Data ${tc[0, 0]} type=KEYWORD name=Log args=\${TEST_NAME}
31+
Check Log Message ${tc[0, 0, 0]} Test With Vars In GROUP Name
32+
Check Body Item Data ${tc[1]} type=GROUP name=42 children=1
33+
Check Body Item Data ${tc[1, 0]} type=KEYWORD name=Log args=Should be 42
34+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
*** Settings ***
2+
Suite Setup Run Tests ${EMPTY} running/group/invalid_group.robot
3+
Resource atest_resource.robot
4+
5+
*** Test Cases ***
6+
END missing
7+
${tc} Check Test Case ${TESTNAME} status=FAIL message=GROUP must have closing END.
8+
Length Should Be ${tc.body} 1
9+
Check Body Item Data ${tc[0]} GROUP status=FAIL children=1 message=GROUP must have closing END.
10+
11+
Empty GROUP
12+
${tc} Check Test Case ${TESTNAME} status=FAIL message=GROUP cannot be empty.
13+
Length Should Be ${tc.body} 2
14+
Check Body Item Data ${tc[0]} GROUP status=FAIL children=1 message=GROUP cannot be empty.
15+
Check Body Item Data ${tc[1]} KEYWORD status=NOT RUN name=Log args=Last Keyword
16+
17+
Multiple Parameters
18+
${tc} Check Test Case ${TESTNAME} status=FAIL message=GROUP accepts only one argument as name, got 3 arguments 'Log', '123' and '321'.
19+
Length Should Be ${tc.body} 2
20+
Check Body Item Data ${tc[0]} GROUP status=FAIL children=1 message=GROUP accepts only one argument as name, got 3 arguments 'Log', '123' and '321'.
21+
Check Body Item Data ${tc[1]} KEYWORD status=NOT RUN name=Log args=Last Keyword
22+
23+
Non existing var in Name
24+
${tc} Check Test Case ${TESTNAME} status=FAIL message=Variable '\${non_existing_var}' not found.
25+
Length Should Be ${tc.body} 2
26+
Check Body Item Data ${tc[0]} GROUP status=FAIL children=1 message=Variable '\${non_existing_var}' not found.
27+
Check Body Item Data ${tc[1]} KEYWORD status=NOT RUN name=Log args=Last Keyword
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
*** Settings ***
2+
Suite Setup Run Tests ${EMPTY} running/group/nesting_group.robot
3+
Resource atest_resource.robot
4+
5+
*** Test Cases ***
6+
Test with Nested Groups
7+
${tc} Check Test Case ${TESTNAME}
8+
Check Body Item Data ${tc[0]} type=GROUP name=
9+
Check Body Item Data ${tc[0, 0]} type=KEYWORD name=Set Variable
10+
Check Body Item Data ${tc[0, 1]} type=GROUP name=This Is A Named Group
11+
Check Body Item Data ${tc[0, 1, 0]} type=KEYWORD name=Should Be Equal
12+
13+
Group with other control structure
14+
${tc} Check Test Case ${TESTNAME}
15+
Check Body Item Data ${tc[0]} type=IF/ELSE ROOT
16+
Check Body Item Data ${tc[0, 0]} type=IF condition=True children=2
17+
Check Body Item Data ${tc[0, 0, 0]} type=GROUP name=Hello children=1
18+
Check Body Item Data ${tc[0, 0, 0, 0]} type=VAR name=\${i}
19+
Check Body Item Data ${tc[0, 0, 1]} type=GROUP name=With WHILE children=2
20+
Check Body Item Data ${tc[0, 0, 1, 0]} type=WHILE condition=$i < 2 children=2
21+
Check Body Item Data ${tc[0, 0, 1, 0, 0]} type=ITERATION
22+
Check Body Item Data ${tc[0, 0, 1, 0, 0, 0]} type=GROUP name=Group1 Inside WHILE (0) children=1
23+
Check Body Item Data ${tc[0, 0, 1, 0, 0, 0, 0]} type=KEYWORD name=Log args=\${i}
24+
Check Body Item Data ${tc[0, 0, 1, 0, 0, 1]} type=GROUP name=Group2 Inside WHILE children=1
25+
Check Body Item Data ${tc[0, 0, 1, 0, 0, 1, 0]} type=VAR name=\${i} value=\${i + 1}
26+
Check Body Item Data ${tc[0, 0, 1, 0, 1]} type=ITERATION
27+
Check Body Item Data ${tc[0, 0, 1, 0, 1, 0]} type=GROUP name=Group1 Inside WHILE (1) children=1
28+
Check Body Item Data ${tc[0, 0, 1, 0, 1, 0, 0]} type=KEYWORD name=Log args=\${i}
29+
Check Body Item Data ${tc[0, 0, 1, 0, 1, 1]} type=GROUP name=Group2 Inside WHILE children=1
30+
Check Body Item Data ${tc[0, 0, 1, 0, 1, 1, 0]} type=VAR name=\${i} value=\${i + 1}
31+
Check Body Item Data ${tc[0, 0, 1, 1]} type=IF/ELSE ROOT
32+
Check Body Item Data ${tc[0, 0, 1, 1, 0]} type=IF status=NOT RUN condition=$i != 2 children=1
33+
Check Body Item Data ${tc[0, 0, 1, 1, 0, 0]} type=KEYWORD status=NOT RUN name=Fail args=Shall be logged but NOT RUN
34+
35+
36+
37+
Test With Not Executed Groups
38+
${tc} Check Test Case ${TESTNAME}
39+
Check Body Item Data ${tc[0]} type=VAR name=\${var} value=value
40+
Check Body Item Data ${tc[1]} type=IF/ELSE ROOT
41+
Check Body Item Data ${tc[1, 0]} type=IF condition=True children=1
42+
Check Body Item Data ${tc[1, 0, 0]} type=GROUP name=GROUP in IF children=2
43+
Check Body Item Data ${tc[1, 0, 0, 0]} type=KEYWORD name=Should Be Equal
44+
Check Body Item Data ${tc[1, 0, 0, 1]} type=IF/ELSE ROOT
45+
Check Body Item Data ${tc[1, 0, 0, 1, 0]} type=IF status=PASS condition=True children=1
46+
Check Body Item Data ${tc[1, 0, 0, 1, 0, 0]} type=KEYWORD status=PASS name=Log args=IF in GROUP
47+
Check Body Item Data ${tc[1, 0, 0, 1, 1]} type=ELSE status=NOT RUN
48+
Check Body Item Data ${tc[1, 0, 0, 1, 1, 0]} type=GROUP status=NOT RUN name=GROUP in ELSE children=1
49+
Check Body Item Data ${tc[1, 0, 0, 1, 1, 0, 0]} type=KEYWORD status=NOT RUN name=Fail args=Shall be logged but NOT RUN
50+
Check Body Item Data ${tc[1, 1]} type=ELSE status=NOT RUN
51+
Check Body Item Data ${tc[1, 1, 0]} type=GROUP status=NOT RUN name= children=1
52+
Check Body Item Data ${tc[1, 1, 0, 0]} type=KEYWORD status=NOT RUN name=Fail args=Shall be logged but NOT RUN

atest/robot/running/steps_after_failure.robot

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ IF after failure
3636
Check Keyword Data ${tc[1, 1, 0]}
3737
... BuiltIn.Fail assign=\${x} args=This should not be run status=NOT RUN
3838

39+
GROUP after failure
40+
${tc} = Check Test Case ${TESTNAME}
41+
Should Not Be Run ${tc[1:]}
42+
Should Not Be Run ${tc[1].body} 2
43+
Check Keyword Data ${tc[1,1]}
44+
... BuiltIn.Fail assign=\${x} args=This should not be run status=NOT RUN
45+
3946
FOR after failure
4047
${tc} = Check Test Case ${TESTNAME}
4148
Should Not Be Run ${tc[1:]}
@@ -89,10 +96,12 @@ Nested control structure after failure
8996
Should Be Equal ${tc[1, 0, 0, 0, 0].type} FOR
9097
Should Not Be Run ${tc[1, 0, 0, 0, 0].body} 1
9198
Should Be Equal ${tc[1, 0, 0, 0, 0, 0].type} ITERATION
92-
Should Not Be Run ${tc[1, 0, 0, 0, 0, 0].body} 3
99+
Should Not Be Run ${tc[1, 0, 0, 0, 0, 0].body} 2
93100
Should Be Equal ${tc[1, 0, 0, 0, 0, 0, 0].type} KEYWORD
94-
Should Be Equal ${tc[1, 0, 0, 0, 0, 0, 1].type} KEYWORD
95-
Should Be Equal ${tc[1, 0, 0, 0, 0, 0, 2].type} KEYWORD
101+
Should Be Equal ${tc[1, 0, 0, 0, 0, 0, 1].type} GROUP
102+
Should Not Be Run ${tc[1, 0, 0, 0, 0, 0, 1].body} 2
103+
Should Be Equal ${tc[1, 0, 0, 0, 0, 0, 1, 0].type} KEYWORD
104+
Should Be Equal ${tc[1, 0, 0, 0, 0, 0, 1, 1].type} KEYWORD
96105
Should Be Equal ${tc[1, 0, 0, 0, 1].type} KEYWORD
97106
Should Be Equal ${tc[1, 0, 0, 1].type} ELSE
98107
Should Not Be Run ${tc[1, 0, 0, 1].body} 2
@@ -137,6 +146,13 @@ Failure in ELSE branch
137146
Should Not Be Run ${tc[0, 1][1:]}
138147
Should Not Be Run ${tc[1:]}
139148

149+
Failure in GROUP
150+
${tc} = Check Test Case ${TESTNAME}
151+
Should Not Be Run ${tc[0,0][1:]}
152+
Should Not Be Run ${tc[0][1:]} 2
153+
Should Not Be Run ${tc[0,2].body}
154+
Should Not Be Run ${tc[1:]}
155+
140156
Failure in FOR iteration
141157
${tc} = Check Test Case ${TESTNAME}
142158
Should Not Be Run ${tc[1:]}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
*** Settings ***
2+
Suite Setup Keyword With A Group
3+
Suite Teardown Keyword With A Group
4+
5+
6+
*** Test Cases ***
7+
Simple GROUP
8+
GROUP
9+
... name 1
10+
Log low level
11+
Log another low level
12+
END
13+
GROUP name 2
14+
Log yet another low level
15+
END
16+
Log this is the end
17+
18+
GROUP in keywords
19+
Keyword With A Group
20+
21+
Anonymous GROUP
22+
GROUP
23+
Log this group has no name
24+
END
25+
26+
Test With Vars In GROUP Name
27+
GROUP Test is named: ${TEST_NAME}
28+
Log ${TEST_NAME}
29+
END
30+
GROUP ${42}
31+
Log Should be 42
32+
END
33+
34+
35+
*** Keywords ***
36+
Keyword With A Group
37+
Log top level
38+
GROUP frist keyword GROUP
39+
Log low level
40+
Log another low level
41+
END
42+
GROUP second keyword GROUP
43+
Log yet another low level
44+
END
45+
Log this is the end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
*** Test Cases ***
2+
END missing
3+
GROUP This is not closed
4+
Log 123
5+
6+
Empty GROUP
7+
GROUP This is empty
8+
END
9+
Log Last Keyword
10+
11+
Multiple Parameters
12+
GROUP Log 123 321
13+
Fail this has too much param
14+
END
15+
Log Last Keyword
16+
17+
Non existing var in Name
18+
GROUP ${non_existing_var} in Name
19+
Fail this has invalid vars in name
20+
END
21+
Log Last Keyword
22+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
*** Test Cases ***
2+
Test with Nested Groups
3+
GROUP
4+
${var} Set Variable assignment
5+
GROUP This Is A Named Group
6+
Should Be Equal ${var} assignment
7+
END
8+
END
9+
10+
Group with other control structure
11+
IF True
12+
GROUP Hello
13+
VAR ${i} ${0}
14+
END
15+
GROUP With WHILE
16+
WHILE $i < 2
17+
GROUP Group1 Inside WHILE (${i})
18+
Log ${i}
19+
END
20+
GROUP Group2 Inside WHILE
21+
VAR ${i} ${i + 1}
22+
END
23+
END
24+
IF $i != 2 Fail Shall be logged but NOT RUN
25+
END
26+
END
27+
28+
Test With Not Executed Groups
29+
VAR ${var} value
30+
IF True
31+
GROUP GROUP in IF
32+
Should Be Equal ${var} value
33+
IF True
34+
Log IF in GROUP
35+
ELSE
36+
GROUP GROUP in ELSE
37+
Fail Shall be logged but NOT RUN
38+
END
39+
END
40+
END
41+
ELSE
42+
GROUP
43+
Fail Shall be logged but NOT RUN
44+
END
45+
END

atest/testdata/running/steps_after_failure.robot

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ IF after failure
4242
${x} = Fail This should not be run
4343
END
4444

45+
GROUP after failure
46+
[Documentation] FAIL This fails
47+
Fail This fails
48+
GROUP Group Name
49+
Fail This should not be run
50+
${x} = Fail This should not be run
51+
END
52+
4553
FOR after failure
4654
[Documentation] FAIL This fails
4755
Fail This fails
@@ -103,8 +111,10 @@ Nested control structure after failure
103111
IF True
104112
FOR ${y} IN RANGE ${x}
105113
Fail This should not be run
106-
Fail This should not be run
107-
Fail This should not be run
114+
GROUP This should not be run
115+
Fail This should not be run
116+
Fail This should not be run
117+
END
108118
END
109119
Fail This should not be run
110120
ELSE
@@ -159,6 +169,20 @@ Failure in ELSE branch
159169
END
160170
Fail This should not be run
161171

172+
Failure in GROUP
173+
[Documentation] FAIL This fails
174+
GROUP Group Name 0
175+
GROUP Group Name 0,0
176+
Fail This fails
177+
Fail This should not be run
178+
END
179+
Fail This should not be run
180+
GROUP Group Name 0,1
181+
Fail This should not be run
182+
END
183+
END
184+
Fail This should not be run
185+
162186
Failure in FOR iteration
163187
[Documentation] FAIL This fails
164188
FOR ${x} IN RANGE 100

0 commit comments

Comments
 (0)