Forum Discussion

srk's avatar
srk
New Contributor
16 years ago

How to Export the data to excel Which is returned by Groovy Script

I wrote a Groovy Script Which takes the Values from Data Source and returned in Log Output. How to export this data to excel sheet using groovy script?

Groovy Script which  prints output

def EMPLOYEENAME = context.expand( '${DataTest#EMPLOYEENAME}' )
def EMPID=context.expand('${DataTest#EMPID}')
log.info(EMPLOYEENAME)
log.info(EMPID)

I want to upload this EMPLOYEENAME, EMPID value to EXCEL. Can someone help me out?

1 Reply

  • EADS_Support's avatar
    EADS_Support
    Occasional Contributor
    you can create a datasink that writes to an excel file

    add a datasink property then write to that from the groovy script

    i.e.
    create a datasink called TestOutput
    create properties within datasink called 'EmployeeName' & 'EmployeeID'

    then in groovy script
    def EMPLOYEENAME = context.expand( '${DataTest#EMPLOYEENAME}' )
    def EMPID=context.expand('${DataTest#EMPID}')
    log.info(EMPLOYEENAME)
    log.info(EMPID)

    def datasink = testRunner.testCase.testSteps('TestOutput')
    datasink.setPropertyValue('EmployeeName', EMPLOYEENAME)
    datasink.setPropertyValue('EmployeeID', EMPID)


    or you can reference the data source directly within the datasink value field bypassing the need to do this within a groovy script, of course that does depend on whether or not you need to use those values in the script
    just a thought