Storing Data in a CSV or XML fileby Group Public on Friday April 23 2010 @ 13:58:01 (1/1 Points) |
|
| API ↪Reference ✑ Reply ✓ Stick It ✗ Ditch It ⚐ Tag It |
If doing data extraction with TestPlan you will likely need to write data into a file. The DataFile commands offer a simple way to store structured data into a CSV or XML file.
unit.file.CreateDataFile
CreateDataFile can be called to setup the output file.
call unit.file.CreateDataFile with
%Format% csv
%Fields% withvector
One
Two
Three
end
end
set %MyFile% %Return:Value%
Notice Writing file %Return:Path%This will create a CSV file with the three indicated headers. The order specified for the fields here will the order they appear in the file.
xml can also be specified as an output format, in which case the data written will be formatted as XML records.
The name of the resulting file can be obtained from the Return:Path item. If you wish instead to specify a filename then set the Name parameter to the function.
unit.file.WriteDataFile
WriteDataFile is used to write content to the file. There are two ways to write data, with a map or a vector.
Writing With a Vector
In this mode the data written to the file will matched to the fields in CreateDataFile based on order.
call unit.file.WriteDataFile with
%DataFile% %MyFile%
%Record% withvector
1
2
3
end
endWriting with a Map
Using a key value map allows you to reorder the data and to omit values. In this mode each key you specify maps to the name of the field from CreateDataFile. If a field is omitted then the data will be blank in CSV, and simply not written in XML (that is, not specified is different than blank in some formats).
call unit.file.WriteDataFile with
%DataFile% %MyFile%
%Record% with
%Two% 200
%One% 100
end
endHere you can see the order of the fields is not important. Additionally field Three has not been set.
unit.file.CloseDataFile
When you are done writing to the file you should call CloseDataFile.
call unit.file.CloseDataFile with %DataFile% %MyFile% end
TestPlan Storing Data in a CSV or XML file
