cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Frequent Visitor

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

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

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

 

 

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 title of the post to something more descriptive? This will help people when searching for problems.
4 REPLIES 4
Moderator

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

Thanks for reaching out, @RobertZ !

 

Community, any ideas of how to accomplish this task?

 


Olga Terentieva
SmartBear Assistant Community Manager

Highlighted
Community Hero

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

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

 

 

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 title of the post to something more descriptive? This will help people when searching for problems.
Moderator

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

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!

 


Olga Terentieva
SmartBear Assistant Community Manager

Moderator

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

Hi all,

Let me mark Richie's reply as a solution at this stage. If RobertZ gets back with another solution later on, we will change it. 

 


Olga Terentieva
SmartBear Assistant Community Manager

New Here?
Join us and watch the welcome video:
Top Kudoed Authors