public static List <string> GetAllFile(string path) { List <string> fileName = new List <string>(); DirectoryInfo folder = new DirectoryInfo(path); TestRail.LocalTestCase ltc = new TestRail.LocalTestCase(); foreach (FileInfo file in folder.GetFiles("*.feature", SearchOption.AllDirectories)) { fileName.Add(file.DirectoryName + "\\" + file.Name); } return(fileName); }
public bool SyncTestcase(TestRail.TestResult tr, ref TestRail.LocalTestCase ltc, ref TestRail.Case cs, ref TestRail.Suite suite) { bool updateResult = false; if (bTestCaseSyncWithFailedTestCase) { ltc = ltcs.Find(p => p.CaseId == tr.Case_id); cs = tru.GetCaseByCaseId(tr.Case_id); suite = tru.GetSuiteBySuiteId(cs.SuiteId); if (cs.AutomationType == "4" && suite.ProjectId == projectId) //retail project,automated type { if (ltc.Steps.Trim() != cs.Steps.Trim() || ltc.Title.Trim() != cs.Title.Trim()) { //update test case in test rail updateResult = tru.UpdateTestCase(ltc.CaseId, ltc); } } } else { if (tr.Result_status == "Success") { ltc = ltcs.Find(p => p.CaseId == tr.Case_id); cs = tru.GetCaseByCaseId(tr.Case_id); suite = tru.GetSuiteBySuiteId(cs.SuiteId); if (cs.AutomationType == "4" && suite.ProjectId == projectId)//retail project,automated type { if (ltc.Steps.Trim() != cs.Steps.Trim() || ltc.Title.Trim() != cs.Title.Trim()) { //update test case in test rail updateResult = tru.UpdateTestCase(ltc.CaseId, ltc); } } } } return(updateResult); }
public static List <TestRail.LocalTestCase> GetLocalTestCase(string path) { List <TestRail.LocalTestCase> list_localTestCase = new List <TestRail.LocalTestCase>(); // TreeNode lastSection = null; StreamReader sr = new StreamReader(path, Encoding.Default); string line = string.Empty; string suiteName = string.Empty, casePath = string.Empty, lastSectionName = string.Empty, caseId = string.Empty, title = string.Empty, steps = string.Empty; StringBuilder sb = null; bool caseStartFlag = false; while ((line = sr.ReadLine()) != null) { if (line.TrimStart().StartsWith("@caseid:") && !caseStartFlag) //caseid line { sb = new StringBuilder(); string[] tags = line.Split('@'); foreach (string tag in tags) { if (tag.StartsWith("caseid:")) { caseId = tag.Replace("caseid:", string.Empty).Trim(); } } caseStartFlag = true; } else if (line.TrimStart().StartsWith("Scenario:") && caseStartFlag) { title = line.Replace("Scenario:", string.Empty); //if (title == "Validate PinRule table for NewEveryday Visa") //{ //} //else //{ // sb.AppendLine(line.ToString()); //} } else if (line.TrimStart().StartsWith("Scenario Outline:") && caseStartFlag) { title = line.Replace("Scenario Outline:", string.Empty); //if (title == "Validate PinRule table for NewEveryday Visa") //{ //} //else //{ // sb.AppendLine(line.ToString()); //} } else if (!line.TrimStart().StartsWith("#") && !line.TrimStart().StartsWith("@caseid:") && !line.TrimStart().StartsWith("Scenario:") && caseStartFlag) { sb.AppendLine(line.ToString()); } else if (line.TrimStart().StartsWith("@caseid:") && caseStartFlag) { //if (caseId == "1277464") //{ //} TestRail.LocalTestCase tc = new TestRail.LocalTestCase(); steps = sb.ToString(); tc.Title = title; tc.CaseId = caseId; tc.Steps = steps; list_localTestCase.Add(tc); sb.Clear(); //foreach (LocalTestCases tc2 in list_localTestCase) //{ // Console.WriteLine(tc2.CaseID); // Console.WriteLine(tc2.Title); // Console.WriteLine(tc2.Steps); //} string[] tags = line.Split('@'); foreach (string tag in tags) { if (tag.StartsWith("caseid:")) { caseId = tag.Replace("caseid:", string.Empty).Trim(); } } // caseStartFlag =false; } } if (line == null && caseId != string.Empty) { TestRail.LocalTestCase tc = new TestRail.LocalTestCase(); tc.Title = title; tc.CaseId = caseId; steps = sb.ToString(); tc.Steps = steps; //Console.WriteLine(tc.CaseID); //Console.WriteLine(tc.Title); //Console.WriteLine(tc.Steps); list_localTestCase.Add(tc); } sr.Close(); sr.Dispose(); return(list_localTestCase); }
public void TestFinished(NUnit.Core.TestResult result) { TestRail.TestResult tr = null; string testType = result.Test.TestType; try { GetTestResult(result, ref tr, ref failureTestCases); //update automation type to specflow after test finished TestRail.Case cse = tru.GetCaseByCaseId(tr.Case_id); if (cse.AutomationType != "4") { tru.UpdateAutomationTypeToSpecFlow(tr.Case_id); } suiteid = tr.Suite_Id; if (result.Test.Categories.Count == 0) { if (result.IsSuccess) { testcaseres.Add(true); } else { testcaseres.Add(false); } results.Add(result.FullName, tr.Result_status.ToString()); caseid = tr.Case_id; } if (!result.IsSuccess) { AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_FailureTestCases.log"), result.FullName); } List <Run> runs = tru.GetRunIdsByProjectNameAndPlanNameAndSuiteId(project, planName, tr.Suite_Id); // List<string> runids = GetTestRunsByPlanNameAndSuiteId(project, planName, tr.Suite_Id, tr.Case_id); #region //if (runname.Trim() == string.Empty) //{ // foreach (Run run in runs) // { // TestRail.Suite suite = null; // TestRail.Case cs = null; // TestRail.LocalTestCase ltc = null; // output = string.Empty; // tr.RunId = run.Id; // if (bAddTestResult) // { // tru.AddTestResult(tr); // } // if (btestCaseSync && result.Test.Categories.Count == 1) // { // bool updateresult = SyncTestcase(tr, ref ltc, ref cs, ref suite); // if (updateresult) // { // string message = "Case update success, " + "Suite:" + suite.SuiteName + ", Case: " + tr.Case_id + ", Title:" + ltc.Title; // AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_CaseUpdate.log"), message); // } // } // } //} //else //{ // foreach (Run run in runs) // { // if (run.RunName == runname.Trim()) // { // TestRail.Suite suite = null; // TestRail.Case cs = null; // TestRail.LocalTestCase ltc = null; // output = string.Empty; // tr.RunId = run.Id; // if (bAddTestResult) // { // tru.AddTestResult(tr); // } // if (btestCaseSync && result.Test.Categories.Count == 1) // { // bool updateresult = SyncTestcase(tr, ref ltc, ref cs, ref suite); // if (updateresult) // { // string message = "Case update success, " + "Suite:" + suite.SuiteName + ", Case: " + tr.Case_id + ", Title:" + ltc.Title; // AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_CaseUpdate.log"), message); // } // } // } // } //} #endregion foreach (Run run in runs) { if (runname.Trim() == string.Empty) { TestRail.Suite suite = null; TestRail.Case cs = null; TestRail.LocalTestCase ltc = null; output = string.Empty; tr.RunId = run.Id; if (bAddTestResult) { tru.AddTestResult(tr); } if (btestCaseSync && result.Test.Categories.Count == 1) { bool updateresult = SyncTestcase(tr, ref ltc, ref cs, ref suite); if (updateresult) { string message = "Case update success, " + "Suite:" + suite.SuiteName + ", Case: " + tr.Case_id + ", Title:" + ltc.Title; AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_CaseUpdate.log"), message); } } } else { if (run.RunName == runname.Trim()) { TestRail.Suite suite = null; TestRail.Case cs = null; TestRail.LocalTestCase ltc = null; output = string.Empty; tr.RunId = run.Id; if (bAddTestResult) { tru.AddTestResult(tr); } if (btestCaseSync && result.Test.Categories.Count == 1) { bool updateresult = SyncTestcase(tr, ref ltc, ref cs, ref suite); if (updateresult) { string message = "Case update success, " + "Suite:" + suite.SuiteName + ", Case: " + tr.Case_id + ", Title:" + ltc.Title; AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_CaseUpdate.log"), message); } } } } } } catch (Exception ex) { caseid = tr.Case_id; string errorMsg = result.FullName + ":\r\n" + "caseid:" + caseid + "\r\n" + ex.Message + "\r\n" + ex.StackTrace + "\r\n"; AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_ErrorMsg.log"), errorMsg); throw ex; } }
public void SuiteFinished(NUnit.Core.TestResult result) { string testType = result.Test.TestType; if (testType == "ParameterizedTest") { finalres = testcaseres[0]; foreach (bool res in testcaseres) { finalres &= res; } TestRail.TestResult tr = new TestRail.TestResult(); tr.Case_id = caseid; if (finalres) { tr.Result_status = "Success"; tr.Result_message = "Final result -Success: \r\n"; } else { tr.Result_status = "Failure"; tr.Result_message = "Final result -Failure: \r\n"; } foreach (KeyValuePair <string, string> res in results) { tr.Result_message += res.Key + ":" + res.Value + "\r\n"; } try { // List<string> runids = GetTestRunsByPlanNameAndSuiteId(project, planName, suiteid, tr.Case_id); List <Run> runs = tru.GetRunIdsByProjectNameAndPlanNameAndSuiteId(project, planName, suiteid); foreach (Run run in runs) { if (runname.Trim() == string.Empty) { tr.RunId = run.Id; if (bAddTestResult) { tru.AddTestResult(tr); } if (btestCaseSync) { TestRail.Suite suite = null; TestRail.Case cs = null; TestRail.LocalTestCase ltc = null; bool updateresult = SyncTestcase(tr, ref ltc, ref cs, ref suite); if (updateresult) { string message = "Case update success, " + "Suite:" + suite.SuiteName + ", Case: " + tr.Case_id + ", Title:" + ltc.Title; AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_CaseUpdate.log"), message); } } } else { if (run.RunName == runname.Trim()) { tr.RunId = run.Id; if (bAddTestResult) { tru.AddTestResult(tr); } if (btestCaseSync) { TestRail.Suite suite = null; TestRail.Case cs = null; TestRail.LocalTestCase ltc = null; bool updateresult = SyncTestcase(tr, ref ltc, ref cs, ref suite); if (updateresult) { string message = "Case update success, " + "Suite:" + suite.SuiteName + ", Case: " + tr.Case_id + ", Title:" + ltc.Title; AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_CaseUpdate.log"), message); } } } } } } catch (Exception ex) { caseid = tr.Case_id; string errorMsg = result.FullName + ":\r\n" + "caseid:" + caseid + "\r\n" + ex.Message + "\r\n" + ex.StackTrace + "\r\n"; AddLog(Path.Combine(logPath, planName, runstarttime + "." + planName + "_ErrorMsg.log"), errorMsg); throw ex; } } results.Clear(); testcaseres.Clear(); }