How to use data source values inside groovy scripts
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2018
04:55 PM
09-15-2018
04:55 PM
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2018
04:31 AM
09-16-2018
04:31 AM
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
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 Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018
12:03 PM
09-17-2018
12:03 PM
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. 🙂
