RaiMan / SikuliX-2014

SikuliX version 1.1.2 (until February 2018)
http://sikulix.com
805 stars 235 forks source link

How to set ImagePath in a spring boot application JAR package ? #277

Open frankiezdh opened 6 years ago

frankiezdh commented 6 years ago

I wrote a spring boot application. The application is compiled and packaged into a jar. I unzip the jar, get the file structure like below.

├── META-INF
│   └── MANIFEST.MF
├── org
│   └── springframework
│       └── boot
│           └── loader
└── WEB-INF
    ├── classes
    │   ├── banner.txt
    │   ├── com
    │   │   └── xxxx
    │   │       ├── service
    │   │       │   ├── sikulix2
    │   │       │   │   └── **WechatService.class**
    │   ├── images
    │   │   ├── **1.png**
    │   │   └── **2.png**
    │   ├── logback-spring.xml
    │   ├── META-INF
    │   │   └── build-info.properties
    │   └── templates
    │       └── error.html
    └── lib

I use sikulixapi (java code below) in WechatService.class

        Screen s = new Screen();
        ImagePath.add("com.xxxx.service.sikulix2.WechatService/images");
        try {
            log.info("{}", ImagePath.get());
            log.info("{}", ImagePath.getBundlePath());
            s.click("1.png");
        } catch (FindFailed e) {
            e.printStackTrace();
        }

but i get an error while running. I read the doc faq/030-java-dev and where-sikulix-looks-for-image-files, but no help.

[error] ImagePath: add: not valid: com.xxxx.service.sikulix2.WechatService/images
2017-08-14 10:24:30.704  INFO 9140 --- [pool-2-thread-1] com.xxxx.service.sikulix2.WechatService   : {}
2017-08-14 10:24:30.708  INFO 9140 --- [pool-2-thread-1] com.xxxx.service.sikulix2.WechatService   : D:\xxxx\xxxx\xxxx
[error] Image: Image not valid, but TextSearch is switched off!
[error] RunTimeAPI: Wait: Abort: unknown
[error] RunTimeAPI: ImageMissing: 1.png

by the way sikulix version 1.1.2-snapshot

frankiezdh commented 6 years ago

I find a solution.

        Screen s = new Screen();
        try {
            ImagePath.add(new ClassPathResource("images").getURL());
            s.click("1.png");
        } catch (Exception e) {
            e.printStackTrace();
        }
RaiMan commented 6 years ago

Apparently, the class-reference-imagePath does not work in a spring application.

ImagePath.add(new ClassPathResource("images").getURL());

Is ClassPathResource Spring specific or Java standard?

frankiezdh commented 6 years ago

@RaiMan I think iClassPathResource is specificed by Spring.