Log test result to a file
- 4 years ago
NOTE: You format the string however you need to.
I did the below with commas to use as a way to separate(split) later for
pulling this data for use somewhere else.
The below string contains variables I have set per data collected from the script I ran.//New info for file
resultStr = ""+TFSID+","+T_Result+","+client_version+","+testEnv+","+srtTime+","+stpTime+","+Duration+","+Sys.UserName+","+PCName+","+Sys.OSInfo.Name+","+IEMajorVersion+"\r\n";
//Log.Message(resultStr);
APathFileName1 = "c:\\TCfolders\\TCResults\\TC_Results.txt";
if (aqFile.Exists(APathFileName1))
{
aqFile.WriteToTextFile(APathFileName1, resultStr, aqFile.ctANSI, false);
}
else
{
Log.Message("_TC_Results.txt file not found.");
Log.Message("Creating new file to write to.");
aqFile.Create(APathFileName1);
aqFile.WriteToTextFile(APathFileName1, resultStr, aqFile.ctANSI, false);
}
Once file is created, each time you run the above, it appends to the file for how I
wrote the code above.You want to start with a fresh file, can use the below example code.
function RemoveOldCreateNewReportFiles()
{
var APathFileName1 = "c:\\TCfolders\\TCResults\\TC_Results.txt";
Log.Message(" ");
Log.Message("Running function to delete and create Report files.");
Log.Message(" ");
if(!aqFile.Exists(APathFileName1))
{
aqFile.Create(APathFileName1);
Log.Message("TC_Results.txt did not exist... Creating new file.");
resultStr = "Build,Date,Notes,TestCase,Tester,Verdict\r\n";
aqFile.WriteToTextFile(APathFileName1, resultStr, aqFile.ctANSI, false);
}
else
if(aqFile.Exists(APathFileName1))
{
aqFile.Delete(APathFileName1);
Delay(1000);
aqFile.Create(APathFileName1);
Log.Message("TC_Results.txt existed... Deleted and Recreated new file.");
resultStr = "Build,Date,Notes,TestCase,Tester,Verdict\r\n";
aqFile.WriteToTextFile(APathFileName1, resultStr, aqFile.ctANSI, false);
}
}