Karate call feature with __arg removes square brackets ([]) from calling object if input is array

Viewed 369

I am having 2 file main.feature and post_single_array.feature and trying to call post_single_array.feature from main.feature. But when I pass array as argument it is getting converted into object. Is there any why I can pass array of objects to call feature __args

main.feature

Feature: All test cases related to Keyring Automation

  Background:
    * url baseUrl
    * def keyring1 =
      """
      [{
        "userName": "admin",
        "plainPassword": "admin",
        "platformType": "MX",
        "AuthenticationType": "PASSWORD"
      }]
      """

    * json jsonVar = keyring1
    * table keyring2
      | userName   | plainPassword | platformType | AuthenticationType |
      | 'admin'   | 'admin'       | 'MX'         | 'PASSWORD'                     |


  Scenario: Print input keyring
    * print keyring1
    * print jsonVar
    * print keyring2



  Scenario: Add New keyring
    * call read('post_single_array.feature') keyring1

  Scenario: Add New keyring
    * call read('post_single_array.feature') jsonVar

  Scenario: Add New keyring
    * call read('post_single_array.feature') keyring2

post_single_array.feature

Feature: Rest API for Security

  Scenario: Post
    * print __arg

Workaround

Feature: Rest API for Security

  Scenario: Post
    * def req = []
    * set req[0] = __arg
    * print __arg

Is there any why to fix this , so it can work without workaround 
1 Answers

I'm not sure I understand your question as it is very confusing, but here is my answer.

No there is no workaround. I suggest you re-read the docs and examples because the meaning of an array and object when used as a feature call argument is VERY different: https://github.com/intuit/karate#data-driven-features

So it is normal to convert the "shape" of JSON when passing to feature files in some cases, it shouldn't be seen as an "issue".

Related