0

my requests is created using csv file I need to modify/delete few values in a json request, I have a function that should make Modify/Delete the Key Values

however the delete obj[key] generates error

Feature: Validate TCs

Background:
  Given url 'https://'+env_apiHost
  Given path '/abc/pqr-stu/v1/wxy-zzzz'

Scenario Outline: Validate Functional Data  
  * def CHK_NULL = 'CHK_NULL'
  * def CHK_MAND = 'CHK_MAND'
  * def modify_pop_key = 
  """
    function(obj) {
      for(var key in obj) {
          if (typeof obj[key] === 'object') {
            modify_pop_key(obj[key])
          }else if (obj[key] === CHK_MAND) {
              delete obj[key]        
          }else if (obj[key] === CHK_NULL) {
              obj[key] = ''
          }
      }
    }
  """
  * def request_string = 
  """
    {
      "Key1": "<key1>",
      "key2": "<key2>",
      "key3": "<key3>",
      "key4": "<key4>"
    }
  """    
  * def req1 = call modify_pop_key request_string 
  And request request_string
  When method post
  Then status 200
  * print response

Examples:
    read('classpath:data/jsnVals.csv')| 

data/jsnVals.csv

    | key1   | key2   | key3   | key4   |
    | HAPPY  | Val_12 | Val_13 | Val_14 |
    | TC_001 |CHK_MAND| Val_23 | Val_24 |
    | TC_002 |CHK_NULL| Val_33 | Val_34 |
    | TC_003 | Val_42 | Val_43 | Val_44 |

Error:

* def req1 = call modify_pop_key request_string
org.graalvm.polyglot.PolyglotException
src/test/java/xxxxx/feature/pqr_xyx.feature:58
Vibhuti Salvi
  • 25
  • 1
  • 4
  • can you kindly simplify your question to focus on a single problem ? read this please: https://stackoverflow.com/help/how-to-ask - anyway this can be a bug in the version of karate you are using, so try 1.4.0.RC3 - that said, I think you are un-necessarily complicating your scenarios, karate is not designed to be used like this: https://stackoverflow.com/a/54126724/143475 - if you think it is a bug, follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Mar 05 '23 at 04:16

0 Answers0