【发布时间】:2016-10-26 19:38:49
【问题描述】:
我有一个python类MyClass写在文件MyClass.py中:
class MyClass(object):
def __init__(self):
self.myvar = list()
def setvar(self, val):
self.myvar = val
def mymethod(self):
return self.myvar
我在 Robot Framework 中导入如下:
Library MyClass WITH NAME my_component
我还有一个关键字,它调用传递给它的对象的方法:
testing component
[Arguments] ${cmp}
log to console ************* ${cmp}
${result} = ${cmp}.mymethod
我有多个从 MyClass 类实例化的对象,每个对象都有不同的属性。无论对象本身如何,我都想使用testing component 关键字获取它们的属性。
当我通过my_component 调用testing component 时:
Test Method Call
testing component my_component
我明白了:
No keyword with name '${cmp}.mymethod' found.
如果我在关键字testing component中这样称呼它:
${result} = call method ${cmp} mymethod
我明白了:
Object 'my_component' does not have method 'mymethod'.
我还尝试了call method my_component mymethod 进行测试,我又得到了Object 'my_component' does not have method 'mymethod'.。
但是当我使用${result} = my_component.mymethod 时,一切正常。
【问题讨论】:
-
MyClass.py是否定义了一个名为MyClass的类?还是MyClass.py是一个简单的有功能的模块? -
@BryanOakley 请查看我对问题的编辑
标签: python object robotframework method-call