Forum Discussion

chathurad's avatar
6 years ago

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.



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( at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST( at org.codehaus.groovy.control.SourceUnit.parse( at org.codehaus.groovy.control.CompilationUnit$ at

2 Replies

  • richie's avatar
    Community Hero

    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?


  • TNeuschwanger's avatar
    Champion Level 2

    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.  :)