1

我正在用 Java 构建一个SikuliX自动化脚本,并且对该.close()方法的行为感到困惑。在Sikuli的App类里面,close方法如下:

  /**
   * tries to close the app defined by this App instance, waits max given seconds for the app to no longer be running
   *
   * @return this or null on failure
   */
  public boolean close(int waitTime) {
    if (!isRunning()) {
      log("App.close: not running: %s", this);
      return false;
    }
    if (_osUtil.close(this)) {
      int timeTowait = maxWait;
      if (waitTime > 0) {
        timeTowait = waitTime;
      }
      while (isRunning(0) && timeTowait > 0) {
        timeTowait--;
      }
    }
    if (!isValid()) {
      log("App.close: %s", this);
    } else {
      log("App.close: did not work: %s", this);
      return true;
    }
    return false;
  }

对我来说,有问题的部分是回报。我的理解是,由于它返回一个布尔值,因此如果关闭成功则为真,如果关闭失败则为假。但是,此代码的作用相反。基于我对这个逻辑有缺陷(?)的理解,我最初是这样编写代码的,

if (myApp.close()) {
    System.out.println("closed.");
    isAppClosed = true;
} else {
    System.out.println("NOT closed!");
    isAppClosed = false;
}

这与我想要的结果相反,因为应用程序成功关闭,但测试失败,因为正在打印“未关闭”。

我是否发现了一个错误,或者我错过了什么?

谢谢。

4

1 回答 1

1

原来这是一个错误。该项目的维护者已在 1.1.4 的最新版本中修复了该问题。 https://bugs.launchpad.net/sikuli/+bug/1811938

于 2019-01-16T16:18:42.373 回答