空手道如何仅在失败的情况下自动重新运行 [英] karate-how to rerun automatically only failed scenarios

查看:83
本文介绍了空手道如何仅在失败的情况下自动重新运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

空手道有没有办法以相同的执行方式自动重新运行UI测试自动化(甚至在API中)失败的方案.我正在使用gradle作为构建工具. 这是我的要求,如果任何测试失败,则应再次重试.

Is there any way in karate to re-run only failed scenarios for UI test automation (or even in API as well) automatically, in same execution. I am using gradle as a build tool. This is the requirement at my side if any test get failed it should retry once again.

如果在每种功能场景之后我们都可以跳过stop(),那么也是任何方法.并且只能在功能之后调用.这样单个驱动程序实例将适用于在一个功能文件中编写的所有方案.

Also is the any way if we can skip stop() after every scenario of feature. and it could be called only after feature. so that single driver instance will work for all scenarios written in one feature file.

请提出建议.

推荐答案

当前不支持此功能.它可能存在于下一版本中,但不能保证.有些人认为重试是不好的测试习惯,请仔细检查.

This is not supported currently. It may be there in the next version but no guarantees. Some people consider re-tries to be bad testing practice, look it up.

但是这是一个可能的解决方法.如果您可以将不稳定的流程"移至某个功能(应该已经存在)中,则可以通过包装功能"和一个JS函数进行调用.可以对其进行增强,以轻松地为该功能调用参数以及重试次数.在这里,我们利用了JS try-catch块.

But here is a possible workaround. If you can move your "flaky flow" into a feature (which should be the case already) you can call it via a "wrapper feature" and a JS function. Which can be enhanced to easily take arguments for the feature to call and number of re-tries. Here we make use of JS try-catch blocks.

* def fun =
"""
function() {
  for (var i = 0; i < 3; i++) {
    try {
      karate.call('flaky.feature');
      karate.log('*** call success !')
      return;
    } catch (e) {
      karate.log('try failed:', i, e);
    }
  }
  karate.fail('test failed after retries: ' + i); // karate.fail('message') is only in 0.9.6 onwards, you can also [throw 'message']
}
"""
* fun()

除非它是called功能,否则我们将不支持在多个Scenario -s中重用驱动程序.请在此处查看评论: calling在karate-config.js中登录的单选不能用于空手道UI测试

We will not support re-using a driver across multiple Scenario-s unless it is a called feature. See the comments here: callSingle for login in karate-config.js does not work as expected for Karate UI tests

请记住,空手道是开源的.如果这些代码对您来说具有很高的优先级,请考虑提供代码.

Remember, Karate is open-source. Please consider contributing code if these are such high-priority features for you.

这篇关于空手道如何仅在失败的情况下自动重新运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆