1

I have two jsonArrays which have keys with different name and I want to compare each json object in a separate feature file.

Is there any way I can pass two jsonArrays in a feature file and compare them.

sample-create.feature

* table kittens1 
  | name   | age | dept|
  | 'Bob'  |   2 | IT. |
  | 'Wild' |   1 | HR. |
  | 'Nyan' |   3 |ADMIN|

* table kittens2 
  | first_name    | emp_age   |
  | 'Bob'         |   "2"     |
  | 'Wild'        |   "1"     |
  | 'Nyan'        |   "3"     |


* def result = call read('cat-create.feature') kittens1 kittens2

cat-create.feature

@ignore
Feature:

Scenario:
  assert first_name == name
  assert parseInt(emp_age) == age

I am not able to pass jsonObject from both jsonArrays in another (cat-create.feature) feature file.

Is there any other way to achieve this?

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248

1 Answers1

0

The mistake you are making is call only takes one argument. Also note that any variables before the call are "visible" in the called feature. So you may already have what you want.

That said, I think you are over-complicating things and perhaps not yet appreciated the power of Karate and JSON arrays. I think the below will achieve what you want, without an extra Feature: or call.

* def data2 = kittens2.map(x => ({ name: x.first_name, age: parseInt(x.emp_age) }))
* match kittens1 contains deep data2

Please spend time reading these answers for more explanation of the above: https://stackoverflow.com/a/53120851/143475 | https://stackoverflow.com/a/76091034/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248