cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
New Contributor

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

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.

2 REPLIES
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.

API Summer News

Congratulate last week's winners here:
1. @sanj - $50
2. @Sehuang and @aaronpliu - $35
3. @jhanzeb1 - $15

To do this week:
- Ask product-related questions
- Reply to any questions

Win $50, $35 or $15 gift card!
Winners will be decided next Monday (Aug 27)

Top Kudoed Authors
Are You In?