3

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"        |
3

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'

| improve this answer | |
  • Just fyi, in Karate, you cannot define a custom function like you do in Cucumber, as described in your answer. – djangofan Jun 5 at 21:03
  • @djangofan that was for cucumber , github.com/intuit/karate/blob/master/… the correct implementation can be seen here – PDHide Jun 5 at 21:19
2

I'm assuming you are using Java in your testing framework. You have two ways of achieving it.

Option 1:

Try using Karate framework. If you use Java and want to do easy API testing.

Option 2:

Table is an object with fields named accordingly to table header. Basically you need to serialize them to json in a way that is suitable. You can use gson library for serialization.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.