2

Scenario:

  * def Test_assignment_type = 'ALL'
  * def TEST_NODE_ID = '123455667'

  * def list = [ '123', '1234', '12345' ]
  * def gId_list = karate.mapWithKey(list, 'HOOK_TEST_LOCATION_GID')  

  * callonce read('classpath:hook/delete-assignments-hook.feature') {HOOK_TEST_LOCATION_ID: "#(TEST_NODE_ID)", HOOK_TEST_ASSIGNMENT_TYPE: "#(Test_assignment_type)"}

delete-assignments-hook.feature:

Scenario:

  * Given path '/nodes/'+HOOK_TEST_LOCATION_ID+'/locations/'+HOOK_TEST_LOCATION_GID+'/assignments'
  * And param assignmentType = HOOK_TEST_ASSIGNMENT_TYPE
  * When method delete
  * Then assert responseStatus == 204  || responseStatus == 404

how to pass gId_list in my delete-assignments-hook.feature, so that delete api runs for each value in the list.

1 Answers1

0

Just start with a simple example and study it. This below will make 3 calls with a parameter called id. And also read the documentation: https://github.com/karatelabs/karate#data-driven-features

Feature:

Scenario:
    * def array = [1, 2, 3]
    * def data = karate.mapWithKey(array, 'id')
    * call read('@called') data

@ignore @called
Scenario:
    * url 'https://httpbin.org/anything'
    * param id = id
    * method get
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Hi Peter, I tried this, I gave like this - callonce read('classpath:hook/delete-assignments-hook.feature') {HOOK_TEST_LOCATION_ID: "#(TEST_NODE_ID)", HOOK_TEST_ASSIGNMENT_TYPE: "#(Test_assignment_type)"} gid_list – harshini reddy Sep 05 '22 at 11:12
  • But this is throwing me an error - HOOK_TEST_LOCATION_GID is not defined in delete-assignments-hook.feature – harshini reddy Sep 05 '22 at 11:15
  • @harshinireddy I think it is time for you to follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue - let me say again that you seem to be trying to do too many things without understanding the basics. I strongly suggest not trying to even do `call` let alone `callonce` until you have got a hard-coded flow to work. it is ok to have multiple simple tests instead of this tendency to "re use", read this: https://stackoverflow.com/a/54126724/143475 – Peter Thomas Sep 05 '22 at 11:56
  • I get your point, can you please help me out how can I change my above scenario into a simple one. – harshini reddy Sep 05 '22 at 12:09
  • Since I have multiple dynamic variables for my api, I couldn't able to implement simple example that you gave above. – harshini reddy Sep 05 '22 at 12:14
  • @harshinireddy I provided a simple example, and I'm sorry I can't help more than that. I hope someone else here can help, I pass. – Peter Thomas Sep 05 '22 at 12:15
  • Thank you Peter, one last question, is there a way i can create a function and run my read(api) inside that loop? – harshini reddy Sep 05 '22 at 12:23
  • @harshinireddy yes: https://stackoverflow.com/search?q=%5Bkarate%5D+loop – Peter Thomas Sep 05 '22 at 12:25