Forum Discussion

mlenosgrande's avatar
mlenosgrande
Contributor
15 years ago

[SOLVED]Testing with Xpath or Xquery the correct order

Hi,
U i have the following xml response :
c
b
a


For this sample above, i would like to test the code value are order asc. Of course, for this sample the test will fail like excepted.

Any solution with xquery or xpath or java or groovy ?

Thanks in advance.I appreciate.
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    1) Use the Groovy utilities to get the node values into 2 lists.
    2) Sort one of the lists.
    3) Assert that the 2 lists are equal.
  • First thanks for your reply.

    I solved it finally more quickly.
    Here my solution without 2 lists. Hope it will help others:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

    // create holder for last response
    def holder = groovyUtils.getXmlHolder( "yourtest step name HERE#Response" )

    String [] tab =holder.getNodeValues( "//*:categorie");
    for(int i=0;i<tab.length-1;i++){
            //verify that the actual is lower or equal than the next one
    assert (tab[i].compareToIgnoreCase(tab[i+1])<=0)
    }
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Yes that is more efficient. I preferred not to worry about an index:

    def holder = gu.getXmlHolder("yourtest step name HERE#Response")
    def orderedValues = holder.getNodeValues("//*:categorie")
    if (orderedValues.size() > 1) {
    orderedValues.sort()
    def unorderedValues = holder.getNodeValues("//*:categorie")
    assert unorderedValues == orderedValues
    }


    Yours is better also if you need to point out exactly where the difference starts.