cancel
Showing results for 
Search instead for 
Did you mean: 

How to use data source values inside groovy scripts

Contributor

How to use data source values inside groovy scripts

In my test suite im pasing some values using a excel file. Is there any way to assert the excel file values with actual response at the script assersion level.

 

This is my data source any when i try to add this value to a variable at script level it gives me an error.

${DataSource#SchID}

 

startup failed: Script2.groovy: 1: unexpected char: '#' @ line 1, column 22. var ss = ${DataSource#SchID} ^ org.codehaus.groovy.syntax.SyntaxException: unexpected char: '#' @ line 1, column 22. at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:135) at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:108) at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236) at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:162) at
2 REPLIES 2
Community Hero

Re: How to use data source values inside groovy scripts

Hi,

Sorry. I found your post a little confusing. Are you saying you're using a script assertion and you're getting an error response when you try using the schid property associated with your datasource test step within the script? If my understanding is correct, there doesnt appear to be anything wrong with the syntax you've specified so it seems to me your script isnt expecting the variable at that point in your script.

Can you provide the script you're using? It would help resolve this.

Without seeing your script im just wondering, did you wrap ${datasource#schid} within single quotes?

Cheers

Richie
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 title of the post to something more descriptive? This will help people when searching for problems.
Contributor

Re: How to use data source values inside groovy scripts

def SchID = context.expand( '${DataSource#SchID}' )

assert SchID.equals('ABC'), "Expected School ID to equal 'ABC' but it doesnt. '" + SchID + "' was returned instead";

 

Your first word of the groovy code is 'var' also...  'def' is what groovy likes.  Smiley Happy

New Here?
Join us and watch the welcome video:
Top Kudoed Authors