RF+Selenium2Library+Sikuli集成环境搭建

时间:2022-05-26 18:31:18

Sikuli是通过截图来编写代码的脚本语言,他是对于Selenium不好处理的一些模态窗口、flash等的利器。废话少说,直接开始安装吧。安装RF+Selenium2Library的环境这里就不说了,不会的看一下http://blog.csdn.net/xc5683/article/details/10017915这篇文档就好了。

1、安装Sikuli http://sikuli.org,去官网直接下载Sikuli-X-1.0rc3 (r905)-win32.exe安装就可以了。安装它之前需要先安装Java。

2、安装Jython环境:官网http://www.jython.org,下载jython-installer.jar。安装方法:java -jar jython-installer-2.5.3.jar

安装好之后,将c:\jython2.5.3\bin目录加入到path环境变量中。

3、配置rf远程调用sikuli环境:

a、新建一个文件夹c:\rf_sikuli

b、将sikuli安装目录下的C:\Program Files\Sikuli X\sikuli-script.jar拷贝到c:\rf_sikuli下

c、下载文件http://robotframework.googlecode.com/hg/tools/remoteserver/robotremoteserver.py到c:\rf_sikuli中

d、在c:\rf_sikuli下新建文件SikuliRemoteLibrary.py,文件内容如下:

import sys
from robotremoteserver import RobotRemoteServer
from org.sikuli.script import * class SikuliRemoteLibrary: def __init__(self):
self.SS = Screen()
self.PT = Pattern() def _wait(self, imgFile, timeOut, similarity):
try:
self.PT = Pattern(imgFile)
self.PT = self.PT.similar(float(similarity))
self.SS.wait(self.PT, float(timeOut))
except FindFailed, err:
print "ERR: _wait"
raise AssertionError(err) def click_object(self, imgFile, timeOut, similarity):
try:
self._wait(imgFile, timeOut, similarity)
self.SS.click(imgFile)
except FindFailed, err:
raise AssertionError("Cannot click [" + imgFile + "]") def object_exists(self, imgFile, similarity, timeOut):
try:
self._wait(imgFile, timeOut, similarity)
except FindFailed, err:
raise AssertionError("Could not find [" + imgFile + "]") def type_at_object(self, imgFile, txt, timeOut, similarity):
try:
self._wait(imgFile, timeOut, similarity)
self.SS.type(imgFile, txt)
except FindFailed, err:
raise AssertionError("Cannot type at [" + imgFile + "]") def paste_at_object(self, imgFile, txt, timeOut, similarity):
try:
self._wait(imgFile, timeOut, similarity)
self.SS.paste(imgFile, txt)
except FindFailed, err:
raise AssertionError("Cannot paste at [" + imgFile + "]") if __name__ == '__main__':
SRL = SikuliRemoteLibrary()
RobotRemoteServer(SRL, *sys.argv[1:])

e、将c:\rf_sikuli目录添加到CLASS_PATH环境变量下

f、打开cmd,到c:\rf_sikuli目录下,执行jython.bat SikuliRemoteLibrary.py

如果出现:Robot Framework remote server starting at localhost:8270,说明配置成功,可以使用了

如果出现:no named module sikuli的错误,请将sikuli-script.jar解压一下就可以了(注意解压选择解压到当前文件夹就可以)

4、RIDE中使用sikuli

a、在RIDE中新建一个测试用例

b、需要加入Remote和Screenshot库

RF+Selenium2Library+Sikuli集成环境搭建

c、在用例中直接写用例就可以了

RF+Selenium2Library+Sikuli集成环境搭建