2

I'm trying to post different json body , but same set of set of steps

ie., request builder, header and assertion.

Is it possible to implement cucumber data table for different set of json?

1

Have you look at this? Maybe it gives you some idea. It is combination of Cucumber and JSON_SPEC.
Otherwise you can always load different data from different JSON files as resources.

1

Take a look at Karate I think it is exactly what you are looking for, and it has some pretty advanced data-driven testing capabilities that go beyond what the default Cucumber Examples tables give you.

Here is one advanced example: dynamic-params.feature

1

Yes, you could use a Cucumber DataTable, but you would have to implement the step to create the JSON String / object from your DataTable. Here's a blog that can help you there: http://www.thinkcode.se/blog/2014/06/30/cucumber-data-tables

Rather than using JSON Strings, consider using a domain object with a library like Jackson to generate the JSON from the object for you. This makes your code much cleaner (easier to maintain, less error-prone)

There are several frameworks that can help you post the HTTP request. Karate is one such framework, which I personally haven't used. Another is RestAssured, which I am using atm and found quite easy to get started with. There should be plenty of examples/tutorials on how to use it.

Good luck!

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.