1

I am trying to get the Karate json report for the sample feature file in the specific format mentioned below.

[
  {
    "line": 3,
    "elements": [
      {
        "start_timestamp": "2022-04-05T17:17:20.811Z",
        "before": [
          {
            "result": {
              "duration": 19702884258,
              "status": "passed"
            },
            "match": {
              "location": "Hooks.before(Scenario)"
            }
          }
        ],
        "line": 7,
        "name": "Guided Member Welcome Login - SCAL_ACTIVE_NEW_SMOKE_EN",
        "description": "",
        "id": "smoke-feature;guided-member-welcome-login---scal-active-new-smoke-en",
        "after": [
          {
            "result": {
              "duration": 1245339916,
              "status": "passed"
            },
            "match": {
              "location": "Hooks.after(Scenario)"
            }
          }
        ],
        "type": "scenario",
        "keyword": "Scenario",
        "steps": [
          {
            "result": {
              "duration": 150247948961,
              "status": "passed"
            },
            "line": 8,
            "name": "Iamloggedintokp.orgas\"SCAL_ACTIVE_NEW_SMOKE\"\"English\"",
            "match": {
              "arguments": [
                {
                  "val": "\"SCAL_ACTIVE_NEW_SMOKE\"",
                  "offset": 28
                },
                {
                  "val": "\"English\"",
                  "offset": 51
                }
              ],
              "location": "GMWHub.iAmLoggedInToKpOrgAs(String,String)"
            },
            "keyword": "Given "
          },
          {
            "result": {
              "duration": 15987954340,
              "status": "passed"
            },
            "line": 9,
            "name": "IamnavigatedtoGuidedMemberWelcomehubpage",
            "match": {
              "location": "GMWHub.iNavigateToGuidedMemberWelcomeHubPage()"
            },
            "keyword": "When"
          }
        ],
        "tags": [
          {
            "name": "@smoke"
          },
          {
            "name": "@regression"
          }
        ]
      }
    ],
    "name": "Smoke Feature",
    "description": "",
    "id": "smoke-feature",
    "keyword": "Feature",
    "uri": "file:target/parallel/features/Smoke_scenario001_run001_IT.feature",
    "tags": []
  }
]

However I am getting the report without the before and after keys as shown below.

[
  {
    "line": 1,
    "elements": [
      {
        "start_timestamp": "2022-05-23T07:27:32.501Z",
        "line": 3,
        "name": "GET Request",
        "description": "",
        "id": "get-request",
        "type": "scenario",
        "keyword": "Scenario",
        "steps": [
          {
            "name": "url 'https://reqres.in/api/users/2'",
            "result": {
              "duration": 1949100,
              "status": "passed"
            },
            "match": {
              "location": "karate",
              "arguments": []
            },
            "keyword": "Given",
            "line": 4
          },
          {
            "name": "method GET",
            "result": {
              "duration": 1208456200,
              "status": "passed"
            },
            "match": {
              "location": "karate",
              "arguments": []
            },
            "keyword": "When",
            "line": 5
          },
          {
            "name": "status 200",
            "result": {
              "duration": 16100,
              "status": "passed"
            },
            "match": {
              "location": "karate",
              "arguments": []
            },
            "keyword": "Then",
            "line": 6
          }
        ],
        "tags": []
      }
    ],
    "name": "feature/main.feature",
    "description": "Testing GET API",
    "id": "testing-get-api",
    "keyword": "Feature",
    "uri": "feature/main.feature"
  }
]

The TestRunner Class:

public class TestRunner {

@Test
void testParallel() {

 ArrayList list = new ArrayList();
 Results results = Runner.path("classpath:features/sample.feature").parallel(5);
 Stream<FeatureResult> res = results.getFeatureResults();
 
 res.forEach(action -> {

      JSONObject jsonObj = new JSONObject(action.toCucumberJson());
       System.out.println(jsonObj);
    }
  }
} 

Sample Feature file:

Feature: Testing GET API
Scenario: GET Request
Given url 'https://reqres.in/api/users/2'
When method GET
Then status 200 

Is there a way to get the json report as expected with the before and after keywords?

Hemanth B
  • 11
  • 2

1 Answers1

0

Assume this is not supported by Karate. You are welcome to file an issue and make a case for and submit a PR (contribute code).

For a similar discussion, refer this thread: https://github.com/karatelabs/karate/issues/1980

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248