【发布时间】:2014-05-06 19:54:43
【问题描述】:
我正在使用 Marathon 测试 Java Swing 应用程序。使用 Jython 的 Java Swing 应用程序测试工具。在这个问题的整个范围内,我只关心两个 python 文件。
调用文件.py:
testObject = getParentOfFooJPanel(get_component('...'))
print(testObject.getClass().getSimpleName()) #this is only here for testing
#if my code works, but this is
#where I get the errors
FileWithMethod.py
def getParentOfFooJPanel(startingComponent):
if (startingComponent.getClass().getSimpleName() == 'FooJPanel')
print(startingComponent.getClass().getSimpleName()) #prints what I would expect
print(startingComponent.getParent().getClass().getSimpleName()) #prints what I would expect
return(startingComponent.getParent())
else:
getParentOfFooJPanel(startingComponent.getParent())
每当我尝试在 FileWithMethod.py 中引用该对象时,它的行为都符合我的预期。但是,当我返回组件(Java 对象)并尝试在 CallingFile.py 中使用它(现在我调用以打印简单名称)时,它说“NoneType”对象没有属性“getClass”。 Jython 不能返回 Java 对象吗?如果没有,有什么解决办法吗?
【问题讨论】:
-
不确定,但您可能需要返回以递归调用 getParentOfFooJPanel。