1
votes

Is there any way to dynamically Count how many Arguments has been passed to a keyword AND is there a way to print arguments like Log ${Argument1}, ${Argument2}?. for E.g. There are some 10 check boxes to select. but in TC QA selects only few items which he/she sends as argument to a keyword. So, We want to capture all the list of arguments to create a List and iterate through them to select the right check boxes

Add Arguments to List
    [Arguments]   arg1  arg2  arg3  arg4  arg5 
    ${NoOf_Arguments}  =   #TODO: no idea how to count no of arguments
    @{List_To_Create}=  Create List
    : For ${item}  IN RANGE ${NoOf_Arguments}
    \   append to list  ${List_To_Create} ${item}
    [Return]  ${List_To_Create}  
1
Pass all arguments as a list [Arguments] @{args} and then handle them as list items. You can count them, log the list etc. - Jan Kovařík
If you hard-code five arguments, you must pass five arguments or robot will throw an error. Are you asking how to support a variable number of arguments? - Bryan Oakley
@BryanOakley, In my e.g. its 5 .. but in real time it can be more then 1. i.e. like n variables .. so i wanted to know A. how find how many arguments passed. B. how to bring them all into List - bbk

1 Answers

4
votes

Robot supports a variable number of arguments by having the last item in [Arguments] be a list variable.

For example:

*** Keywords ***
A keyword
    [Arguments]  @{args}
    ${count}=  get length  ${args}
    log  you passed in ${count} arguments
    :FOR  ${arg}  IN  @{args}
    \  log  argument: ${arg}
    [return]  ${count}    

*** Test cases ***
Example
    ${result}=  A keyword  arg1  arg2  arg3
    should be equal as numbers  ${result}  3

    ${result}=  A keyword  arg1  arg2  arg3  arg4  arg5
    should be equal as numbers  ${result}  5