0
String json = "{  \n" + 
        "   \"id\":\"\",\n" + 
        "   \"type\":\"ENTERPRISE_ORG\",\n" + 
        "   \"owner\":{  \n" + 
        "      \"type\":\"ORGANIZATION\",\n" + 
        "      \"identity_reference\":"+identityReference+"\n" + 
        "   },\n" + 
        "   \"license_type\":\"CONTRACTED\",\n" + 
        "   \"contract_start_date\":\"2018-03-22T00:00:01\",\n" + 
        "   \"contract_end_date\":\"2020-03-22T07:00:01\",\n" + 
        "   \"effective_date\":\"2018-03-22T00:00:01\",\n" + 
        "   \"originating_entity_id\":"+orginatingReference+",\n" + 
        "   \"external_contract_id\":\"0047813102Gs2LOCCZ\",\n" + 
        "   \"sold_to_id\":\"1041292\",\n" + 
        "   \"sold_to_name\":\"BLOOMSOFT ARGENTINA SA\",\n" + 
        "   \"sold_to_type\":\"RESELLER\",\n" + 
        "   \"market_segment\":\"CR\",\n" + 
        "   \"iso_3166_alpha2_code\":\"US\",\n" + 
        "   \"eu_id\":\"22547302\",\n" + 
        "   \"parent_org_id\":\"\",\n" + 
        "   \"acm_id\":null,\n" + 
        "   \"abn\":null,\n" + 
        "}";

I have post api for above request json and need to have same json with different set of data for various scenarios and need to capture values at run time and pass to next post api

Question:

I’m confused and worried how to call json request for easy maintenance and standard process.

Options

  1. Create a Java String method and call in feature file and parametrize

  2. Create json and read it and parametrize from feature file

  3. Directly having json content in feature file for each scenario with various data. Not sure moving forward any changes in the json need lot of updates / maintenance

Any suggestions would be great

Vinod Kumar
  • 45
  • 1
  • 6

2 Answers2

1

If i understand your question correctly i think option 2 is your best bet

My suggestion would be to make multiple "re-usable" feature files. Which have json manipulations within them

please read up on get, examples, Scenario Outline, set and tables

Jawad Kalia
  • 286
  • 2
  • 16
-1

Vinod - you need to do a little bit of research and read the documentation. Please read this section on Data Driven testing, and then follow the links to sample / demo files. Thanks.

https://github.com/intuit/karate#data-driven-tests

I strongly advise you not to use Java unless absolutely necessary.

EDIT: Yes, you can use JSON to data-drive tests: https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/callarray/call-json-array.feature#L8

And yes, even the JSON you read from files can have values dynamically replaced: https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/cats/kittens.feature#L28

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I have gone through data driven feature and works perfectly My scenario is some thing different where JSON request and response has 20 keys and multiple nested arrays (around 30 lines of json). Some key required previous response and other required dynamic data like date or run time and so on.. In case if i use examples (as per Pipe box) table, it need 30 columns in feature file and will multiple test scenarios. If i want to modify and maintenance.. its not user friendly.. – Vinod Kumar Apr 11 '18 at 11:20
  • Please suggest missing any thing with out using java Just a thought call json file in feature eg:- call (orderrequest.json) Is there any way to replace key-values in json at run time? – Vinod Kumar Apr 11 '18 at 11:21