1

I have a response stored in one of my karate var holdingid as :

And def holdingID =  $GetDataSet_greaterThan_Filter_Response.rowData[*].7

holdingID = [ 21015000, 146066000, 10497015000, 58765000, 27790000, 4.308709302E7, 2.0360701868295E7, 21710000, 331720000, 62327000, 57210000, 19430000, 19129000, 2.0168081879E8, 35242933, 7.0444591772E8, 2.551241528E7, 1.948655045E7, 2.520400137E7, 3.8540777658E8, 103001450, 1.957371122E7, 1.6805940819E8, 20907400, 19500118, 1.8480989443E8, 181875000, 5.609840033E7, 6.931536767E7, 5.32741731109984E8, 188974032, 591381346, 8.419481045E7, 19868866, 5.5488624902E7, 30759197, 8.926510191E7, 5.382712107E7, 3.095059546E7, 7.174669486E7, 23828000, 42558698, 1.777676693E7, 21695100, 7.198816072E8, 322132495, 19120000 ]

Now I need to check following operations over this with some value(for example: 17559097):

  1. Greater Than 17559097
  2. Greater than equals to 17559097
  3. Less than 17559097
  4. Less than or equals to 17559097

What I tried:

First Approach:

I did following things to find the solution: * assert holdingID > 17559097

This got fail with this message: assertion failed: assert evaluated to false: holdingID > 17559097

Second Approach: Created a list and tried to perform sorting. So that I can check first value and apply assertion over that.

And def listAsDescending = new ArrayList()
* eval for(var i = 0; i < holdingID.length; i++) listAsDescending.add(holdingID[i])
And print listAsDescending
* eval Collections.sort(listAsDescending)

But I got following error:Collections.sort(listAsDescending), java.lang.Integer cannot be cast to java.lang.Long

How to perform these operations over stored variable?

1 Answer 1

1

Read the docs carefully, there are so many ways. I leave it to you to find other ways:

* def holdingId = [ 21015000, 146066000, 10497015000, 58765000, 27790000, 4.308709302E7, 2.0360701868295E7, 21710000, 331720000, 62327000, 57210000, 19430000, 19129000, 2.0168081879E8, 35242933, 7.0444591772E8, 2.551241528E7, 1.948655045E7, 2.520400137E7, 3.8540777658E8, 103001450, 1.957371122E7, 1.6805940819E8, 20907400, 19500118, 1.8480989443E8, 181875000, 5.609840033E7, 6.931536767E7, 5.32741731109984E8, 188974032, 591381346, 8.419481045E7, 19868866, 5.5488624902E7, 30759197, 8.926510191E7, 5.382712107E7, 3.095059546E7, 7.174669486E7, 23828000, 42558698, 1.777676693E7, 21695100, 7.198816072E8, 322132495, 19120000 ]
* match each holdingId == '#? _ > 17559097'
* def fun = function(x){ return x > 17559097 }
* def actual = karate.filter(holdingId, fun)
* match holdingId == actual
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.