如何在关键字中为可选列表参数设置默认值

时间:2019-04-03 15:35:11

标签: robotframework optional-parameters optional-arguments

我以前曾使用列表作为参数,以可变/可选数量的关键字作为参数,并且效果很好:

Keyword Name
[Arguments]  ${otherVariable}  @{args}

....

我的问题是,如果用户遗漏了更多值,该如何设置默认值?

即像

Keyword Name
[Arguments]  ${otherVariable}  @{args}=['0']

....

1 个答案:

答案 0 :(得分:2)

检查为${args}为空,如果是-将其设置为默认值:

Keyword Name
    [Arguments]  ${otherVariable}  @{args}
    ${args}=    Run Keyword If    not $args    Create List    0
                             ...    ELSE       Set Variable   ${args}    # varags were passed, leave it as is

这类似于此python代码(RF是基于它的,因此很多方法/方法都相同/非常接近):

def keword(otherVariable, *args):
    if not args: args = [0]