【问题标题】:How to use karate.pause() in normal karate feature files? [duplicate]如何在普通的空手道功能文件中使用 karate.pause()? [复制]
【发布时间】:2021-10-12 11:27:29
【问题描述】:

我有一个场景,每 5 秒有条件地等待最多 1 分钟。我已经通过使用 java.lang.Thread.sleep() 进行轮询来实现它,这会阻塞线程并在我的多线程项目中失败。如何在我的普通空手道特征函数中使用类似 karate.pause() 的东西?注意:在我的情况下,我不能使用“重试直到”。

这是我使用 Thread.sleep() 进行轮询的方法,

* def checkForEventCompletion =
      """
      function(arg) {
          var poolTime = 5;
          var counter = 1;
          // should pool for every 5 seconds until it exceeds your input wait time
          while (true) {
              if( (counter*poolTime) > arg.maxWaitTime){
                  karate.log('Status Not yet Updated');
                  return EventStatus;
              }
          //Code to Fetch EventStatus
          karate.log('Current Status->',EventStatus);
              if (EventStatus == 'COMPLETED') {
                  karate.log('Status Verified, --Exiting--');
                  return true;
              }
              // pool every 5 seconds
              java.lang.Thread.sleep(poolTime*1000);
              counter++;
          }
      }

当我尝试使用 karate.pause() 时,它失败并显示“com.intuit.karate.core.ScenarioBridge@4acb7ecc 上的 invokeMember (pause) 失败,原因是:未知标识符:暂停”。

【问题讨论】:

    标签: multithreading sleep karate pause


    【解决方案1】:

    很可能是因为您使用的是旧版本的空手道,而pause() 仅在 1.1.0 中。

    而且我认为您混淆了很多东西,pause() 仅用于使用 Gatling 进行性能测试:https://github.com/intuit/karate/issues/1622

    如果您正在寻找测试异步流,请参考:https://twitter.com/KarateDSL/status/1417023536082812935

    上面的示例为您提供了一种“等待”或轮询某事的方法。另一种方法是:https://stackoverflow.com/a/55823180/143475

    否则 - 您的问题没有意义,因此请在完成此过程后提供更多信息:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

    您可以在此处找到某人这样做的示例:https://github.com/intuit/karate/issues/1681

    【讨论】:

      猜你喜欢
      • 2021-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      相关资源
      最近更新 更多