我有一个MyClass写在文件中的python类MyClass.py:
class MyClass(object):
def __init__(self):
self.myvar = list()
def setvar(self, val):
self.myvar = val
def mymethod(self):
return self.myvar
Run Code Online (Sandbox Code Playgroud)
我在Robot Framework中导入如下:
Library MyClass WITH NAME my_component
Run Code Online (Sandbox Code Playgroud)
我还有一个关键字,它调用传递给它的对象方法:
testing component
[Arguments] ${cmp}
log to console ************* ${cmp}
${result} = ${cmp}.mymethod
Run Code Online (Sandbox Code Playgroud)
我有几个从类实例化的MyClass对象,每个对象都有不同的属性.testing component无论对象本身如何,我都希望使用关键字获取其属性.
当我打电话testing component传球my_component:
Test Method Call
testing component my_component
Run Code Online (Sandbox Code Playgroud)
我明白了:
No keyword with name '${cmp}.mymethod' found.
Run Code Online (Sandbox Code Playgroud)
如果我在关键字中这样调用它testing component:
${result} = call method ${cmp} mymethod
Run Code Online (Sandbox Code Playgroud)
我明白了:
Object 'my_component' …Run Code Online (Sandbox Code Playgroud)