使用afterFeature钩子调用时,动态方案冻结 [英] Dynamic scenario freezes when called using afterFeature hook

查看:60
本文介绍了使用afterFeature钩子调用时,动态方案冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用afterFeature挂钩调用功能文件进行测试清理时,行为异常.可以正确调用清除功能文件,因为我可以从文件的背景"部分看到打印内容,但是由于某种原因,方案大纲的执行挂起.

Strange behaviour when I call a feature file for test clean using afterFeature hook. The cleanup feature file is called correctly because I can see the print from Background section of the file, but for some reason the execution hangs for Scenario Outline.

我已经尝试通过Junit5 Runner以及在IntelliJ IDE中通过右键单击功能文件来运行功能,但是遇到相同的问题,执行挂起.

I have tried running feature with Junit5 runner and also in IntelliJ IDE by right clicking on feature file but get the same issue, the execution hangs.

这是我的主要功能文件:

This is my main feature file:

Feature: To test afterFeature hook

  Background:
    * def num1 = 100
    * def num2 = 200
    * def num3 = 300

    * def dataForAfterFeature =
    """
    [
      {"id":'#(num1)'},
      {"id":'#(num2)'},
      {"id":'#(num3)'}
    ]
    """
  * configure afterFeature = function(){ karate.call('after.feature'); }

  Scenario: Test 1
    * print 'Hello World 1'

  Scenario: Test 2
    * print 'Hello World 2'

afterFeature文件:

The afterFeature file:

@ignore

Feature: Called after calling feature run is completed

  Background:
    * def dynamicData = dataForAfterFeature
    * print 'dynamicData: ' + dynamicData

  Scenario Outline: Print dynamic data
    * print 'From after feature for id: ' + <id>

    Examples:
    | dynamicData |

执行停在方案大纲中.我可以在控制台中看到dynamicData变量的打印值,但此后没有任何反应.

The execution stalls at Scenario Outline. I can see the printed value for dynamicData variable in console but nothing happens after that.

似乎轮廓循环未开始或已崩溃?由于测试尚未完成或没有错误报告,因此无法从日志中获取详细信息.我还能检查什么或可能是什么问题?

Seems like the outline loop is not starting or has crashed? Was not able to get details from log as the test has not finished or there is no error reported. What else can I check or what might be the issue?

如果不容易重现,您建议使用哪种测试清除方法?

If not easily reproducible, what test cleanup workaround do you recommend?

推荐答案

目前,我已经完成以下变通办法,其中在具有测试功能的末尾添加了测试清理方案.已经停止了这些测试的并行执行,老实说,我不介意这些测试不会并行运行,因为它们无论如何都可以快速运行.

For now, I have done the following workaround where I have added a test clean-up scenario at the end of the feature that has tests. Have stopped parallel execution for these tests and to be honest I do not mind these tests not running in parallel as they are fast to run anyways.

要删除的ID:

* def idsToDelete =
    """
      [
        101,
        102,
        103
      ]
   """

测试清理方案:

# Test data clean-up scenario
  Scenario: Delete test data
    # Js method to call delete data feature.
    * def deleteTestDataFun =
    """
      function(x) {
        var temp = [x];
        // Call to feature. Pass argument as json object.
        karate.call('delete-test-data.feature', { id: temp });
      }
    """
    * karate.forEach(idsToDelete, deleteTestDataFun)

调用删除测试数据方案,并向其传递需要删除的ID列表.

Calls the delete test data scenario and passes it a list of ids that needs to be deleted.

删除测试数据功能:

Feature: To delete test data

  Background:
    * def idVal = id

  Scenario: Delete 
    Given path 'tests', 'delete', idVal
    Then method delete

这篇关于使用afterFeature钩子调用时,动态方案冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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