如何在 RobotFramework 中使用具有默认值的用户关键字参数 [英] How to use User Keyword Arguments with default values in RobotFramework

查看:33
本文介绍了如何在 RobotFramework 中使用具有默认值的用户关键字参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释我如何使用与数据驱动测试用例相关的可选关键字参数的默认值吗?

Can someone explain me how to use default values for optional keyword arguments in connection with data-driven testcases?

正如您在我的示例中看到的,在某些情况下并非所有默认值都使用:

As you can see in my example not all default values are used in some cases:

*** Test Cases ***
| testArgs | [Template] | doSomething
| | 111 : 222 : 333 : 444
| | xxx : 222 : 333 : 444 | xxx
| | 111 : xxx : 333 : 444 | | xxx
| | 111 : xxx : 333 : 444 | ${EMPTY} | xxx
| | None : xxx : 333 : 444 | ${None} | xxx
| | None : xxx : 333 : 444 | ${null} | xxx
| | 111 : 222 : xxx : 444  | | | xxx

*** Keywords ***
| doSomething
| | [Arguments] | ${expected} | ${arg1}=111 | ${arg2}=222 | ${arg3}=333 | ${arg4}=444
| | Log | exp: ${expected}
| | ${rc} | Set Variable | ${arg1} : ${arg2} : ${arg3} : ${arg4}
| | Log | arg: ${rc}
| | Run Keyword If  | '${rc}' == '${expected}'  
| | ... | Log | === equal ===
| | ... | ELSE  
| | ... | Log | !!! diff !!!
| | Log | **************************
| | Should be equal | ${rc} | ${expected}

结果:

testArgs                                                              | FAIL |
Several failures occurred:
1)  : xxx : 333 : 444 != 111 : xxx : 333 : 444
2)  : xxx : 333 : 444 != 111 : xxx : 333 : 444
3)  :  : xxx : 444 != 111 : 222 : xxx : 444

我知道我可以使用命名参数来设置特定的关键字参数.但这仅在关键字驱动的测试用例中才有可能.

I know that I can use named arguments to set specific keyword arguments. But this is only possible in keyword-driven testcases.

问候,汤姆

推荐答案

仅使用您想传递的参数调用特定关键字.例如:

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

在这里,我没有传递参数b".默认情况下,它将采用 b=2

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

这篇关于如何在 RobotFramework 中使用具有默认值的用户关键字参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆