cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot convert string to a double

Highlighted
Occasional Contributor

Cannot convert string to a double

Using Soapui v 5.4.0 and A script assertion which has numerous def and assert statements in it.

A def statement produces the error shown in the subject of the post what does this mean?

Def Count01 = Cdataxmlholder [“count((//*[local-name() = ‘list01’] /*[local-name () = list02 and . = + expectedlist + “])”]

The expected list variable is defined at the start if the assertion script.

Please advise thank you

8 REPLIES 8
Highlighted
Community Leader

Re: Cannot convert string to a double

@Nasturshia : Could you please attach any screenshot or error which you are getting and also code which you are using. It will be helpful to resolve the issue.


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Occasional Contributor

Re: Cannot convert string to a double

Hi Himanshu, not easy to attach any files as the assertion script is held on a secure server.

I just need a clue where the variable is defined and what the message means.

Thanks
Highlighted
Community Hero

Re: Cannot convert string to a double

Hi @Nasturshia,

The error response is saying it cant cast a string type to a double (numeric) type. So whatever that variable is being set a string is trying to be read in as numeric. Thats it. Does that help you diagnose the issue?

If it doesnt then @HimanshuTayals probably going to need to see your script assertion code (and the full error details just in case theres any further helpful info outside the initial cast error)

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Occasional Contributor

Re: Cannot convert string to a double

Rich
Thank you that is helpful.
So It seems I need to look in another script where these elements are defined.

Can you provide an example of defining a variable as a string and integer so I can see what it looks like thank you

Highlighted
Community Hero

Re: Cannot convert string to a double

Hey @Nasturshia,

In regards to defining variables as strings or numerics, i just slap a .toString() or .toInteger() on it.

I should highlight variables/properties are saved as text/string type by default.

In regards to what the line is actually doing

[“count((//*[local-name() = ‘list01’] /*[local-name () = list02 and . = + expectedlist + “])”]

I cant actually read this to tell you whats going on.....i would need to know what the content of your response looks like cos i dont know what that local-name() method is doing. This is doing a count followed by the xpath to what is being counted which is then beimg concatenated with whatever variable/property defined as 'expectedlist'.
Im not in front of my laptop to actually try an xpath count (to work out if the count value is being stored as text (e.g. '4') or numeric (e.g. 4), but i'm wondering if 'expectedlist' is a stringtype and thats the problem?

Have you tried removing the concatenation of 'expectedlist' from the variable declaration to see what happens? If you remove it and you dont get the error, that'll mean that the expectedlist property is likely causing the issue.

Thats all i got, im afraid!

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Occasional Contributor

Re: Cannot convert string to a double

Rich
Thank you for your reply, I can now go back to the script and use the information you have supplied to try to identify the glitch.
The fog is lifting slowly.
Highlighted
Occasional Contributor

Re: Cannot convert string to a double

Rich as you suggested I did remove the offending variable from the expression and the error is not seen as you predicted.
Now I need to find where the variable is defined.

Highlighted
Community Leader

Re: Cannot convert string to a double

@Nasturshia :

 

Could you give a try to below code:

 

double count01 = Double.parseDouble([“count((//*[local-name() = ‘list01’] /*[local-name () = list02 and . = + expectedlist + “])”])

-----------------------------------OR-----------------------------------------------------------------

def count01 = [“count((//*[local-name() = ‘list01’] /*[local-name () = list02 and . = + expectedlist + “])”] as Double

 

Hope it will help you 🙂


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
New Here?
Join us and watch the welcome video:
Top Kudoed Authors