TRX to HTML- Ordered Tests

Sep 13, 2011 at 7:49 PM
Edited Sep 13, 2011 at 8:06 PM

I have TRX file which include Ordered Tests. Anyone have solution to convert TRX file in to HTML.

If you have solution or if you know any software application which convert TRX file (this file contains ordered test) to HTML please let us know.

Mar 19, 2012 at 10:14 AM

I have managed to do this by amending the LINQ in the version 85426 TrxParser.cs in the method TrxParser.Parse(string filePath) by replacing:

            string name = doc.Document.Root.Attribute("name").Value;
            string runUser = doc.Document.Root.Attribute("runUser").Value;
            var unitTests = doc.Descendants(ns + "UnitTest").ToList<XElement>();           
            var unitTestResults = doc.Descendants(ns + "UnitTestResult").ToList<XElement>();
            var result = from u in unitTests
                         let id = u.Element(ns + "Execution").Attribute("id").Value
                         let desc = GetSafeValue(u, ns + "Description")
                         let testClass = GetSafeAttrValue(u, ns + "TestMethod", "className")
                         join r in unitTestResults
                         on id equals r.Attribute("executionId").Value
                         orderby testClass
                         select new TestMethodRun
                         {
                             TestClass = testClass,
                             TestMethodName = u.Attribute("name").Value,
                             Description = desc,
                             Status = r.Attribute("outcome").Value,
                             Duration = ParseDuration(r,"duration"),
                             ErrorInfo = ParseErrorInfo(r),
                             ComputerName = r.Attribute("computerName").Value
                         };

 



with the following which has an extra join to test entries to enable the linking of Tests to results where ExecutionID is not held in the unitTest element which is where the problem lies if there is an ordered test.

            string name = doc.Document.Root.Attribute("name").Value;
            string runUser = doc.Document.Root.Attribute("runUser").Value;
            var orderedTests = doc.Descendants(ns + "OrderedTest").ToList<XElement>();
            var testEntries = doc.Descendants(ns + "TestEntry").ToList<XElement>();
            var unitTests = doc.Descendants(ns + "UnitTest").ToList<XElement>();           
            var unitTestResults = doc.Descendants(ns + "UnitTestResult").ToList<XElement>();
            var testResultAggregation = doc.Descendants(ns + "TestResultAggregation").ToList<XElement>();
            var result = from u in unitTests
                         join testEntry in testEntries
                         on u.Attribute("id").Value equals testEntry.Attribute("testId").Value
                         join r in unitTestResults
                         on testEntry.Attribute("executionId").Value equals r.Attribute("executionId").Value
                         orderby GetSafeAttrValue(u, ns + "TestMethod", "className")
                         select new TestMethodRun
                         {
                             TestClass = GetSafeAttrValue(u, ns + "TestMethod", "className"),
                             TestMethodName = u.Attribute("name").Value,
                             Description = GetSafeValue(u, ns + "Description"),
                             Status = r.Attribute("outcome").Value,
                             Duration = ParseDuration(r, "duration"),
                             ErrorInfo = ParseErrorInfo(r),
                             ComputerName = r.Attribute("computerName").Value,
                             Categories = GetCategories(u.Element(ns + "TestCategory")),
                             ParentTestName = GetParentTestName(orderedTests, testEntries, testResultAggregation, GetSafeAttrValue(r, "parentExecutionId"))
                         };

In addition to this I added added another property to TestMethodRun of ParentTestName of type string and added another method to TrxParser class of the below which allows me customise the HTML writer to output results by Ordered test as well as by class

        private string GetParentTestName(List<XElement> OrderedTest, List<XElement> testEntries, List<XElement> testResultAggregation, string ParentExecID)
        {
            if (ParentExecID != "")
            {
                var parentName = from u in OrderedTest
                                 join testEntry in testEntries
                                 on u.Attribute("id").Value equals testEntry.Attribute("testId").Value
                                 join r in testResultAggregation
                                 on testEntry.Attribute("executionId").Value equals r.Attribute("executionId").Value
                                 where r.Attribute("executionId").Value == ParentExecID
                                 select u.Attribute("name").Value;
                return parentName.First();
            }
            return String.Empty;
        }

Its a quick hack but its working for me but hopefully its a starting point for you.

Mar 19, 2012 at 10:24 AM

I missed an extra method i had added which enabled me to categorise my tests and output in the html results. This was done by adding Categories property to TestMethodRun and then adding the method below to the TrxParser.

        private string GetCategories(XElement xElement)
        {
            var categoryElements = xElement.Descendants(ns + "TestCategoryItem").ToList<XElement>(); 
            StringBuilder sb = new StringBuilder();
            for(int i=0;i<categoryElements.Count;i++)
            {
                sb.Append(categoryElements[i].Attribute("TestCategory").Value);
                if (i != categoryElements.Count - 1)
                {
                    sb.Append(",");
                }
            }
            return sb.ToString();
        }