Karate API Testing - Sorting Validation Scenario

后端 未结 2 583
旧时难觅i
旧时难觅i 2020-12-10 23:46

I have a request which produces below response:

{
\"totalRows\": 10,
\"colDefs\": [
    {
        \"entityAttributeId\": \"somestring\",
        \"headerName         


        
2条回答
  •  生来不讨喜
    2020-12-11 00:11

    Please refer to this example that even involves a case-insensitive sort. It is easy to dive into Java from Karate, especially for a complex use-case like this:

    Scenario: case-insensitive sort
        * def ArrayList = Java.type('java.util.ArrayList')
        * def Collections = Java.type('java.util.Collections')
    
        * def json = [{ v: 'C' }, { v: 'b' }, { v: 'A' }]
        * def actual = $json[*].v
        * match actual == ['C', 'b', 'A']
        * def list = new ArrayList()
        * eval for (var i = 0; i < actual.length; i++) list.add(actual[i])
        * match list == ['C', 'b', 'A']
        * eval Collections.sort(list, java.lang.String.CASE_INSENSITIVE_ORDER)
        * match list == ['A', 'b', 'C']
    

    Since your example is too complex, I can't provide a specific answer, kindly refer: https://stackoverflow.com/help/mcve

    For a cleaner way to express the above code, refer the actual example, where you can move some of the code into JS: https://github.com/intuit/karate/blob/master/karate-junit4/src/test/java/com/intuit/karate/junit4/demos/sort-array.feature

提交回复
热议问题