sikuli和Robotframework集成若干问题(一):TypeError: exists(): 2nd arg can't be coerced to double

很多同学在集成sikuli和Robotframework的时候,都参考了http://blog.mykhailo.com/2011/02/how-to-sikuli-and-robot-framework.html这篇经典文章。

其中关于包装sikuli的基本函数如下:

9 
10 # =============================================== #
11 #          SikuliWrapperOverwritten sikuli methods             #
12 # =============================================== #
13 
14 # function for calling native sikuli methods
15 def sikuli_method(name, *args, **kwargs):
16     return sys.modules['sikuli.Sikuli'].__dict__[name](*args, **kwargs)
17 
18 # overwritten Screen.exists method
19 def exists(target, timeout=None):
20     addFoundImage(getFilename(target))
21     return sikuli_method('exists', target, timeout)

然后使用如下的Robotframework的Test Case:

*Setting* *Value* *Value* *Value*
Library SikuliWrapper WITH NAME wrapper
Test Timeout 10 minutes
*Variable* *Value* *Value* *Value*
*Test Case* *Action* *Argument* *Argument*
Test Sikuli Exists c:\\a.jpg 5
*Keyword* *Action* *Argument* *Argument* *Argument*

在执行后报错:
TypeError: exists(): 2nd arg can't be coerced to double

经过很多次尝试后,我发现是由于Robotframework的Test Case中数字“5”其实是个String,在输入
exists函数的时候没有转型成为int或者double。解决方法,改变exists函数如下: 
18 # overwritten Screen.exists method
19 def exists(target, timeout=None):
20     addFoundImage(getFilename(target))
21     return sikuli_method('exists', target, int(timeout))


你可能感兴趣的:(framework)