【问题标题】:How do I skip some optional arguments in Robot Framework?如何跳过 Robot Framework 中的一些可选参数?
【发布时间】:2020-12-24 17:20:27
【问题描述】:

我打算跳过 ${num2}${num4} 参数。 但我收到一条错误消息:

命名参数后不能使用位置参数

我不知道为什么它认为列表是一个位置参数,它不应该是一个变量吗?

*** Test Cases ***  
Test  
    @{daysOff}=    Create List    Tuesday    Friday  
    Keyword    30    num3=6    @{daysOff}  
  
*** Keywords ***  
Keyword  
    [Arguments]    ${num1}    ${num2}=5    ${num3}=10    ${num4}=15    @{list}  
    Log    ${num1}  
    Log    ${num2}  
    Log    ${num3}  
    Log    ${num4}  
    FOR    ${item}    IN   @{list}
        Log    ${item}
    END

【问题讨论】:

  • 请点击答案旁边的空心勾号,接受适合您的答案。这是感谢花费宝贵时间回答您问题的人的方式。它还可以帮助和引导社区成员找到有效的答案。

标签: testing automated-tests robotframework


【解决方案1】:

解决问题

命名参数后不能使用位置参数

错误,您应该将列表参数移动到命名的位置参数之前。 请注意,您不能在 ${num1} 之前移动它,因为这会产生另一个错误:

关键字“关键字”缺少仅命名参数“num1”。

总而言之:

*** Test Cases ***  
Test  
    @{daysOff}=    Create List    Tuesday    Friday  
    Keyword    30    @{daysOff}    num3=6
  
*** Keywords ***  
Keyword
    [Arguments]    ${num1}    @{list}    ${num2}=5    ${num3}=10    ${num4}=15    
    Log    ${num1}  
    Log    ${num2}  
    Log    ${num3}  
    Log    ${num4}  
    FOR    ${item}    IN   @{list}
        Log    ${item}
    END

【讨论】:

  • Robot Framework 使用三种类型的参数:Positional、Default 和 Variable。我希望列表是可变的。
  • @user2420374 我已更新我的答案以使其与您更新的问题保持一致。
猜你喜欢
  • 2011-06-05
  • 2016-01-28
  • 1970-01-01
  • 2018-01-30
  • 2021-07-17
  • 1970-01-01
  • 2021-11-09
  • 2013-10-02
  • 2010-11-07
相关资源
最近更新 更多