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?
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.
Sign up to join this communityHave 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.
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
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!