Forum Discussion

RobertZ's avatar
RobertZ
Frequent Visitor
5 years ago
Solved

How can i use datasink to write an output time and date into an excel spreadsheet?

Im using a dataloop to do some iterative testing. I would like to be able to output a time and date for each iteration of a test loop. Any advice on how to accomplish that?
  • richie's avatar
    richie
    5 years ago

    Hi RobertZ 

     

    I haven't got exactly what you want - my solution is kindof overkill for what you are asking for - but if you need the timestamp of each loop written out to a file - I do have something.

     

    I use the following 'script/event handler' to capture my test evidence - the script/event handler writes out the requests and responses for each test step (even the ones without assertions - like the datasource loop step) for each test case in each test suite in my project.

     

    I've just checked one of my projects that has a loop step and it records the timestamp for each loop.

     

    It uses the TestRunListener.afterStep event handler

     

    The script is as follows:

    def pName = context.currentStep.testCase.testSuite.project.name //get project name
    def pDate = new Date().format( 'yyyyMMdd' )//get current date
    def sDate = pDate.toString()//convert date to string
    def pTestSuite = context.currentStep.testCase.testSuite.name//get TestSuite name
    def pTestCase = context.currentStep.testCase.name//get TestCase name
    def filePath = 'C:/SoapUI Projects/TS0.1/TestEvidence/'+pName+'_'+sDate+'/'+pTestSuite+'/'+pTestCase+'/'//compose the folder path
    
    File file = new File(filePath)
    if (!file.exists()) file.mkdirs()//create the destination folder
    
    fos = new FileOutputStream(filePath+ testStepResult.testStep.label + '.txt', true)
    pw = new PrintWriter( fos )
    testStepResult.writeTo( pw )
    pw.close()
    fos.close()

     

    As I said above - it gives you waaaaay more than you ask for - but it does in fact record the timestamp for each iteration of a looped testcase.

     

    Essentially the above script will generate a new folder each time you execute your project.  Within this folder will be testsuite folder and within these will be testcase folders.  Within the testcase folders there are individual .txt files for each test step in your test case.

     

    I know this is more than what you ask for - but in the absence of anything else - would this suffice?

     

    Cheers,

     

    richie