Combine Coded UI Test HTML Logs?
Asked Answered
T

2

8

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:

enter image description here

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?

Taenia answered 6/6, 2013 at 17:51 Comment(4)
I'd say use this to merge the HTML files, which is what I've used in the past. softsnow.griffin3.com/merger/merger.shtmlBeverage
If the HTML is XHML compliant, you could write a small c# app that iterates through all *.html and uses linq2xml to extract the data.Wino
@taoufik this sounds like it would result in an .XML file, I'd prefer the end result to be a combined .HTML fileTaenia
@StickFigs The mark-up for xml and xhtml is the same. xhtml was created to be compatible with xml, so that you could use xml tools to process it. If the html files are not xhtml compatible, you could use htmlagilitypack.codeplex.com to read themWino
T
3

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.

Taenia answered 24/6, 2013 at 19:3 Comment(1)
Would it be possible to upload that program, It would be really useful to me.Middleoftheroader
A
2

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++;
        }
    }
}
Aigrette answered 20/10, 2013 at 15:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.