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

问题描述 投票:1回答:1

我以前使用列表作为参数来获取关键字的变量/可选数量的参数,这完美地起作用:

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

....

我的问题是如果用户省略了更多值,我该如何为此设置默认值?

就像这样的东西

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

....
robotframework optional-parameters optional-arguments
1个回答
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]
© www.soinside.com 2019 - 2024. All rights reserved.