How To: Enable Coded UI Html Logger

24/11/2014

Many of my customers has already build large amount of Tests based on Coded UI, those tests running every build and every day, for a second everything looks just perfect, until a test failed with unexpected exception….

Then we need to understand why? the test failed because the new build broke the test? maybe something wrong with the test?

So the obvious choice is adding logs to Coded UI, Coded UI has some basic logs capabilities, you can use either console, trace and TestContext to write logs inside your Coded UI Tests.

Console.WriteLine("Console Writeline"); Trace.WriteLine("Trace Writeline"); TestContext.WriteLine("TestContext Writeline");

Now, if you didn’t add those logs at the beginning this might be a painful process but you should effort time doing so, other option is using DataCollectors to collect as many relevant information from the application to figure out what happened and try to understand the source of the problem.

By default Coded UI take screenshot on first failure.

image

 

What if you can get full Coded UI log with images for each step, detailed exception information just by adding a single line in your code?

In previous version of Visual Studio (before 2012) you had to specify the Html from configuration files but since Visual Studio 2012 you can enable the Html Trace Log directly from your code.

Just specify the LoggerOverrideState property under PlacbackSettings to HtmlLoggerState.

You don’t have to collect all steps, you can choose the logger level you want.

Playback.PlaybackSettings.LoggerOverrideState = HtmlLoggerState.AllActionSnapshot; //public static class HtmlLoggerState //{ // public const string AllActionSnapshot = "AllActionSnapshot"; // public const string DefaultTraceLevel = "DefaultTraceLevel"; // public const string Disabled = "Disabled"; // public const string ErrorAndWarningOnlySnapshot = "ErrorAndWarningOnlySnapshot"; //}

Html Logger Result:

image 

 

image

Enjoy

Add comment
facebook linkedin twitter email

Leave a Reply