【问题标题】:How to set default value for an optional list parameter in keyword如何为关键字中的可选列表参数设置默认值
【发布时间】:2019-08-25 05:03:04
【问题描述】:

我以前使用列表作为参数来为关键字接收可变/可选数量的参数,这非常有效:

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

....

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

即像

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

....

【问题讨论】:

    标签: robotframework optional-parameters optional-arguments


    【解决方案1】:

    检查 ${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]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-19
      • 2011-02-13
      • 1970-01-01
      • 2022-01-26
      • 2012-07-06
      • 2012-11-09
      • 1970-01-01
      相关资源
      最近更新 更多