Forum Discussion

alibaba82's avatar
alibaba82
Super Contributor
15 years ago

Script assertion using groovyutils acting funky

I have the following script assertion for my soap response (see attachment)

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( "GetRecommendationItemsInList - Daily#Response" )
def AiringType = holder.getNodeValues("//ns1:GetRecommendationItemsInListResponse[1]/ns1:GetRecommendationItemsInListResult[1]/ns1:Airings[1]/ns1:Airing/ns1:AiringType[1]")
def CC = holder.getNodeValues("//ns1:GetRecommendationItemsInListResponse[1]/ns1:GetRecommendationItemsInListResult[1]/ns1:Airings[1]/ns1:Airing/ns1:CC[1]")
def StartDateTime = holder.getNodeValue("//ns1:GetRecommendationItemsInListResponse[1]/ns1:GetRecommendationItemsInListResult[1]/ns1:Airings[1]/ns1:Airing/ns1:StartDateTime[1]")
def EndDateTime = holder.getNodeValue("//ns1:GetRecommendationItemsInListResponse[1]/ns1:GetRecommendationItemsInListResult[1]/ns1:Airings[1]/ns1:Airing/ns1:EndDateTime[1]")


for (int j = 0; j < AiringType.size(); j++)
{
if(AiringType[j] == null || AiringType[j].equals(""))
throw new Exception("Error: AiringType @index[" + j + "] is empty")

if(CC[j] == null || CC[j].equals(""))
throw new Exception("Error: CC @index[" + j + "] is empty")

if(StartDateTime[j] == null || StartDateTime[j].equals(""))
throw new Exception("Error: StartDateTime @index[" + j + "] is empty")

if(EndDateTime[j] == null || EndDateTime[j].equals(""))
throw new Exception("Error: EndDateTime @index[" + j + "] is empty")
}

I am getting index out of range --> 21 when there are 23 items in the list. Not sure why this is happening.

Thanks

Ali

4 Replies

  • alibaba82's avatar
    alibaba82
    Super Contributor
    Hi.
    sorry to bother so quickly again. but this issue is a major blocker for me. not sure if its bad scripting or a bug. if you can look at this quickly, it would really help out.

    Thanks

    Ali
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi!

    you need to use

    holder.getNodeValues for StartDateTime and EndDateTime

    regards!

    /Ole
    eviware.com
  • alibaba82's avatar
    alibaba82
    Super Contributor
    Thanks for the quick response and sorry for bad scripting