Forum Discussion

soapuifan's avatar
soapuifan
Occasional Contributor
13 years ago

sorting properties

Hi,
in soapui open source there is button for sorting properties (alphabetically).

Can anyone share how to get the same behaviour via groovy script? I want to sort all the properties used in given test case (properties defined on test case level)
alphabetically. The properties are in eg in transfers so I assume I can not just get properties map, sort it, delete all properties, and set them back from sorted
map. This way all the transfers will be nulled...

Yuor quick response is higlhy appreciated.
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    From within a Groovy script step in the test case:

    def propList = []     
    testRunner.testCase.getPropertyList().each { prop ->
    pmap.add(prop.name)
    }
    def sortedList = propList.sort()
    def index = 0
    sortedList.each { name ->
    testRunner.testCase.moveProperty(name, index++)
    }

    From the project Load script to sort properties in all test cases in all test suites:

    project.testSuiteList.each { testSuite ->
    testSuite.testCaseList.each { testCase ->
    def propList = []
    testCase.getPropertyList().each { prop ->
    propList.add(prop.name)
    }
    def sortedList = propList.sort()
    def index = 0
    sortedList.each { name ->
    testCase.moveProperty(name, index++)
    }
    }
    }

    I'm curious as to why you would want to do this.
  • soapuifan's avatar
    soapuifan
    Occasional Contributor
    M McDonald, thanks a lot!!!
    How could I be so blind to miss the moveProperty method in the documentation