Robot FrameWork ::如何计算参数?

时间:2018-01-15 13:57:01

标签: python robotframework

有没有办法动态计算已将多少个Arguments传递给关键字?是否有办法打印像Log $ {Argument1},$ {Argument2}?这样的参数。例如有10个复选框可供选择。但在TC QA中只选择他/她作为参数发送给关键字的几个项目。因此,我们希望捕获所有参数列表以创建List并迭代它们以选择正确的复选框

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 个答案:

答案 0 :(得分:2)

Robot通过让[Arguments]中的最后一项成为列表变量来支持可变数量的参数。

例如:

*** 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