コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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();
        }