public static List <ReportMetaData> readReportFromXMLFile(string reportPath) { List <ReportMetaData> listReport = new List <ReportMetaData>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(reportPath); foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) { foreach (XmlNode currentNode in node) { ReportMetaData reportmetadata = new ReportMetaData(); XmlAttributeCollection attributesList = currentNode.Attributes; foreach (XmlAttribute attribute in attributesList) { switch (attribute.Name) { case "name": reportmetadata.setDisplayName(attribute.Value); break; case "status": reportmetadata.setStatus(attribute.Value); break; default: break; } } XmlNodeList nodes = currentNode.ChildNodes; foreach (XmlNode xmlNode in nodes) { if (xmlNode.Name.Equals("system-out")) { reportmetadata.setDateTime(xmlNode.InnerText.Substring(0, 19)); } } listReport.Add(reportmetadata); } } return(listReport); }
public static List <ReportMetaData> readReportFromXMLFile(string reportPath, Dictionary <string, List <ReportMetaData> > testSteps, bool isJUnitReport) { List <ReportMetaData> listReport = new List <ReportMetaData>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(reportPath); foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) //inside <testsuite> node { List <ReportMetaData> steps = new List <ReportMetaData>(); string testName = ""; if (isJUnitReport) { string currentTest = node.Attributes["name"].Value; testName = currentTest.Substring(currentTest.LastIndexOf("-") + 1); } foreach (XmlNode currentNode in node) //inside <testcase> nodes { ReportMetaData reportmetadata = new ReportMetaData(); XmlAttributeCollection attributesList = currentNode.Attributes; foreach (XmlAttribute attribute in attributesList) { switch (attribute.Name) { case "name": reportmetadata.setDisplayName(attribute.Value); break; case "report": reportmetadata.setReportPath(attribute.Value); break; case "status": reportmetadata.setStatus(attribute.Value); break; case "time": reportmetadata.setDuration(attribute.Value); break; default: break; } } if (isJUnitReport) { //remove the number in front of each step string stepName = reportmetadata.getDisplayName(); if (!String.IsNullOrEmpty(stepName)) { if (stepName.StartsWith("#")) { reportmetadata.setDisplayName(stepName.Substring(stepName.IndexOf(":") + 1)); } } } XmlNodeList nodes = currentNode.ChildNodes; foreach (XmlNode xmlNode in nodes)//inside nodes in <testcase> nodes { if (xmlNode.Name.Equals("failure")) { foreach (XmlAttribute attribute in xmlNode.Attributes) { if (attribute.Name.Equals("message")) { reportmetadata.setErrorMessage(attribute.Value); reportmetadata.setStatus("fail"); } } } if (xmlNode.Name.Equals("system-out")) { reportmetadata.setDateTime(xmlNode.InnerText.Substring(0, 19)); } } if (isJUnitReport) { steps.Add(reportmetadata); } listReport.Add(reportmetadata); } if (isJUnitReport) { testSteps.Add(testName, steps); } } return(listReport); }