How to send API request json body in cucumber



  • Can anyone help me to send json request in one line ?? Example

    {
      "benefitPlanIDs": [
        {
          "benefitPlanID": "011748abc",
          "benefitPlanPlatform": "abc"
        }
      ],
      "clientId": "abc",
      "dateOfService": "2017-01-01",
      "language": "English",
      "searchPhrase": "Digital",
      "session": "3nopmolkgjanbe2x2ddttlua"
    }
    

    I need to pass this as Given User hits "/end points" When User make Search in request

    Examples: 
      | searchPhrase |
      | "out"        |
    

    Right now I am passing as When User enters request details as following, , ,,, ,

    Examples: 
      | BenefitPlanPlatform | BenefitPlanID     | ClientId | Session                    | DateOfService | Language  | searchPhrase |
      | "abc"              | "0117482abc" | "abc"  | "3nopmolkgjanbe2x2ddttlua" | "2017-01-01"  | "English" | "out"        |
    


  • Hi you can use multiline argument (docstring) for this:

    https://cucumber.io/docs/gherkin/reference/#doc-strings https://github.com/intuit/karate/blob/master/README.md#multi-line-expressions

    Your step definition:

    Here you pass the json between """ and """

    Given a blog post named "Random" with Markdown body
    """
           { "benefitPlanIDs": [ { "benefitPlanID": "011748abc", "benefitPlanPlatform": "abc" } ], "clientId": "abc", "dateOfService": "2017-01-01", "language": "English", "searchPhrase": "Digital", "session": "3nopmolkgjanbe2x2ddttlua" }
    """
    

    Your step definition :

    the text is retrieved in the step definition as an argument,so if your step definition is like:

    Given('the user is {string}', function(a){
      console.log(a) 
    });
    

    change it to:

    Given('the user is {string}', function(a,b){
      console.log(a) 
      console.log(b) 
    });
    

    You will have the docstring as the last argument parameter 'b'



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2