簡體   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