How to use User Keyword Arguments with default values in RobotFramework

不想你离开。 提交于 2019-12-03 15:13:25
Blue

Call the specific keyword only with which argument you wanted to pass. eg:

*** Test Cases ***
TEST
    MyKeyword   a=1    c=3

*** Keywords ***
MyKeywords
    [Arguments]   ${a}=0   ${b}=2   ${c}=3

Here, I am not passing argument 'b'. By default it will take b=2

An example from the Robot Framework User Guide:

*** Keywords ***
    Two Arguments With Defaults
    [Arguments]    ${arg1}=default 1    ${arg2}=${VARIABLE}
    [Documentation]    This keyword takes 0-2 arguments
    Log    1st argument ${arg1}
    Log    2nd argument ${arg2}

 *** Test Cases ***
Example
    Two Arguments With Defaults    arg2=new value

So Peter Bingham is right:

*** Test Cases ***
TEST
    MyKeyword   a=1    c=3

*** Keywords ***
MyKeywords
    [Arguments]   ${a}=0   ${b}=2   ${c}=3

You already used the default argument values in your example :

0a) 111 : 222 : 333 : 444 => That is only ${expected} set, all other args are defaults (and it's working).

0b) 111 : xxx : 333 : 444 | | xxx => This outputs no error, ${arg1} default value seems correctly used.

1) None : xxx : 333 : 444 | ${None} | xxx => The 'None' text is not the special value ${None}, you may have the ${expected} corrected with one of thoses : ${None}: xxx : 333 : 444 | ${None} | xxx or None : xxx : 333 : 444 |None| xxx.

2) None : xxx : 333 : 444 | ${null} | xxx => Same remark as above, concerning the difference between the text 'None' and the value ${null}, you may correct it with similar of above props.

3) 111 : 222 : xxx : 444 | | | xxx => Can't find why ${arg1} and ${arg2} are set to ${None} in the result : they should be valued, and this should output no error ; may have you changed this line to 111 : 222 : xxx : 444 | ${None} | ${None} | xxx specially for the output errors ?

There is no problem in your examples, you use default values appropriately. (I know that's a 3-yo thread, but I was looking for an "How-to" about defaulting values in RobotFramework, thus answering.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!