【问题标题】:Sikuli screen.wait not workingSikuli screen.wait 不工作
【发布时间】:2018-04-07 06:43:43
【问题描述】:

我在 Java 中使用 sikuli,当前的 IDE 是 eclipse 氧气

这是我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Automation</groupId>
  <artifactId>SeleniumTest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>LATEST</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.sikulix</groupId>
      <artifactId>sikulixapi</artifactId>
      <version>1.1.0</version>
    </dependency>
  </dependencies>
</project>

我的代码是这样的

    @Test(description = "spin test")
    public void spinLongPeriod() throws Exception {
        int wait_time, last = 5000;

        caseReq.addAll(Arrays.asList(
                new Pattern("src/test/resources/spin.png"),
                new Pattern("src/test/resources/spin-stop.png"),
                new Pattern("src/test/resources/spin-disabled.png"),
                new Pattern("src/test/resources/good-luck.png"),
                new Pattern("src/test/resources/spin-auto.png")
                ));

        screen.wait(caseReq.get(0), 10);
        while (last >= 0) {
            screen.click(caseReq.get(0));
            screen.click(caseReq.get(1));
            wait_time = 60;
            screen.wait(caseReq.get(0), wait_time);
//          while (wait_time >= 0) {
//              Thread.sleep(1000);
//              wait_time -= 1000;
//              if (screen.exists(caseReq.get(0)) != null) {
//                  break;
//              }
//          }
            --last;
        }
    }

我放弃了一次 sikuli Screen.wait 方法,因为它失败了

通过使用“while + Thread.sleep”解决一段时间

但这次不是,错误信息出来了

FindFailed: can not find P(src/test/resources/spin-stop.png) S: 0.7 in S(0)[0,0 1920x1080]

我在网上找了很久的解决办法……

有什么建议吗?

【问题讨论】:

    标签: java eclipse sikuli


    【解决方案1】:

    我使用下一个方法

    private boolean exists(Pattern img, int sec) {
            try {
                window.wait(img, sec);
                return true;
            } catch (FindFailed exeption) {
                return false;
            }
    
        }
    

    而且效果很好。如果有些图片找不到,尝试通过.similar((float)0.5);进行调整

    【讨论】:

      猜你喜欢
      • 2015-05-28
      • 1970-01-01
      • 2017-10-15
      • 1970-01-01
      • 2015-10-09
      • 1970-01-01
      • 2017-02-18
      • 2020-12-01
      • 1970-01-01
      相关资源
      最近更新 更多