Forum Discussion

gmanoj77's avatar
gmanoj77
Occasional Contributor
11 years ago

[Res]how to do an assert to test the count of a list returnd

how to do an assest to test the count of a list returned
  • nmrao's avatar
    nmrao
    Icon for Champion Level 2 rankChampion Level 2
    You mean in the groovy?

    for eg:
    def list = [1,2,3,4]
    def expectedSize = 4
    assert list.size == expectedSize

    Is this something you looking for?
  • gmanoj77's avatar
    gmanoj77
    Occasional Contributor
    yes in Groovy, but bit for dynamic which can parse the response.
  • Cizo89's avatar
    Cizo89
    Frequent Contributor
    Hi,

    this should give you the idea:

    String xml = '''<a>
    <b>b1</b>
    <b>b2</b>
    <b>b3</b>
    <b>b4</b>
    </a>'''

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

    Integer expectedSize = 4

    assert holder.getNodeValues("//a/b").size() == expectedSize

    /*
    To get whole Response of your requested step, use this:
    def holder = groovyUtils.getXmlHolder("Your_Test_StepT#ResponseAsXml")
    */


    Regards,
    Marek
  • gmanoj77's avatar
    gmanoj77
    Occasional Contributor
    this worked except had to change to

    def holder = groovyUtils.getXmlHolder("Your_Test_StepT#Response")