public string saveToFile(string path, String name) { if (path == null || path.Length == 0) { path = Environment.CurrentDirectory; } testsuite ts = tree[0]; List <object> items = ts.Items; //save to one file ts.SaveToFile(path + "/" + name + "_" + this.tc_cnt(ts) + ".xml"); //save to many files //for (int i = 0; i < items.Count; i++) //{ // ts.Items = new List<object>(); // string name=((testsuite)items[i]).name; // ts.Items.Add(items[i]); // name=name.Replace("/","").Replace("\\", ""); // name = path + "/" + i + "_" + name + "_" + this.tc_cnt((testsuite)items[i]) + ".xml"; // log.AppendLine(name); // ts.SaveToFile(name); //} return(path); }
/// <summary> /// converts all data from the test resutls in to the Junit xml format and writes the xml file to disk. /// </summary> /// <param name="results"></param> public void CreateXmlFromRunResults(TestSuiteRunResults results) { _testSuites = new testsuites(); testsuite ts = new testsuite { errors = results.NumErrors.ToString(), tests = results.NumTests.ToString(), failures = results.NumFailures.ToString(), name = results.SuiteName, package = ClassName }; foreach (TestRunResults testRes in results.TestRuns) { testcase tc; if (testRes.TestType == TestType.LoadRunner.ToString()) { tc = CreateXmlFromLRRunResults(testRes); } else { tc = CreateXmlFromUFTRunResults(testRes); } ts.AddTestCase(tc); } _testSuites.AddTestsuite(ts); if (File.Exists(XmlName)) File.Delete(XmlName); using (Stream s = File.OpenWrite(XmlName)) { _serializer.Serialize(s, _testSuites); } }
public testlink(ILog log) { this.log = log; tree[0] = new testsuite(); apikey = ConfigurationManager.AppSettings["tl_apikey"]; uri = ConfigurationManager.AppSettings["tl_xmlrpc_url"]; // testsuite template = testsuite.LoadFromFile(Environment.CurrentDirectory + "\\template.xml"); }
/// <summary> /// converts all data from the test results in to the Junit xml format and writes the xml file to disk. /// </summary> /// <param name="results"></param> public bool CreateXmlFromRunResults(TestSuiteRunResults results, out string error) { error = string.Empty; _testSuites = new testsuites(); testsuite uftts = new testsuite { errors = IntToString(results.NumErrors), tests = IntToString(results.NumTests), failures = IntToString(results.NumFailures), name = results.SuiteName, package = ClassName, time = DoubleToString(results.TotalRunTime.TotalSeconds) }; foreach (TestRunResults testRes in results.TestRuns) { if (testRes.TestType == TestType.LoadRunner.ToString()) { testsuite lrts = CreateXmlFromLRRunResults(testRes); _testSuites.AddTestsuite(lrts); } else { testcase ufttc = CreateXmlFromUFTRunResults(testRes); uftts.AddTestCase(ufttc); } } if (uftts.testcase.Length > 0) { _testSuites.AddTestsuite(uftts); } try { if (File.Exists(XmlName)) { File.Delete(XmlName); } using (Stream s = File.OpenWrite(XmlName)) { _serializer.Serialize(s, _testSuites); } return(File.Exists(XmlName)); } catch (Exception ex) { error = ex.Message; return(false); } }
public void Serialize(IEnumerable <object> dataObjects) { testsuite suite = MapToTestSuite(dataObjects); XmlSerializer serializer = new XmlSerializer(typeof(testsuite)); var fileStream = new FileStream(_path, FileMode.Create); var textWriter = new StreamWriter(fileStream, Encoding.GetEncoding(1250)); serializer.Serialize(textWriter, suite); textWriter.Close(); }
private testsuite MapToTestSuite(IEnumerable <object> dataObjects) { testsuite suite = new testsuite(); suite.errors = dataObjects.Count(x => KeywordStatus.Error.ToString().Equals(((Keyword)x).Status)).ToString(); suite.skipped = dataObjects.Count(x => KeywordStatus.Skipped.ToString().Equals(((Keyword)x).Status)).ToString(); suite.tests = dataObjects.Count().ToString(); suite.name = GetSuiteName(dataObjects); suite.testcase = dataObjects.Select(keyword => MapToTestCase((Keyword)keyword)).ToArray(); return(suite); }
private testsuite CreateXmlFromLRRunResults(TestRunResults testRes) { testsuite lrts = new testsuite(); int totalTests = 0, totalFailures = 0, totalErrors = 0; string resultFileFullPath = testRes.ReportLocation + "\\SLA.xml"; if (File.Exists(resultFileFullPath)) { try { XmlDocument xdoc = new XmlDocument(); xdoc.Load(resultFileFullPath); foreach (XmlNode childNode in xdoc.DocumentElement.ChildNodes) { if (childNode.Attributes != null && childNode.Attributes["FullName"] != null) { testRes.TestGroup = testRes.TestPath; testcase lrtc = CreateXmlFromUFTRunResults(testRes); lrtc.name = childNode.Attributes["FullName"].Value; if (childNode.InnerText.ToLowerInvariant().Contains("failed")) { lrtc.status = "fail"; totalFailures++; } else if (childNode.InnerText.ToLowerInvariant().Contains("passed")) { lrtc.status = "pass"; lrtc.error = new error[] { }; } totalErrors += lrtc.error.Length; lrts.AddTestCase(lrtc); totalTests++; } } } catch (System.Xml.XmlException) { } } lrts.name = testRes.TestPath; lrts.tests = totalTests.ToString(); lrts.errors = totalErrors.ToString(); lrts.failures = totalFailures.ToString(); lrts.time = testRes.Runtime.TotalSeconds.ToString(); return lrts; }
private testsuite CreateXmlFromLRRunResults(TestRunResults testRes) { testsuite lrts = new testsuite(); int totalTests = 0, totalFailures = 0, totalErrors = 0; string resultFileFullPath = testRes.ReportLocation + "\\SLA.xml"; if (File.Exists(resultFileFullPath)) { try { XmlDocument xdoc = new XmlDocument(); xdoc.Load(resultFileFullPath); foreach (XmlNode childNode in xdoc.DocumentElement.ChildNodes) { if (childNode.Attributes != null && childNode.Attributes["FullName"] != null) { testRes.TestGroup = testRes.TestPath; testcase lrtc = CreateXmlFromUFTRunResults(testRes); lrtc.name = childNode.Attributes["FullName"].Value; if (childNode.InnerText.ToLowerInvariant().Contains("failed")) { lrtc.status = "fail"; totalFailures++; } else if (childNode.InnerText.ToLowerInvariant().Contains("passed")) { lrtc.status = "pass"; lrtc.error = new error[] { }; } totalErrors += lrtc.error.Length; lrts.AddTestCase(lrtc); totalTests++; } } } catch (System.Xml.XmlException) { } } lrts.name = testRes.TestPath; lrts.tests = totalTests.ToString(); lrts.errors = totalErrors.ToString(); lrts.failures = totalFailures.ToString(); lrts.time = testRes.Runtime.TotalSeconds.ToString(); return(lrts); }
public testsuite addItems(int deep, string id, string summary) { testsuite ts = new testsuite(); ts.name = id; ts.details = summary; ts.node_order = ++node_order[deep]; tree[deep - 1].Items.Add(ts); tree[deep] = ts; for (int i = deep + 1; i < 5; i++) { node_order[i] = 0; } return(ts); }
public int tc_cnt(testsuite ts) { List <object> items = ts.Items; int cnt = 0; for (int i = 0; i < items.Count; i++) { if (items[i] is testsuite) { cnt += tc_cnt((testsuite)items[i]); } else { cnt++; } } return(cnt); }
internal void RemoveTestSuite(string name) { testsuite foundSuite = null; foreach (testsuite s in testsuiteField) { if (s.name == name) { foundSuite = s; break; } } if (foundSuite != null) { testsuiteField.Remove(foundSuite); } }
/// <summary> /// converts all data from the test results in to the Junit xml format and writes the xml file to disk. /// </summary> /// <param name="results"></param> public void CreateXmlFromRunResults(TestSuiteRunResults results) { _testSuites = new testsuites(); testsuite uftts = new testsuite { errors = results.NumErrors.ToString(), tests = results.NumTests.ToString(), failures = results.NumFailures.ToString(), name = results.SuiteName, package = ClassName }; foreach (TestRunResults testRes in results.TestRuns) { if (testRes.TestType == TestType.LoadRunner.ToString()) { testsuite lrts = CreateXmlFromLRRunResults(testRes); _testSuites.AddTestsuite(lrts); } else { testcase ufttc = CreateXmlFromUFTRunResults(testRes); uftts.AddTestCase(ufttc); } } if (uftts.testcase.Length > 0) { _testSuites.AddTestsuite(uftts); } if (File.Exists(XmlName)) { File.Delete(XmlName); } using (Stream s = File.OpenWrite(XmlName)) { _serializer.Serialize(s, _testSuites); } }
private void DeserializeStream(Stream stream) { var serializer = new XmlSerializer(typeof(testsuites)); testsuites suites = (testsuites)serializer.Deserialize(stream); _nativeResult = suites.testsuite[0]; }
private void DeserializeDocument(XmlDocument document) { var reader = new XmlNodeReader(document.DocumentElement); var serializer = new XmlSerializer(typeof(resultType)); testsuites suites = (testsuites)serializer.Deserialize(reader); _nativeResult = suites.testsuite[0]; }
public JUnitXmlSerializer(PackageSource source, string time, string outputFile) { var testSuites = new testsuites(); var testSuite = new testsuite(); testSuite.name = string.Format("DevAudit {0} package source audit.", source.PackageManagerLabel); testSuite.package = "org.ossindex.devaudit"; testSuite.time = time; testSuite.tests = source.Vulnerabilities.Count.ToString(); testSuite.failures = source.Vulnerabilities.Where(v => v.Value.Count > 0).Count().ToString(); testSuite.testcase = new testcase[source.Vulnerabilities.Count]; int tcount = 0; foreach (var pv in source.Vulnerabilities.OrderByDescending(sv => sv.Value.Count(v => v.PackageVersionIsInRange))) { IPackage package = pv.Key; List <IVulnerability> package_vulnerabilities = pv.Value; var tc = new testcase(); tc.name = package.Name; tc.classname = package.Name; tc.assertions = "1"; if (package_vulnerabilities.Count() == 0) { continue; } else if (package_vulnerabilities.Count(v => v.PackageVersionIsInRange) == 0) { continue; } else { var matched_vulnerabilities = package_vulnerabilities.Where(v => v.PackageVersionIsInRange).ToList(); int matched_vulnerabilities_count = matched_vulnerabilities.Count; tc.failure = new failure[matched_vulnerabilities_count]; int c = 0; foreach (var v in matched_vulnerabilities) { failure f = new failure(); f.message = "Package vulnerable"; VulnText.AppendFormat("--[{0}/{1}] ", (c + 1), matched_vulnerabilities_count); VulnText.AppendFormat("{0} ", v.Title.Trim()); PrintAuditResultMultiLineField(2, "Description", v.Description.Trim().Replace("\n", "").Replace(". ", "." + Environment.NewLine)); VulnText.AppendFormat("{0}", string.Join(", ", v.Versions.ToArray())); if (v.CVE != null && v.CVE.Count() > 0) { VulnText.AppendFormat(" --CVE(s): {0}", string.Join(", ", v.CVE.ToArray())); } if (!string.IsNullOrEmpty(v.Reporter)) { VulnText.AppendFormat(" --Reporter: {0} ", v.Reporter.Trim()); } if (!string.IsNullOrEmpty(v.CVSS.Score)) { VulnText.AppendFormat(" --CVSS Score: {0}. Vector: {1}", v.CVSS.Score, v.CVSS.Vector); } if (v.Published != DateTime.MinValue) { VulnText.AppendFormat(" --Date published: {0}", v.Published.ToShortDateString()); } if (!string.IsNullOrEmpty(v.Id)) { VulnText.AppendFormat(" --Id: {0}", v.Id); } if (v.References != null && v.References.Count() > 0) { if (v.References.Count() == 1) { VulnText.AppendFormat(" --Reference: {0}", v.References[0]); } else { VulnText.AppendFormat(" --References:"); for (int i = 0; i < v.References.Count(); i++) { VulnText.AppendFormat(" - {0}", v.References[i]); } } } if (!string.IsNullOrEmpty(v.DataSource.Name)) { VulnText.AppendFormat(" --Provided by: {0}", v.DataSource.Name); } f.Text = VulnText.ToString().Split(Environment.NewLine.ToCharArray()); tc.failure[c++] = f; VulnText.Clear(); } } testSuite.testcase[tcount++] = tc; } testSuites.testsuite = new testsuite[] { testSuite }; XmlSerializer xs = new XmlSerializer(typeof(testsuites)); xs.Serialize(File.CreateText(outputFile), testSuites); }
public void AddTestsuite(testsuite ts) { testsuiteField.Add(ts); }
public int addTestcases(Excel.Worksheet sheet, DefaultTC itc, int row) { itc.InitialTestcase(sheet, row); // testsuite ts=addItems(4,itc.GetCell(DefaultTC.colName.FEATUREID),itc.GetCell(DefaultTC.colName.FEATURE_DESC)); string detail = itc.GetCell(DefaultTC.colName.FEATUREID) + ":" + itc.GetCell(DefaultTC.colName.CASE_DESC); testsuite ts = addItems(4, itc.GetCell(DefaultTC.colName.FEATURE_DESC), detail); string preset = itc.GetCell(DefaultTC.colName.PRESET); List <string> steps = itc.getSteps(); List <string> exp = itc.getExpRsts(); string req = itc.GetCell(DefaultTC.colName.DS_ID); bool can_auto = itc.GetCell(DefaultTC.colName.CAN_AUTO).ToLower().Equals("true"); string importance = itc.GetCell(DefaultTC.colName.PRIORITY).ToLower(); string testtype = itc.GetCell(DefaultTC.colName.TYPE); uint order = 0; while (true) { row++; string c0 = itc.GetSubCase(row, DefaultTC.subColName.ID0); string c1 = itc.GetSubCase(row, DefaultTC.subColName.ID); if (c0.Length != 0 || c1.Length == 0) { row--; return(row); } string c2 = itc.GetSubCase(row, DefaultTC.subColName.SAMPLES); testcase tc = new testcase(); tc.name = c1; tc.externalid = externalid++; tc.internalid = externalid + ""; tc.node_order = order++; tc.version = 1; tc.summary = c2; tc.preconditions = preset; tc.execution_type = (uint)(can_auto ? 2 : 1); if (importance.Length > 5) { tc.importance = Convert.ToUInt32(importance.Substring(5, 1)); } else { tc.importance = 1; } custom_field test_type = new custom_field(); test_type.name = "test_type"; test_type.value = testtype; tc.custom_fields.Add(test_type); //todo 需求没有处理 //string reqs= itc.GetSubCase(row,DefaultTC.subColName.REQ); //requirement rq=new requirement(); //tc.requirements.Add for (int i = 0; i < steps.Count; i++) { step s = new step(); s.actions = steps[i]; s.expectedresults = exp[i]; s.step_number = (uint)(i + 1); s.execution_type = tc.execution_type; tc.steps.Add(s); } ts.Items.Add(tc); } }
private testsuite CreateXmlFromLRRunResults(TestRunResults testRes) { testsuite lrts = new testsuite(); int totalTests = 0, totalFailures = 0, totalErrors = 0; // two LR report files may be generated: RunReport.xml, SLA.xml string lrRunReportFile = Path.Combine(testRes.ReportLocation, "RunReport.xml"); string lrSLAFile = Path.Combine(testRes.ReportLocation, "SLA.xml"); LRRunGeneralInfo generalInfo = new LRRunGeneralInfo(); List <LRRunSLAGoalResult> slaGoals = new List <LRRunSLAGoalResult>(); try { XmlDocument xdoc = new XmlDocument(); XmlElement slaNode = null; if (File.Exists(lrRunReportFile)) { xdoc.Load(lrRunReportFile); // General node var generalNode = xdoc.DocumentElement.SelectSingleNode("General"); if (generalNode != null) { var vUsersNode = generalNode.SelectSingleNode("VUsers") as XmlElement; if (vUsersNode != null) { if (vUsersNode.HasAttribute("Count")) { int vUsersCount = 0; if (int.TryParse(vUsersNode.Attributes["Count"].Value, out vUsersCount)) { generalInfo.VUsersCount = vUsersCount; } } } } // SLA node slaNode = xdoc.DocumentElement.SelectSingleNode("SLA") as XmlElement; } else if (File.Exists(lrSLAFile)) { xdoc.Load(lrSLAFile); slaNode = xdoc.DocumentElement; } if (slaNode != null) { var slaGoalNodes = slaNode.SelectNodes("SLA_GOAL"); if (slaGoalNodes != null) { foreach (var slaGoalNode in slaGoalNodes) { var slaGoalElement = slaGoalNode as XmlElement; if (slaGoalElement != null) { slaGoals.Add(new LRRunSLAGoalResult { TransactionName = slaGoalElement.GetAttribute("TransactionName"), Percentile = slaGoalElement.GetAttribute("Percentile"), FullName = slaGoalElement.GetAttribute("FullName"), Measurement = slaGoalElement.GetAttribute("Measurement"), GoalValue = slaGoalElement.GetAttribute("GoalValue"), ActualValue = slaGoalElement.GetAttribute("ActualValue"), Status = slaGoalElement.InnerText }); } } } } } catch (XmlException) { } lrts.name = testRes.TestPath; // testsuite properties lrts.properties = new property[] { new property { name = "Total vUsers", value = IntToString(generalInfo.VUsersCount) } }; double totalSeconds = testRes.Runtime.TotalSeconds; lrts.time = DoubleToString(totalSeconds); // testcases foreach (var slaGoal in slaGoals) { testcase tc = new testcase { name = slaGoal.TransactionName, classname = slaGoal.FullName + ": " + slaGoal.Percentile, report = testRes.ReportLocation, type = testRes.TestType, time = DoubleToString(totalSeconds / slaGoals.Count) }; switch (slaGoal.Status.Trim().ToLowerInvariant()) { case "failed": case "fail": tc.status = "fail"; tc.AddFailure(new failure { message = string.Format("The goal value '{0}' does not equal to the actual value '{1}'", slaGoal.GoalValue, slaGoal.ActualValue) }); totalFailures++; break; case "error": case "err": tc.status = "error"; tc.AddError(new error { message = testRes.ErrorDesc }); totalErrors++; break; case "warning": case "warn": tc.status = "warning"; break; default: tc.status = "pass"; break; } lrts.AddTestCase(tc); totalTests++; } lrts.tests = IntToString(totalTests); lrts.errors = IntToString(totalErrors); lrts.failures = IntToString(totalFailures); return(lrts); }
/// <summary> /// converts all data from the test results in to the Junit xml format and writes the xml file to disk. /// </summary> /// <param name="results"></param> public void CreateXmlFromRunResults(TestSuiteRunResults results) { _testSuites = new testsuites(); testsuite uftts = new testsuite { errors = results.NumErrors.ToString(), tests = results.NumTests.ToString(), failures = results.NumFailures.ToString(), name = results.SuiteName, package = ClassName }; foreach (TestRunResults testRes in results.TestRuns) { if (testRes.TestType == TestType.LoadRunner.ToString()) { testsuite lrts = CreateXmlFromLRRunResults(testRes); _testSuites.AddTestsuite(lrts); } else { //Console.WriteLine("CreateXmlFromRunResults, UFT test"); testcase ufttc = CreateXmlFromUFTRunResults(testRes); uftts.AddTestCase(ufttc); } } if (uftts.testcase.Length > 0) { //Console.WriteLine("CreateXmlFromRunResults, add test case to test suite"); _testSuites.AddTestsuite(uftts); } else { //Console.WriteLine("CreateXmlFromRunResults, no uft test case to write"); } if (File.Exists(XmlName)) { //Console.WriteLine("CreateXmlFromRunResults, file exist - delete file"); File.Delete(XmlName); } // else //{ //Console.WriteLine("CreateXmlFromRunResults, file does not exist"); // } using (Stream s = File.OpenWrite(XmlName)) { //Console.WriteLine("CreateXmlFromRunResults, write test results to xml file"); //Console.WriteLine("_testSuites: " + _testSuites.name + " tests: " + _testSuites.tests); //Console.WriteLine("_testSuites: " + _testSuites.ToString()); _serializer.Serialize(s, _testSuites); } //Console.WriteLine("CreateXmlFromRunResults, XmlName: " + XmlName); /*if (File.Exists(XmlName)) * { * Console.WriteLine("CreateXmlFromRunResults, results file was created"); * } else * { * Console.WriteLine("CreateXmlFromRunResults, results file was not created"); * }*/ }