Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 views
in Technique[技术] by (71.8m points)

karate - Dynamic scenario freezes when called using afterFeature hook

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.

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'

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 |

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?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

Ids to delete:

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

Test clean up scenario:

# 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)

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

Delete test data feature:

Feature: To delete test data

  Background:
    * def idVal = id

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...