Wednesday, July 31, 2013

Creating a External Log in Telerik Test Studio

The Logs are basically useful in managing the Test Results. Also there is always demand from the manager or stack holders about the execution result of the script. So creating and maintaining the Test Execution Log by automation will enhance the quality of the framework.

The below code will allow you to create a customized Log in Telerik, Notepad, Excel. This log will consists of following:

  1. Total No of Test Steps
  2. Total No of Test Passed
  3. Total No of Test Not Executed
  4. Total No of Test Failed
  5. Also the Result message(eg. exception) can be shown in Log.  
So all these stuffs are going out by automation. Lets see how.....

Customizing the Log of Telerik: 
These statements will pass the string written under the Log.writeline to the Telerik Log.

Code:
            Log.WriteLine(result.Message);
                                //Write the message of Pass/Fail to the log of telerik
            Log.WriteLine("No of passed steps= "+ result.TotalPassedSteps);
//Shows the Count of Total Passed Steps
            Log.WriteLine("No of Failed steps= "+ result.Totalnotrunsteps);
//Shows the Count of Not Run steps
            Log.WriteLine("Total Steps= "+result.AllTestStepCount);
//Shows the Count of Total steps
*****************************************************************************
Customizing the Log in Notepad
Code:
System.IO.StreamWriter File=new System.IO.StreamWriter("c:\\source.txt");
// StreamWriter writes text files. It enables easy and efficient text output. This statement created the text file //in the specified location
            File.WriteLine(result.message);
            File.WriteLine("Message: "+ result.Message);
            File.WriteLine("Total Pass Steps= "+result.TotalPassedSteps);
            File.WriteLine("Total Fail Steps= "+result.TotalNumberOfNotRunSteps);
            File.WriteLine("Total Steps= "+result.AllTestStepCount);
            File.Close();
        }
*****************************************************************************
Customizing the Log in Excel

Microsoft Office is developed in Object Model. All the Office tools are structured as Object models.
Example: Excel 2010
Creating the application object.
Create the Workbook object by  application object.
Create the worksheet object by Workbook object.
Use the Worksheet object for different actions.

Code:

Microsoft.Office.Interop.Excel.Application excel07=new Microsoft.Office.Interop.Excel.ApplicationClass();
            Microsoft.Office.Interop.Excel.Workbook wb=excel07.Workbooks.Open(path);
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets.get_Item(1);
           
            excel07.Cells[1,1]=("Number of passed steps: ");
            excel07.Cells[2,1]=("Number of Not run steps: ");
            excel07.Cells[3,1]=("Number of fail steps");
            excel07.Cells[4,1]=("Total steps: ");
           
            excel07.Cells[1,2]=Convert.ToString(p);
            excel07.Cells[2,2]=Convert.ToString(nr);
            excel07.Cells[3,2]=Convert.ToString(f);
            excel07.Cells[4,2]=Convert.ToString(t);
            //excel07.Visible=true;

For more information about the Microsoft Excel Objects, Properties , Methods click here

No comments:

Post a Comment