繁体   English   中英

sikuli没有找到图像文件

[英]sikuli is not finding image files

使用sikulixapi 1.1.0在Java中试用Sikuli,但找不到我的图像文件。

      screen.click("images/Terminal.png");

Maven(阴影)将我的src / main / resources / images放到了JAR的顶级“ images”目录中。 但是运行uberjar找不到图像。

~/hello $ java -cp target/hello.jar hello.TestSikuli
 [error] Image: could not be loaded: file://Users.../hello/images/Terminal.png

它在当前目录(可能是项目目录)中查找,而不是在JAR中。 我在程序中打印出了imagePath,它是一个空数组。

如何获取(也许通过imagePath.add?)来搜索调用的JAR? 我以为它会默认出现在那儿。


我尝试过的另一件事:

URL u = this.getClass().getClassLoader().getResource("images/Terminal.png");
Region r = screen.find(u);

但这炸毁了。 如果我按此处所示传递URL,则会得到“无效参数”; 如果传递.toString,则会得到:

FindFailed: Region: doFind: Image not loadable:
jar:file:/Users/.../Sikulix/j/hello/target/hello-1.0-SNAPSHOT.jar!/images/Terminal.png

Sikluix中似乎没有流输入接口,因此也许无法完成。

这工作:

  ImagePath.add(TestSikuli.class.getCanonicalName() + "/images");

也可能有将图像加载到内存中的解决方法。 https://answers.launchpad.net/sikuli/+question/232217

导入该库

import org.sikuli.basics.ImageLocator;

并使用此功能找到图像目录路径

ImageLocator.setBundlePath("path to img directory");

并执行您的jar文件,请运行以下命令

  cd "your directory"

  java -jar hello.jar
Screen s1 = new Screen();
s.dragDrop("Drag elemtn location.png","Drag elemtn location.png");

您可以指定要拖动的元素路径位置,并与放置相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM