Java语言与sikuli配合
sikuli IDE可以完成常见的单击、右击、移动到、拖动等鼠标操作,java引用sikuli-script.jar同样可以执行这些常见的鼠标操作,因此即可方便的编写java实现识别图片并模拟点击/拖动目标控件。将sikuli-script.jar包添加到eclipse中。然后编写自动化测试脚本:package com.mypro.sikuli;
import org.sikuli.script.*;
public class STest {
public static void main(String[] args) throws FindFailed, InterruptedException {
Screen s = new Screen();
//定义图片存放路径
String imgpath = "D:/java/sikuli/img/";
//双击桌面chrome浏览器图标
s.doubleClick(imgpath+"chrome.png");
//输入url
s.type(imgpath+"url.png","www.bing.com");
s.click(imgpath+"lianxiang.png");
Thread.sleep(2000);
//在bing输入框输入搜索关键字:sikuli,并点击搜索按钮
s.type(imgpath+"sreach_input.jpg","sikuli");
s.click(imgpath+"sreach_button.png");
System.out.println("end");
}
}
执行日志: Windows utilities loaded.
Sikuli vision engine loaded.
DOUBLE CLICK on (185,450)
CLICK on (426,206)
TYPE "www.bing.com"
CLICK on (430,239)
CLICK on (685,370)
TYPE "sikuli"
CLICK on (938,371)
end
如果在执行脚本的时候出现以下错误: Getting the VisionProxy.dll: Can not find dependent libraries...把Sikuli X 的libs目录添加到系统环境变量path下:path:
;D:\Program Files (x86)\Sikuli X\libs
支持分享
页:
[1]