SmartBear Connect 2018
Join us at SmartBear Connect 2018 on October 29th & 30th in Boston, MA.
Apply to speak and share your experience with the greater SmartBear Community
Reply
New Contributor
Accepted Solution

Groovy script syntax error on 'context.expand' doesn't like '#' symbol

[ Edited ]

Hi All,

I am trying to setup a simple 2 step test where I want to write the response from a web service call, to a file on my C drive. But, soapui is giving me a groovy syntax error. It does not like the '#' symbol.

If my request object name is GetContractVersionListRequest, and I write a groovy script as so:

def response = context.expand( ‘${GetContractVersionListRequest#Response}’ ) 
new File( “C:/Groovy/” + “_response.txt” ).write( response )

Why am I getting the following syntax error?

Wed Feb 07 16:55:05 PST 2018:ERROR:An error occurred [startup failed: Script4.groovy: 1: unexpected char: '#' @ line 1, column 64. {GetContractVersionListRequest#Request}’ ^ org.codehaus.groovy.syntax.SyntaxException: unexpected char: '#' @ line 1, column 64.

 

What's wrong with this attached picture?  I'm using soapui 5.3.0 and Windows 10.

Highlighted
Community Leader

Re: Groovy script syntax error on 'context.expand' doesn't like '#' symbol

Were the quote characters changed from ' to curly ‘? Usually Word does that.

Check the double quotes on the next line as well.

New Contributor

Re: Groovy script syntax error on 'context.expand' doesn't like '#' symbol

SUCCESS! Kudos to PaulMS! Yes you are correct!  This solves the problem!

screenshot attached.
Sorry it took me so long to get back to this post, but I've been busy with other work projects.

for this error:
Wed Mar 21 15:50:21 PDT 2018:ERROR:An error occurred [startup failed:
Script1.groovy: 1: unexpected char: '#' @ line 1, column 64.
   {GetContractVersionListRequest#Response}
                                                        ^

here is the code that gets the error:
def response = context.expand( ‘${GetContractVersionListRequest#Response}’ )
new File( “C:/Groovy/” + “_response.txt” ).write( response )

here is the code that works successfully:
def response = context.expand( '${GetContractVersionListRequest#Response}' )
new File( "C:/Groovy/" + "_response.txt" ).write( response )

notice above the difference between ‘ and '
notice above the difference between “ and "

Difficult to tell the difference from the above 2 lines huh?

Paste the above 2 lines into your favorite text editor, zoom in, then you will see the difference that causes the above referenced error.

 

You could also paste directly into the soapUI groovy script editor and maybe see the difference.

Nevertheless, while in the soapUI groovy script editor, and backspacing over what I had pasted in from a website example solved the problem and the script wrote to file & directory specified.