cancel
Showing results for 
Search instead for 
Did you mean: 

ERROR: An error occurred [java.lang.ClassCastException]

Highlighted
New Member

ERROR: An error occurred [java.lang.ClassCastException]

Hi

 

I am trying to add a Groovy Script to compare Data Source Results with Rest API Resuest. I am asserting as a individual Step. Currently it is erroring out and the error is Java.Lang.ClassCastException.

 

If I Remove For Loop then Script passes, but i want script to go through all records in db and compare all node elements from API

 

import groovy.xml.*
import groovy.json.JsonSlurper


//Grabbing db Response
def cO_RecordID = context.expand( '${DataSource#cO_RecordID }' ) //retreive record id

def db_recordid = cO_RecordID .toString() // Casting Result to String
log.info db_recordid

//Grabbing Json Response
def Jsonresponse_RecordId = context.expand( '${Get Funding Frequencies#Response}' ) //retreiving Json Response
log.info Jsonresponse_RecordId

def Json_Object = new JsonSlurper().parseText(Jsonresponse_RecordId) // putting Json Response into an Object
log.info Json_Object.items.id[0].toString()


def ItemCountResponse = context.expand( '${Get Funding Frequencies#Response#$[\'itemCount\']}' )
log.info ItemCountResponse.toString()

def int i;

for(i=0; i<=ItemCountResponse; i++)
{
if(i<ItemCountResponse)
{
//testRunner.runTestStepByName("Get Funding Frequencies")
log.info i
}
else
{
End
}
}

 

Can anyone guide me through this error, also if you can confirm if the For Loop Statement is correct in my script that would be great. 

Tags (1)
3 REPLIES 3
Highlighted
Community Manager

Re: ERROR: An error occurred [java.lang.ClassCastException]

@richie , @nmrao , @jsheph01 , @Radford could you take a look at this script? Thank you! 


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
Contributor

Re: ERROR: An error occurred [java.lang.ClassCastException]

Do you have the whole error message or know what line the error occured on? I have not been able to try it but by guess is that the error is coming from i<=ItemCountResponse in the for loop. My guess is that ItemCountResponse is not an numeric value. What value do you get if you output ItemCountResponse without the .toString() ?

 

Also, you dont need to define the variable i before you use it in the for loop. The variable is declared when you do for(i=0;

Highlighted
Community Manager

Re: ERROR: An error occurred [java.lang.ClassCastException]

Thank you jsheph01! 

 

@MohammedRehman, please provide the info jsheph01 is requiring, we might find a solution for you! Thanks. 


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Compete with community members in the TechCorner Challenge and get into the Leaderboard!

Rank Participant Points Earned
1 msiadak 12
2 nmrao 8
3 HimanshuTayal 3
Top Kudoed Authors