Cucumber JSON Report

By now we have seen how HTML report is generated. However, if we want to pass on this report information to any other application, then JSON is another format for generating Cucumber test reports. JSON is an object containing a lot of information stored in text format. JSON report can also be used as a payload of information to be transferred between different servers. Further, it can be used to be displayed as a web page. In a nutshell, JSON reports can be used by other application.

@CucumberOptions(
    plugin = {"pretty","json:target/cucumber/cucumber.json"},
    features = {"features"},
    glue={"com.pb.cucumbertest.stepdefinitions"},
    monochrome = true,
    strict = true,
    dryRun = false,
    tags = {"@singleargument"}
)

In plugin you can see we have specified that we need json report. Output will be generated in cucumber.json inside folder target/cucumber.

Sample Output

[
  {
    "line": 2,
    "elements": [
      {
        "line": 4,
        "name": "Title of Background",
        "description": "",
        "type": "background",
        "keyword": "Background",
        "steps": [
          {
            "result": {
              "duration": 38963404000,
              "status": "passed"
            },
            "line": 5,
            "name": "I am on the home page",
            "match": {
              "location": "com.pb.cucumbertest.stepdefinitions.StepDefinitions.i_am_on_the_homepage()"
            },
            "keyword": "Given "
          },
          {
            "result": {
              "duration": 2530519000,
              "status": "passed"
            },
            "line": 6,
            "name": "I follow \"Sign in\" link",
            "match": {
              "arguments": [
                {
                  "val": "\"Sign in\"",
                  "offset": 9
                }
              ],
              "location": "com.pb.cucumbertest.stepdefinitions.StepDefinitions.i_follow_link(java.lang.String)"
            },
            "keyword": "And "
          }
        ]
      },
      {
        "start_timestamp": "2020-02-23T07:56:08.338Z",
        "before": [
          {
            "result": {
              "duration": 1670766000,
              "status": "passed"
            },
            "match": {
              "location": "com.pb.cucumbertest.stepdefinitions.StepDefinitions.bf0()"
            }
          }
        ],
        "line": 23,
        "name": "Verify Forgot Password Functionality",
        "description": "",
        "id": "registration--login-and-myaccount;verify-forgot-password-functionality",
        "after": [
          {
            "result": {
              "duration": 5003024000,
              "status": "passed"
            },
            "match": {
              "location": "com.pb.cucumbertest.stepdefinitions.StepDefinitions.af0()"
            }
          }
        ],
        "type": "scenario",
        "keyword": "Scenario",
        "steps": [
          {
            "result": {
              "duration": 5940303000,
              "status": "passed"
            },
            "line": 24,
            "name": "I follow \"Forgot your password?\" link",
            "match": {
              "arguments": [
                {
                  "val": "\"Forgot your password?\"",
                  "offset": 9
                }
              ],
              "location": "com.pb.cucumbertest.stepdefinitions.StepDefinitions.i_follow_link(java.lang.String)"
            },
            "keyword": "When "
          },
          {
            "result": {
              "error_message": "java.lang.ArithmeticException: / by zero\n\tat com.pb.cucumbertest.stepdefinitions.StepDefinitions.i_fill_in_with(StepDefinitions.java:167)\n\tat ✽.I fill in \"input[id\u003d\u0027email\u0027]\" with \"goswami.tarun77+7@gmail.com\"(file:///Users/tarungoswami/git/cucumbertest/cucumbertest/features/Login.feature:25)\n",
              "duration": 188597000,
              "status": "failed"
            },
            "line": 25,
            "name": "I fill in \"input[id\u003d\u0027email\u0027]\" with \"goswami.tarun77+7@gmail.com\"",
            "match": {
              "arguments": [
                {
                  "val": "\"input[id\u003d\u0027email\u0027]\"",
                  "offset": 10
                },
                {
                  "val": "\"goswami.tarun77+7@gmail.com\"",
                  "offset": 35
                }
              ],
              "location": "com.pb.cucumbertest.stepdefinitions.StepDefinitions.i_fill_in_with(java.lang.String,java.lang.String)"
            },
            "keyword": "And "
          },
          {
            "result": {
              "duration": 35000,
              "status": "skipped"
            },
            "line": 26,
            "name": "I click on \"button[type\u003d\u0027submit\u0027] span i\"",
            "match": {
              "arguments": [
                {
                  "val": "\"button[type\u003d\u0027submit\u0027] span i\"",
                  "offset": 11
                }
              ],
              "location": "com.pb.cucumbertest.stepdefinitions.StepDefinitions.i_click_sign_in_button(java.lang.String)"
            },
            "keyword": "And "
          }
        ],
        "tags": [
          {
            "name": "@sanity"
          },
          {
            "name": "@singleargument"
          }
        ]
      }
    ],
    "name": "Registration, Login and MyAccount",
    "description": "",
    "id": "registration--login-and-myaccount",
    "keyword": "Feature",
    "uri": "file:features/Login.feature",
    "tags": [
      {
        "name": "@sanity",
        "type": "Tag",
        "location": {
          "line": 1,
          "column": 1
        }
      }
    ]
  }
]
Sun, 08/30/2020 - 22:51

Authored by

Tarun Goswami, works as a Technical Lead at the well-known IT services company. With Over 11+ years of experience in Quality Assurance, he writes engaging and informative blogs in his spare time.