New to Telerik Test Studio Dev EditionStart a free 30-day trial

External Log File

I would like to save the test execution log to an external file on disk.

Solution

Overwrite the OnAfterTestCompleted method for individual tests in order to perform logic on Test Results. See our KB article on Executing Custom Scripts Before/After your Test Run for more information. You can generate a custom log file by using the TestResult class.

We have code samples for two file types:

Text File

C#
    public IList<AutomationStepResult> stepResults { get; set; }
    public override void OnAfterTestCompleted(TestResult result)
    {
        stepResults = result.StepResults;
        
        string passed = Convert.ToString(result.TotalPassedSteps);
        string notRunSteps = Convert.ToString(result.TotalNumberOfNotRunSteps);
        string overall = Convert.ToString(result.Result);
        string resultMessage = Convert.ToString(result.Message);
        
        System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\source.txt");
        
        file.WriteLine(resultMessage);
        file.WriteLine("Number of Passed Steps:"+ passed);
        file.WriteLine("Number of Not Run Steps: "+ notRunSteps);
        file.WriteLine("Total Test Result: "+ overall);
        file.Close();
    }

Finally you'll need to add an Assembly Reference for ArtOfTest.Common.Design. If it is already present, remove it and add it again. Add it from the *Test Studio\Bin* directory:

  • C:\Program Files (x86)\Progress\Test Studio\Bin

Excel File

  • You'll need to add a reference to Microsoft.Office.Interop.Excel.dll. If it isn't already on your machine, ensure you download the version from Microsoft that matches your Office suite.

  • You'll need to create the Excel file on disk first.

C#
    public override void OnAfterTestCompleted(TestResult result)
    {
        string passed = Convert.ToString(result.TotalPassedSteps);
        string notRunSteps = Convert.ToString(result.TotalNumberOfNotRunSteps);
        string overall = Convert.ToString(result.Result);
        
        string resultMessage = Convert.ToString(result.Message);  
        string [] split = resultMessage.Split(new Char [] {'\n'});
                
        Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();           
        string myPath = "C:\\Excel.xlsx";
        Microsoft.Office.Interop.Excel.Workbook workbook = excelApp.Workbooks.Open(myPath);
                
        int idx = 1;
        foreach (string s in split)
        {
            excelApp.Cells[idx, 1] = s;
            idx++;
        }
                
        excelApp.Cells[idx + 1, 1] = ("Number of Passed Steps: " + passed);
        excelApp.Cells[idx + 2, 1] = ("Number of Not Run Steps: " + notRunSteps);
        excelApp.Cells[idx + 3, 1] = ("Total Test Result: " + overall);
        excelApp.Visible = true;
            
        excelApp.ActiveWorkbook.Save();
        workbook.Close(false, Type.Missing, Type.Missing);
        excelApp.Workbooks.Close();
        System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
                
        excelApp.Quit();
        GC.Collect();
        System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
    }
In this article
SolutionText FileExcel File
Not finding the help you need?
Contact Support