Friday, April 22, 2016

Create Log file for Coded UI Tests

Logs containing results and other information helps in debugging the test failures. This post will help you to create a log file for coded UI test in Microsoft Visual Studio 2010.

Suppose there is one coded UI test method CodedUITestMethod1 with one recorded method as SignInTest in UIMap.Designer.cs.

[TestMethod]
public void CodedUITestMethod1()
{
   this.UIMap.SignInTest();
}

To add logs to it, modify partial class UIMap.cs as follows -

public void WriteLogs(string message)
{
  FileInfo f = new FileInfo(strAppPath + "Results.txt");
  StreamWriter w = f.AppendText();
  w.WriteLine(message);
  w.Close();
}

Call this method from test method as follows -

[TestMethod]
public void CodedUITestMethod1()
{
  this.UIMap.SignInTest();
  this.UIMap.WriteLogs("Logging Into Aplication Event Success");
}

Please share your views about this post.

No comments:

Post a Comment