Writing Data on a CSV file


I am currently trying to create a script that will read a value from the SUT then write it on a CSV file. I am trying to use the writedata command but I’m getting this error.

28/5/14 8:46:15 AM	readtext		(174,206,353,256)
	Writedata Actual to item 5 of line n of file filepath
<<< 08:46:15 End handler 1: testcase2 (aborted)
28/5/14 8:46:15 AM	EndTestCase		(Duration:"17.222", Errors:"1", Exceptions:"0", StartTime:"2014-05-28 08:45:58 +0800", Successes:"0", TestCase:"Testcase2.script", Warnings:"0")
28/5/14 8:46:15 AM	FAILURE		Invalid Range Only numeric, date/time, and character ranges are supported.
Execution Time 0:00:17 Testcase2.script

Here’s my script:

Put file "C:/Testcase.csv" into filepath
Set the itemdelimiter to ","
Put 2 into n
Set Actual to ReadText(uprectangle,downrectangle)
Writedata Actual to item 5 of line n of file filepath

Please advise if there is something wrong on how I used the command or if there are some other commands that I can use to handle it. Thanks.

I think there are a number of things going wrong here, but let me explain what’s happening. The primary issue is that there is no “Writedata” command among the built-in commands, so SenseTalk presumes this is a custom command (a script or handler that you are trying to call).

The rest of the line is then interpreted as a range expression, since it fits the format “X to Y” which is valid syntax for a range. In this case, X is Actual and Y is item 5 of line n of file filepath, but these values don’t fit the criteria for a range so you get an Invalid Range exception.

I guess what you want is to use the Put … Into command to store the value of Actual into that particular chunk of your csv file, like this:

put Actual into item 5 of line n of file filepath

If that’s not it, please explain what you’re trying to accomplish in more detail.

Hi Doug,

Thanks for the very detailed explanation of the error. I saw this ‘write’ command at this link http://docs.testplant.com/?q=content/file-socket-process-and-stream-input-and-output so I thought I can use it.

Yes, I believe the ‘put…into’ command is the command that I would want to use in able to achieve my goal on this test script.

However, I am getting this error when I tried your suggestion.

open file "C:\Testcase.csv"
	put Actual into item 5 of line n of file "C:\Testcase.csv" 
<<< 12:28:15 End handler 1: testcase2 (aborted)
28/5/14 12:28:15 PM	EndTestCase		(Duration:"28.514", Errors:"1", Exceptions:"0", StartTime:"2014-05-28 12:27:46 +0800", Successes:"0", TestCase:"Testcase2.script", Warnings:"0")
28/5/14 12:28:16 PM	FAILURE		STFileException Failed to write to file C:/Testcase.csv
Execution Time 0:00:29 Testcase2.script

I already tried to use the ‘open file’ command prior to the ‘put…into’ but still it won’t let me write on the CSV file.

What I want to do is that eggplant will get the values from this CSV file, calculate it using an application, and then write the results on the CSV file. As of this moment, I’m only having problem on the ‘writing’ part.