After running my Coded UI tests in Visual Studio 2012 I wanted the test results to be logged to an HTML file. After following this tutorial I was able to achieve this.
Unfortunately, every single test gets its own HTML report at ..\TestResults\<Test Run Folder>\In\<Individual Test Log Folder>\<PC Name>\UITestActionLog.html
, currently I have 3 different individual tests and each gets its own folder at ..\TestResults\<Test Run Folder>\In\
Each resulting HTML file looks like this:
What I want is for all 3 HTML files to be combined into one, and instead of just
> Test 1
it would be like
>Test 1
>Test 2
>Test 3
Is there a way to do this automatically with some configuration options or am I stuck writing a program to merge all of the HTML files myself?
Figured out a solution by myself, wrote a program to take the <div class="g">
nodes from each HTML log and combine them into a single HTML file. Works like a charm.
I've also written my own solution. After spending an hour using the HTML agility pack, and discovering it sometimes break with HTML5 embedded images e.g. ">,<".
I simply wrote a console app that parsed the htmls, and combines into 1:
cmd ActionLogBuilder inputfile's.html outputfile.html
(it's very raw, but works)
static void Main(string[] args)
{
bool only2 = false;
StringBuilder outputFile = new StringBuilder();
if (args.Length == 2)
{
try
{
System.IO.File.Delete(args[1]);
}
catch
{
Console.WriteLine("No file to delete");
}
System.IO.File.Move(args[0], args[1]);
only2 = true;
}
int endArg = args.Length;
Console.WriteLine(endArg.ToString());
int c = 0;
if(!only2)
{
foreach (string a in args)
{
if (c == (endArg - 1))
{
System.IO.TextWriter w = new System.IO.StreamWriter(a);
w.Write(outputFile);
w.Flush();
w.Close();
break;
}
else
{
if (c == 0)
{
using (StreamReader sr = new StreamReader(a))
{
while (sr.Peek() >= 0)
{
string grabLine = sr.ReadLine();
if (grabLine.Contains("<div class=\"test-name\">Coded UI Test Log</div>"))
{
outputFile.AppendLine("<div class=\"test-name\">Test " + (c + 1).ToString() + "</div>");
}
else
{
if (!grabLine.Contains("</body>") | !grabLine.Contains("</html>"))
{
outputFile.AppendLine(grabLine);
}
}
}
}
}
if (c != 0 && c != (endArg - 2))
{
bool notYet = false;
using (StreamReader sr = new StreamReader(a))
{
while (sr.Peek() >= 0)
{
string grabLine = sr.ReadLine();
if (grabLine.Contains("<body>"))
{
notYet = true;
}
if (grabLine.Contains("<div class=\"test-name\">Coded UI Test Log</div>"))
{
outputFile.AppendLine("<div class=\"test-name\">Test " + (c + 1).ToString() + "</div>");
}
else
{
if (notYet)
{
if (!grabLine.Contains("</body>") | !grabLine.Contains("</html>"))
{
outputFile.AppendLine(grabLine);
}
}
}
}
}
}
if (c == (endArg - 2))
{
bool notYet = false;
using (StreamReader sr = new StreamReader(a))
{
while (sr.Peek() >= 0)
{
string grabLine = sr.ReadLine();
if (grabLine.Contains("<body>"))
{
notYet = true;
}
if (notYet)
{
if (grabLine.Contains("<div class=\"test-name\">Coded UI Test Log</div>"))
{
outputFile.AppendLine("<div class=\"test-name\">Test " + (c + 1).ToString() + "</div>");
}
else
{
outputFile.AppendLine(grabLine);
}
}
}
}
}
}
c++;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With