Forum Discussion

RobertZ's avatar
RobertZ
Frequent Visitor
6 years ago

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?

  • 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

     

     

  • Olga_T's avatar
    Olga_T
    SmartBear Alumni (Retired)

    Thanks for reaching out, RobertZ !

     

    Community, any ideas of how to accomplish this task?

     

    • richie's avatar
      richie
      Community Hero

      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

       

       

      • Olga_T's avatar
        Olga_T
        SmartBear Alumni (Retired)

        Thanks for the detailed instructions, richie !

        RobertZ , does this approach help? If it does, please accept Richie's reply as a Solution.

        Otherwise, could you please provide more details on what you are currently facing?

        Thanks in advance!