Ask a Question

Log test result to a file

SOLVED
nedbacan
Contributor

Log test result to a file

Can someone help me, I am having problems figuring how to do the following:

 

Using the following data-driven script which compares the captured text "Moving Average" to the expected result kept in the Stores baseline for each patient that is searched.  The pass result should be that the text match and is shown as "on" for each searched patient.

Questions:

I would like to log the Checkpoint message to a text file to show "Moving Average" is active the select patient and for the log to contain the verification passed string with the checkmark symbol icon in the Type Column.   Can you show me how to add it to the script below? 

 

I would like to show the PatientID for each test result in the log.   (example:  Patient001has Moving Average active)

 

Can the result be added to an existing Word document (TestReport.doc), adding it to a new line after a new break page? 

 

 

//Clicks the 'textboxPatientid' object.
Aliases.browser.pageImagenet.textboxPatientid.Click(44, 9);
//Sets the text KeywordTests.CheckBscan.Variables.PatientID("MaestroPatient") in the 'textboxPatientid' text editor.
Aliases.browser.pageImagenet.textboxPatientid.SetText(Project.Variables.PatientID.Value("MaestroPatient"));
//Clicks the 'buttonAll' button.
Aliases.browser.pageImagenet.buttonAll.ClickButton();
//Clicks the 'cell' object.
Aliases.browser.pageImagenet.cell.Click(93, 11);
//Simulates a left-button double click in a window or control as specified (relative position, shift keys).
Aliases.browser.pageImagenet.panel.DblClick(60, 72);
//Waits until the browser loads the page and is ready to accept user input.
Aliases.browser.pageExam.Wait();
//Clicks the 'vgSvgslice0' object with the right mouse button.
Aliases.browser.pageExam.vgSvgslice0.ClickR(456, 155);
//Clicks the 'textnodeProcessingmovingaverage' object.
Aliases.browser.pageExam.textnodeProcessingmovingaverage.Click(40, 18);

//Clicks the 'vgSvgslice0' object with the right mouse button.
Aliases.browser.pageExam.vgSvgslice0.ClickR(456, 155);
//Clicks the 'textnodeProcessingmovingaverage' object.
Aliases.browser.pageExam.textnodeProcessingmovingaverage.Click(40, 18);
//Checks whether the 'contentText' property of the NameMapping.Sys.browser.pageExam.panelResult.panel object equals 'Moving Average
aqObject.CheckProperty(NameMapping.Sys.browser.pageExam.panelResult.panel, "contentText", cmpEqual, "Moving Average\nClose\nON\n0");

 

Thank you for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
jkrolczy
Frequent Contributor

Re: Log test result to a file

 

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);
}
}

JamesK

View solution in original post

3 REPLIES 3
Marsha_R
Community Hero

Re: Log test result to a file

 You can certainly write to a file from TC

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfile/writetotextfile.htm...

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqtextfile/index.html

 

You can have a string variable to collect your information in for each pass of the test and then log it to your file each time the test does a loop.  This option will not get you the icon out of the TC log.

 

I know others have taken a different approach which is to export the TC log at the end of the test run and pick apart the HTML to get the needed information.  

https://support.smartbear.com/testcomplete/docs/testing-with/log/working-with/exporting/index.html#h...

nedbacan
Contributor

Re: Log test result to a file

Can you elaborate on your comment ...."You can have a string variable to collect your information in for each pass of the test and then log it to your file each time the test does a loop. "

 

Can you show an example?

jkrolczy
Frequent Contributor

Re: Log test result to a file

 

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);
}
}

JamesK

View solution in original post

cancel
Showing results for 
Search instead for 
Did you mean: