Reputation: 3718
I'm using robot framework and I want to use a keyword that acepts a variable number of parameters
this is the common use of this keyworkd
keyWord to use var1 var2 var3
Now I want to use it from my own keyword because it will be common in my project, and I want to avoid repeat the loop in every file. This is what I tried
Get data from users var1 var2 var3
Get data from users
[Arguments] @{keys}
:FOR ${user} IN @{users}
\ keyWord to use ${keys}
[Return] ${userData}
But this is not working because ${keys} is a list.
Is it anyway to convert this list:
${keys} ['var1','var2','var3']
into this positional arguments:
var1 var2 var3
Upvotes: 1
Views: 1286
Reputation: 20077
Is it anyway to convert this list: ... into this positional arguments:
Yes, pass it as an argument, with the @
prefix - that will expand it, and every member will be an argument to the called keyword:
\ keyWord to use @{keys}
Upvotes: 5
Reputation: 1062
*** Test Cases ***
Keyword with args
Some Keyword a b c
*** Keywords ***
Some Keyword
[Arguments] @{args}
Another keyword with args @{args}
Another keyword with args
[Arguments] @{args}
: FOR ${arg} IN @{args}
\ Log To Console Another keyword prints: ${arg}
Outputs:
Another keyword prints: a
Another keyword prints: b
Another keyword prints: c
Upvotes: 2