如何在robotframework

时间:2017-12-14 15:21:23

标签: robotframework

我在Python和Linux上使用Robot框架。

我不知道如何在装饰器中使用可选的命名参数bc。有人可以解释一下吗?

见下面的例子:

@keyword('Starting a "${a}" b "${b}"?? c "${c}"??')
def Start(self, a, b='', c=''):
   foo

1 个答案:

答案 0 :(得分:1)

我理解你的问题的方式是,你试图创建一个带有嵌入参数的关键字,这个参数有默认的参数 - 这是不允许的,doc link, the last paragraph in Basic Syntax

你可以做的是让调用者传递“默认”值; e.g:

@keyword('Starting a "${a}" b "${b}" c "${c}"')
def Start(self, a, b, c):
   # just work with a, b, c, they *always* have _some_ value when called from RF
   foo
# later on, used in Robotframework code:
Starting a "" b "" c ""

当像这样调用^时,变量abc将作为空字符串传递给python函数 - RF默认参数为字符串类型,这意味着此代码内部在这种情况下,该函数将起作用:

assert a == ''  # will pass when called with no value for a
assert type(b) == str  # this will always work, regardless did b (or a, or c) have a value set in the call, or not