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");
- }
- }
复制代码
执行日志: - [info] Windows utilities loaded.
- [info] Sikuli vision engine loaded.
- [log] DOUBLE CLICK on (185,450)
- [log] CLICK on (426,206)
- [log] TYPE "www.bing.com"
- [log] CLICK on (430,239)
- [log] CLICK on (685,370)
- [log] TYPE "sikuli"
- [log] 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
复制代码
|