Forum Discussion

WaveyDavey's avatar
WaveyDavey
Occasional Contributor
14 years ago

[Resolved] Simple Assert needed

My REST service returns this xml :
<root>
<error>200</error>
<errorText>OK</errorText>
<data>
<id>215901</id>
<core_range>844</core_range>
<core_number>1112233</core_number>
<destination>07899999999</destination>
<mapper>rest.api.AutoMap.Done</mapper>
<status>mapped</status>
<comment/>
<mapping_attempts>6</mapping_attempts>
<log><![CDATA[Auto map log = lots of stuff ]]></log>
<reset/>
</data>
<loggedIn>1</loggedIn>
<yourSession>k8vm88govpc69o7q5m00kluj41</yourSession>
</root>

How do I add an assertion that <mapping_attempts> is between 1 and 20 ? I guess I need to get the node, and cast to int, but I have no idea how !

David

2 Replies

  • Hello,

    To do this, probably the easiest way is to create script assertion. Basically you need to
    extract the value from the response and check it. Something like:



    def attempts = context.expand( '${Your Test Step Name#Response#//root[1]/mapping_attempts[1]}' ) as Integer

    assert attempts > 1 && attempts < 20

    // or
    // assert attempts >= 1 && attempts <= 20
    // if you want to include 1 and 20



    Hope this helps.

    regards!
    Predrag
    /Smart Bear Sweden (eviware)
  • WaveyDavey's avatar
    WaveyDavey
    Occasional Contributor
    Aaaah : as Integer !!!
    Wish I'd known about that, I was trying to find all sorts of ways to cast from string to integer.

    Many thanks
    David