Skip to content

Commit 8301773

Browse files
committed
Pass embedded args as objects to Run Keyword and its variants.
Earlier variables were replaced in keyword names before keywords were called. This meant that keywords using embedded arguments only go string representations of objects, not objects themselves. The biggest change that the `name` argument passed to `BuiltIn.run_keyword` isn't anymore resolved before calling the keyword. Instead the keyword resolves it itself after first checking does it match some keyword accepting embedded arguments. If it does, `name` is not resolved and variables will be handled later by appropriate runners. The above change ought to be backwards compatible when using `Run Keyword` in data, but if `BuiltIn.run_keyword` is used by a library keyword handling of the `name` argument changes. This only affects situations where the name contains variables or escapes so it shouldn't cause problems in normal usage. Not resolving `name` caused various bigger and smaller changes elsewhere. For example, how run keyword variants were handled in dry run was affected and that logic needed to be changed. The bad and deprecated RUN_KW_REGISTER was enhanced to help with that and its documentation was enhanced at the same time. Fixes #1595.
1 parent f75c5b2 commit 8301773

17 files changed

+429
-167
lines changed

atest/robot/keywords/trace_log_keyword_arguments.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Object With Unicode Repr as Argument
6868

6969
Arguments With Run Keyword
7070
${tc}= Check Test Case ${TEST NAME}
71-
Check Log Message ${tc.kws[1].msgs[0]} Arguments: [ 'Catenate' | '\@{VALUES}' ] TRACE
71+
Check Log Message ${tc.kws[1].msgs[0]} Arguments: [ '\${keyword name}' | '\@{VALUES}' ] TRACE
7272
Check Log Message ${tc.kws[1].kws[0].msgs[0]} Arguments: [ 'a' | 'b' | 'c' | 'd' ] TRACE
7373

7474
Embedded Arguments

atest/robot/standard_libraries/builtin/repeat_keyword.robot

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ Times With 'x' Postfix
2323

2424
Zero And Negative Times
2525
${tc} = Check Test Case ${TEST NAME}
26-
Check Repeated Messages ${tc.kws[0]} 0
27-
Check Repeated Messages ${tc.kws[2]} 0
28-
Check Repeated Messages ${tc.kws[3]} 0
26+
Check Repeated Messages ${tc.kws[0]} 0 name=This is not executed
27+
Check Repeated Messages ${tc.kws[2]} 0 name=\${name}
28+
Check Repeated Messages ${tc.kws[3]} 0 name=This is not executed
2929

3030
Invalid Times
3131
Check Test Case Invalid Times 1
@@ -72,14 +72,17 @@ Repeat Keyword With Pass Execution After Continuable Failure
7272

7373
*** Keywords ***
7474
Check Repeated Messages
75-
[Arguments] ${kw} ${count} ${msg}=${None}
75+
[Arguments] ${kw} ${count} ${msg}= ${name}=
7676
Should Be Equal As Integers ${kw.kw_count} ${count}
7777
FOR ${i} IN RANGE ${count}
7878
Check Log Message ${kw.msgs[${i}]} Repeating keyword, round ${i+1}/${count}.
7979
Check Log Message ${kw.kws[${i}].msgs[0]} ${msg}
8080
END
81-
Run Keyword If ${count} == 0 Check Log Message ${kw.msgs[0]} Keyword 'This is not executed' repeated zero times.
82-
Run Keyword If ${count} != 0 Should Be Equal As Integers ${kw.msg_count} ${count}
81+
IF ${count} != 0
82+
Should Be Equal As Integers ${kw.msg_count} ${count}
83+
ELSE
84+
Check Log Message ${kw.msgs[0]} Keyword '${name}' repeated zero times.
85+
END
8386

8487
Check Repeated Messages With Time
8588
[Arguments] ${kw} ${msg}=${None}

atest/robot/standard_libraries/builtin/run_keyword.robot

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ Run Keyword With UK
3636
Run Keyword In Multiple Levels And With UK
3737
Check test Case ${TEST NAME}
3838

39+
With keyword accepting embedded arguments
40+
${tc} = Check test Case ${TEST NAME}
41+
Check Run Keyword With Embedded Args ${tc.kws[0]} Embedded "arg" arg
42+
43+
With library keyword accepting embedded arguments
44+
${tc} = Check test Case ${TEST NAME}
45+
Check Run Keyword With Embedded Args ${tc.kws[0]} Embedded "arg" in library arg
46+
47+
With keyword accepting embedded arguments as variables
48+
${tc} = Check test Case ${TEST NAME}
49+
Check Run Keyword With Embedded Args ${tc.kws[0]} Embedded "\${VARIABLE}" value
50+
Check Run Keyword With Embedded Args ${tc.kws[1]} Embedded "\${1}" 1
51+
52+
With library keyword accepting embedded arguments as variables
53+
${tc} = Check test Case ${TEST NAME}
54+
Check Run Keyword With Embedded Args ${tc.kws[0]} Embedded "\${VARIABLE}" in library value
55+
Check Run Keyword With Embedded Args ${tc.kws[1]} Embedded "\${1}" in library 1
56+
57+
With keyword accepting embedded arguments as variables containing objects
58+
${tc} = Check test Case ${TEST NAME}
59+
Check Run Keyword With Embedded Args ${tc.kws[0]} Embedded "\${OBJECT}" Robot
60+
Check Run Keyword With Embedded Args ${tc.kws[1]} Embedded object "\${OBJECT}" Robot
61+
62+
With library keyword accepting embedded arguments as variables containing objects
63+
${tc} = Check test Case ${TEST NAME}
64+
Check Run Keyword With Embedded Args ${tc.kws[0]} Embedded "\${OBJECT}" in library Robot
65+
Check Run Keyword With Embedded Args ${tc.kws[1]} Embedded object "\${OBJECT}" in library Robot
66+
3967
Run Keyword In For Loop
4068
${tc} = Check test Case ${TEST NAME}
4169
Check Run Keyword ${tc.kws[0].kws[0].kws[0]} BuiltIn.Log hello from for loop
@@ -81,3 +109,15 @@ Check Run Keyword In Uk
81109
Should Be Equal ${kw.name} BuiltIn.Run Keyword
82110
Should Be Equal ${kw.kws[0].name} My UK
83111
Check Run Keyword ${kw.kws[0].kws[0]} ${subkw_name} @{msgs}
112+
113+
Check Run Keyword With Embedded Args
114+
[Arguments] ${kw} ${subkw_name} ${msg}
115+
Should Be Equal ${kw.name} BuiltIn.Run Keyword
116+
IF ${subkw_name.endswith('library')}
117+
Should Be Equal ${kw.kws[0].name} embedded_args.${subkw_name}
118+
Check Log Message ${kw.kws[0].msgs[0]} ${msg}
119+
ELSE
120+
Should Be Equal ${kw.kws[0].name} ${subkw_name}
121+
Should Be Equal ${kw.kws[0].kws[0].name} BuiltIn.Log
122+
Check Log Message ${kw.kws[0].kws[0].msgs[0]} ${msg}
123+
END

atest/robot/standard_libraries/builtin/run_keyword_variants_variable_handling.robot

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@ Resource atest_resource.robot
55
*** Test Case ***
66
Variable Values Should Not Be Visible As Keyword's Arguments
77
${tc} = Check Test Case ${TEST NAME}
8-
Check Keyword Data ${tc.kws[0]} BuiltIn.Run Keyword args=My UK, Log, \${OBJECT}
9-
Check Keyword Data ${tc.kws[0].kws[0]} My UK args=Log, \${OBJECT}
10-
Check Keyword Data ${tc.kws[0].kws[0].kws[0]} BuiltIn.Run Keyword args=\${name}, \@{args}
11-
Check Keyword Data ${tc.kws[0].kws[0].kws[0].kws[0]} BuiltIn.Log args=\@{args}
8+
Check Keyword Data ${tc.kws[0]} BuiltIn.Run Keyword args=My UK, Log, \${OBJECT}
9+
Check Keyword Data ${tc.kws[0].kws[0]} My UK args=Log, \${OBJECT}
10+
Check Keyword Data ${tc.kws[0].kws[0].kws[0]} BuiltIn.Run Keyword args=\${name}, \@{args}
11+
Check Keyword Data ${tc.kws[0].kws[0].kws[0].kws[0]} BuiltIn.Log args=\@{args}
12+
Check Log Message ${tc.kws[0].kws[0].kws[0].kws[0].msgs[0]} Robot
13+
Check Keyword Data ${tc.kws[0].kws[0].kws[1].kws[0]} BuiltIn.Log args=\${args}[0]
14+
Check Log Message ${tc.kws[0].kws[0].kws[1].kws[0].msgs[0]} Robot
1215

1316
Run Keyword When Keyword and Arguments Are in List Variable
1417
${tc} = Check Test Case ${TEST NAME}
1518
Check Keyword Data ${tc.kws[0].kws[0]} \\Log Many args=c:\\\\temp\\\\foo, \\\${notvar}
1619
Check Keyword Data ${tc.kws[1].kws[0]} \\Log Many args=\\\${notvar}
1720

21+
Run Keyword With Empty List Variable
22+
Check Test Case ${TEST NAME}
23+
24+
Run Keyword With Multiple Empty List Variables
25+
Check Test Case ${TEST NAME}
26+
1827
Run Keyword If When Arguments are In Multiple List
1928
${tc} = Check Test Case ${TEST NAME}
2029
Check Keyword Arguments And Messages ${tc}

atest/robot/standard_libraries/builtin/run_keywords.robot

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
*** Settings ***
2+
Documentation Testing Run Keywords when used without AND. Tests with AND are in
3+
... run_keywords_with_arguments.robot.
24
Suite Setup Run Tests ${EMPTY} standard_libraries/builtin/run_keywords.robot
35
Resource atest_resource.robot
46

@@ -12,6 +14,26 @@ Failing keyword
1214
Test Should Have Correct Keywords
1315
... Passing Failing
1416

17+
Embedded arguments
18+
${tc} = Test Should Have Correct Keywords
19+
... Embedded "arg" Embedded "\${1}" Embedded object "\${OBJECT}"
20+
Check Log Message ${tc.kws[0].kws[0].kws[0].msgs[0]} arg
21+
Check Log Message ${tc.kws[0].kws[1].kws[0].msgs[0]} 1
22+
Check Log Message ${tc.kws[0].kws[2].kws[0].msgs[0]} Robot
23+
24+
Embedded arguments with library keywords
25+
${tc} = Test Should Have Correct Keywords
26+
... embedded_args.Embedded "arg" in library
27+
... embedded_args.Embedded "\${1}" in library
28+
... embedded_args.Embedded object "\${OBJECT}" in library
29+
Check Log Message ${tc.kws[0].kws[0].msgs[0]} arg
30+
Check Log Message ${tc.kws[0].kws[1].msgs[0]} 1
31+
Check Log Message ${tc.kws[0].kws[2].msgs[0]} Robot
32+
33+
Keywords names needing escaping
34+
Test Should Have Correct Keywords
35+
... Needs \\escaping \\\${notvar}
36+
1537
Continuable failures
1638
Test Should Have Correct Keywords
1739
... Continuable failure Multiple continuables Failing
@@ -21,9 +43,14 @@ Keywords as variables
2143
... BuiltIn.No Operation Passing BuiltIn.No Operation
2244
... Passing BuiltIn.Log Variables Failing
2345

46+
Keywords names needing escaping as variable
47+
Test Should Have Correct Keywords
48+
... Needs \\escaping \\\${notvar} Needs \\escaping \\\${notvar}
49+
... kw_index=1
50+
2451
Non-existing variable as keyword name
25-
${tc} = Check Test Case ${TESTNAME}
26-
Should Be Empty ${tc.kws[0].kws}
52+
Test Should Have Correct Keywords
53+
... Passing
2754

2855
Non-existing variable inside executed keyword
2956
Test Should Have Correct Keywords
@@ -43,10 +70,7 @@ In test setup
4370
In test teardown
4471
Check Test Case ${TESTNAME}
4572

46-
In test teardown with non-existing variable in keyword name (with AND)
47-
Check Test Case ${TESTNAME}
48-
49-
In test teardown with non-existing variable in keyword name (without AND)
73+
In test teardown with non-existing variable in keyword name
5074
Check Test Case ${TESTNAME}
5175

5276
In test teardown with ExecutionPassed exception

atest/robot/standard_libraries/builtin/run_keywords_with_arguments.robot

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
*** Settings ***
2+
Documentation Testing Run Keywords when used with AND. Tests without AND are in
3+
... run_keywords.robot.
24
Suite Setup Run Tests ${EMPTY} standard_libraries/builtin/run_keywords_with_arguments.robot
35
Resource atest_resource.robot
46

@@ -54,3 +56,15 @@ Consecutive AND's
5456

5557
AND as first argument should raise an error
5658
Check Test Case ${TESTNAME}
59+
60+
Keywords names needing escaping
61+
Test Should Have Correct Keywords
62+
... Needs \\escaping \\\${notvar} Needs \\escaping \\\${notvar}
63+
64+
Keywords names needing escaping as variable
65+
Test Should Have Correct Keywords
66+
... Needs \\escaping \\\${notvar} Needs \\escaping \\\${notvar}
67+
... kw_index=1
68+
69+
In test teardown with non-existing variable in keyword name
70+
Check Test Case ${TESTNAME}

atest/testdata/standard_libraries/builtin/RegisteringLibrary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ def run_keyword_function(name, *args):
88
register_run_keyword(__name__, 'run_keyword_function', 1)
99

1010
def run_keyword_without_keyword(*args):
11-
return BuiltIn().run_keyword('\Log Many', *args)
11+
return BuiltIn().run_keyword(r'\\Log Many', *args)
1212

1313
register_run_keyword(__name__, 'run_keyword_without_keyword', 0)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from robot.api.deco import keyword
2+
3+
4+
@keyword('Embedded "${argument}" in library')
5+
def embedded(arg):
6+
print(arg)
7+
8+
9+
@keyword('Embedded object "${obj}" in library')
10+
def embedded_object(obj):
11+
print(obj)
12+
if obj.name != 'Robot':
13+
raise AssertionError(f"'{obj.name}' != 'Robot'")

atest/testdata/standard_libraries/builtin/run_keyword.robot

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
*** Settings ***
22
Library OperatingSystem
3+
Library embedded_args.py
4+
Variables variable.py
35

46
*** Variables ***
57
@{NEEDS ESCAPING} c:\\temp\\foo \${notvar} ${42}
68
${FAIL KW} Fail
9+
${VARIABLE} value
710

811
*** Test Cases ***
912
Run Keyword
@@ -48,6 +51,28 @@ Run Keyword In Multiple Levels And With UK
4851
Run Keyword Run Keyword Run Keyword My UK Run Keyword
4952
... My UK My UK My UK Run Keyword Fail Expected Failure
5053

54+
With keyword accepting embedded arguments
55+
Run Keyword Embedded "arg"
56+
57+
With library keyword accepting embedded arguments
58+
Run Keyword Embedded "arg" in library
59+
60+
With keyword accepting embedded arguments as variables
61+
Run Keyword Embedded "${VARIABLE}"
62+
Run Keyword Embedded "${1}"
63+
64+
With library keyword accepting embedded arguments as variables
65+
Run Keyword Embedded "${VARIABLE}" in library
66+
Run Keyword Embedded "${1}" in library
67+
68+
With keyword accepting embedded arguments as variables containing objects
69+
Run Keyword Embedded "${OBJECT}"
70+
Run Keyword Embedded object "${OBJECT}"
71+
72+
With library keyword accepting embedded arguments as variables containing objects
73+
Run Keyword Embedded "${OBJECT}" in library
74+
Run Keyword Embedded object "${OBJECT}" in library
75+
5176
Run Keyword In For Loop
5277
[Documentation] FAIL Expected failure in For Loop
5378
FOR ${kw} ${arg1} ${arg2} IN
@@ -99,3 +124,10 @@ Timeoutted UK Passing
99124
Timeoutted UK Timeouting
100125
[Timeout] 300 milliseconds
101126
Sleep 1 second
127+
128+
Embedded "${arg}"
129+
Log ${arg}
130+
131+
Embedded object "${obj}"
132+
Log ${obj}
133+
Should Be Equal ${obj.name} Robot

atest/testdata/standard_libraries/builtin/run_keyword_variants_variable_handling.robot

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Variables variable.py
66
@{NEEDS ESCAPING} c:\\temp\\foo \${notvar}
77
@{KEYWORD AND ARG WHICH NEEDS ESCAPING} \\Log Many \${notvar}
88
@{KEYWORD AND ARGS WHICH NEEDS ESCAPING} \\Log Many @{NEEDS ESCAPING}
9-
@{EMPTY}
109
@{EXPRESSION} ${TRUE}
1110
@{ARGS} @{NEEDS ESCAPING}
1211
${KEYWORD} \\Log Many
@@ -20,6 +19,16 @@ Run Keyword When Keyword and Arguments Are in List Variable
2019
Run Keyword @{KEYWORD AND ARGS WHICH NEEDS ESCAPING}
2120
Run Keyword @{KEYWORD AND ARG WHICH NEEDS ESCAPING}
2221

22+
Run Keyword With Empty List Variable
23+
[Documentation] FAIL
24+
... Keyword name missing: Given arguments ['\@{EMPTY}'] resolved to an empty list.
25+
Run Keyword @{EMPTY}
26+
27+
Run Keyword With Multiple Empty List Variables
28+
[Documentation] FAIL
29+
... Keyword name missing: Given arguments ['\@{EMPTY}', '\@{{{}}}', '\@{EMPTY}'] resolved to an empty list.
30+
Run Keyword @{EMPTY} @{{{}}} @{EMPTY}
31+
2332
Run Keyword If When Arguments are In Multiple List
2433
Run Keyword If @{EXPRESSION} @{KEYWORD LIST} @{ARGS}
2534

@@ -50,6 +59,8 @@ Run Keyword If With List And One Argument That needs to Be Processed
5059
My UK
5160
[Arguments] ${name} @{args}
5261
Run Keyword ${name} @{args}
62+
Run Keyword ${name} ${args}[0]
63+
Should Be Equal ${args[0].name} Robot
5364

5465
\Log Many
5566
[Arguments] @{args}

0 commit comments

Comments
 (0)