Write Text Log For Coded Ui Testing in VSTS

How to : Write Text Log For Coded Ui Testing in VSTS

Test Logs are nothing but Results during the Test script run:

Suppose we have a specific scenario of logging into an application ( SignInGlobal in the below discussed case ). In general if we have a successfull Log In we need to maintain a log report that the Scenario has been executed successfully and that the functionality is working fine within the application. Contrarily speaking, in case the scenario/functionality is not working as per the expectation we need the same to be maintained in the log file, so that we can figure out from the Log files after the complete run as to which particular module has failed :

The definition of the below two function calls are available in the UIMap.cs partial class file :

1. SignInGlobal
2. WriteLogs : It is taking two parameters One being the TestC ontext and the other the status message as Failure/Pass.

                this.UIMap.WriteLogs(TestContext, "Logging Into Aplication Event Success");
            catch (PlaybackFailureException e)
                this.UIMap.WriteLogs(TestContext, "Logging Into Aplication Event Failure");

In UiMap.cs Partial class file keep the below function body defined :

 public void WriteLogs(TestContext varTestcontext, string Status)
            string strAppPath = varTestcontext.DataRow["AppPath"].ToString();
            FileInfo f = new FileInfo(strAppPath + "Results.txt");
            StreamWriter w = f.AppendText();
            w.WriteLine("Module : " + Status + " TimeStamp : " + DateTime.Now.ToString());

So this particular function namely WriteLogs will append the current status message in the same file .

This is how we can successfully maintain a Log file for the series of events that are happening during the course of script run.


  1. Hi,
    This is the one I am looking for a long in Coded UI, its really good. But while running my solution, i am getting the object reference error in the below line:
    string strAppPath = varTestcontext.DataRow["AppPath"].ToString();
    Can you help me to fix this issue.

  2. http://csesupport.blogspot.com/2010/10/coded-ui-automation-testing-walkthrough_31.html

    Please go through the below link for gaining insights on how to do data driving of the codedui class file.

    Once you have done this data driving take care of two things.
    One is that copy the address of the directory where you want the result file to be stored.
    once the address is copied paste it in a column named Apppath in the excel sheet.
    RFest all is self explanatroy. I hope that will help you greatly. If you still face issues le me know on it.


Post a Comment

Previous Post Next Post