简体   繁体   English

sikuli没有找到图像文件

[英]sikuli is not finding image files

Trying out Sikuli in Java with sikulixapi 1.1.0, but it doesn't find my image files. 使用sikulixapi 1.1.0在Java中试用Sikuli,但找不到我的图像文件。

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

Maven (shade) put my src/main/resources/images into the JAR's toplevel "images" directory as expected. Maven(阴影)将我的src / main / resources / images放到了JAR的顶级“ images”目录中。 But running the uberjar doesn't find the image. 但是运行uberjar找不到图像。

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

It's looking in the current directory (happens to be the project directory), not in the JAR. 它在当前目录(可能是项目目录)中查找,而不是在JAR中。 I printed out the imagePath in the program, and it's an empty array. 我在程序中打印出了imagePath,它是一个空数组。

How do I get it (perhaps with imagePath.add?) to search the invoked JAR? 如何获取(也许通过imagePath.add?)来搜索调用的JAR? I had imagined it would look there by default. 我以为它会默认出现在那儿。


Another thing I tried: 我尝试过的另一件事:

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

But that blows up; 但这炸毁了。 if I pass a URL as shown here, I get "invalid parameter"; 如果我按此处所示传递URL,则会得到“无效参数”; if I pass the .toString, I get: 如果传递.toString,则会得到:

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

There doesn't seem to be a stream input interface in Sikluix, so maybe this just can't be done. Sikluix中似乎没有流输入接口,因此也许无法完成。

This worked: 这工作:

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

There may also be a workaround of loading the image into memory. 也可能有将图像加载到内存中的解决方法。 https://answers.launchpad.net/sikuli/+question/232217 https://answers.launchpad.net/sikuli/+question/232217

import this library 导入该库

import org.sikuli.basics.ImageLocator;

and use this function to locate your image directory path 并使用此功能找到图像目录路径

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

and to execute your jar file run the following commands 并执行您的jar文件,请运行以下命令

  cd "your directory"

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

You can give the element path location which you want to drag and same as drop. 您可以指定要拖动的元素路径位置,并与放置相同。

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

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