/// <summary> /// The StartTestRun. /// </summary> private void StartTestRun(string environment, string buildNumber) { try { RunFactory testRunFactory = this.Test.RunFactory as RunFactory; this.TestRun = testRunFactory.AddItem($"{environment}_{buildNumber}_{testRunFactory.UniqueRunName}") as Run; } catch (Exception) { throw new CannotStartTestRun(CannotStartTestRun.ErrorMsg + this.Name); } }
/** * set status for a single test and update in QC * * @param TSTest test - the test to be updated * @param string status - "Passed", "Failed", etc. */ public void recordTestResult(TSTest test, string status) { string testInfo = DELIM + DELIM + DELIM + "TestId: " + test.TestId + DELIM + "TestName: " + test.TestName + DELIM + ""; Run lastRun = (Run)test.LastRun; if (lastRun != null) { testInfo += lastRun.Name + DELIM + lastRun.Status; } log.Debug(testInfo); RunFactory runFactory = (RunFactory)test.RunFactory; String date = DateTime.Now.ToString("yyyyMMddhhmmss"); Run run = (Run)runFactory.AddItem("Run" + date); run.Status = status; run.Post(); }
public static bool ExportExecutionDetailsToQC(BusinessFlow bizFlow, ref string result, PublishToALMConfig publishToALMConfig = null) { result = string.Empty; if (bizFlow.ExternalID == "0" || String.IsNullOrEmpty(bizFlow.ExternalID)) { result = GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + ": " + bizFlow.Name + " is missing ExternalID, cannot locate QC TestSet without External ID"; return(false); } try { //get the BF matching test set TestSet testSet = ImportFromQC.GetQCTestSet(bizFlow.ExternalID);//bf.externalID holds the TestSet TSTests collection id if (testSet != null) { //get the Test set TC's List <TSTest> qcTSTests = ImportFromQC.GetTSTestsList(testSet); //list of TSTest's on main TestSet in TestLab //get all BF Activities groups ObservableList <ActivitiesGroup> activGroups = bizFlow.ActivitiesGroups; if (activGroups.Count > 0) { foreach (ActivitiesGroup activGroup in activGroups) { if ((publishToALMConfig.FilterStatus == FilterByStatus.OnlyPassed && activGroup.RunStatus == eActivitiesGroupRunStatus.Passed) || (publishToALMConfig.FilterStatus == FilterByStatus.OnlyFailed && activGroup.RunStatus == eActivitiesGroupRunStatus.Failed) || publishToALMConfig.FilterStatus == FilterByStatus.All) { TSTest tsTest = null; //go by TC ID = TC Instance ID tsTest = qcTSTests.Where(x => x.TestId == activGroup.ExternalID && x.ID == activGroup.ExternalID2).FirstOrDefault(); if (tsTest == null) { //go by Linked TC ID + TC Instance ID tsTest = qcTSTests.Where(x => ImportFromQC.GetTSTestLinkedID(x) == activGroup.ExternalID && x.ID == activGroup.ExternalID2).FirstOrDefault(); } if (tsTest == null) { //go by TC ID tsTest = qcTSTests.Where(x => x.TestId == activGroup.ExternalID).FirstOrDefault(); } if (tsTest != null) { //get activities in group List <Activity> activities = (bizFlow.Activities.Where(x => x.ActivitiesGroupID == activGroup.Name)).Select(a => a).ToList(); string TestCaseName = PathHelper.CleanInValidPathChars(tsTest.TestName); if ((publishToALMConfig.VariableForTCRunName == null) || (publishToALMConfig.VariableForTCRunName == string.Empty)) { String timeStamp = DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss"); publishToALMConfig.VariableForTCRunName = "GingerRun_" + timeStamp; } RunFactory runFactory = (RunFactory)tsTest.RunFactory; Run run = (Run)runFactory.AddItem(publishToALMConfig.VariableForTCRunNameCalculated); // Attach ActivityGroup Report if needed if (publishToALMConfig.ToAttachActivitiesGroupReport) { if ((activGroup.TempReportFolder != null) && (activGroup.TempReportFolder != string.Empty) && (System.IO.Directory.Exists(activGroup.TempReportFolder))) { //Creating the Zip file - start string targetZipPath = System.IO.Directory.GetParent(activGroup.TempReportFolder).ToString(); string zipFileName = targetZipPath + "\\" + TestCaseName.ToString() + "_GingerHTMLReport.zip"; if (!System.IO.File.Exists(zipFileName)) { ZipFile.CreateFromDirectory(activGroup.TempReportFolder, zipFileName); } else { System.IO.File.Delete(zipFileName); ZipFile.CreateFromDirectory(activGroup.TempReportFolder, zipFileName); } System.IO.Directory.Delete(activGroup.TempReportFolder, true); //Creating the Zip file - finish //Attaching Zip file - start AttachmentFactory attachmentFactory = (AttachmentFactory)run.Attachments; TDAPIOLELib.Attachment attachment = (TDAPIOLELib.Attachment)attachmentFactory.AddItem(System.DBNull.Value); attachment.Description = "TC Ginger Execution HTML Report"; attachment.Type = 1; attachment.FileName = zipFileName; attachment.Post(); //Attaching Zip file - finish System.IO.File.Delete(zipFileName); } } //create run with activities as steps run.CopyDesignSteps(); run.Post(); StepFactory stepF = run.StepFactory; List stepsList = stepF.NewList(""); //int i = 0; int index = 1; foreach (Step step in stepsList) { //search for matching activity based on ID and not order, un matching steps need to be left as No Run int stepDesignID = (stepsList[index]).Field("ST_DESSTEP_ID"); Activity matchingActivity = activities.Where(x => x.ExternalID == stepDesignID.ToString()).FirstOrDefault(); if (matchingActivity != null) { switch (matchingActivity.Status) { case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed: step.Status = "Failed"; List <IAct> failedActs = matchingActivity.Acts.Where(x => x.Status == Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed).ToList(); string errors = string.Empty; foreach (Act act in failedActs) { errors += act.Error + Environment.NewLine; } step["ST_ACTUAL"] = errors; break; case Amdocs.Ginger.CoreNET.Execution.eRunStatus.NA: step.Status = "N/A"; step["ST_ACTUAL"] = "NA"; break; case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed: step.Status = "Passed"; step["ST_ACTUAL"] = "Passed as expected"; break; case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped: //step.Status = "No Run"; step.Status = "N/A"; step["ST_ACTUAL"] = "Skipped"; break; case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Pending: step.Status = "No Run"; step["ST_ACTUAL"] = "Was not executed"; break; case Amdocs.Ginger.CoreNET.Execution.eRunStatus.Running: step.Status = "Not Completed"; step["ST_ACTUAL"] = "Not Completed"; break; } } else { //Step not exist in Ginger so left as "No Run" unless it is step data if (step.Name.ToUpper() == "STEP DATA") { step.Status = "Passed"; } else { step.Status = "No Run"; } } step.Post(); index++; } //get all execution status for all steps ObservableList <string> stepsStatuses = new ObservableList <string>(); foreach (Step step in stepsList) { stepsStatuses.Add(step.Status); } //update the TC general status based on the activities status collection. if (stepsStatuses.Where(x => x == "Failed").Count() > 0) { run.Status = "Failed"; } else if (stepsStatuses.Where(x => x == "No Run").Count() == stepsList.Count || stepsStatuses.Where(x => x == "N/A").Count() == stepsList.Count) { run.Status = "No Run"; } else if (stepsStatuses.Where(x => x == "Passed").Count() == stepsList.Count || (stepsStatuses.Where(x => x == "Passed").Count() + stepsStatuses.Where(x => x == "N/A").Count()) == stepsList.Count) { run.Status = "Passed"; } else { run.Status = "Not Completed"; } run.Post(); } else { //No matching TC was found for the ActivitiesGroup in QC result = "Matching TC's were not found for all " + GingerDicser.GetTermResValue(eTermResKey.ActivitiesGroups) + " in QC/ALM."; } } } } else { //No matching Test Set was found for the BF in QC result = "No matching Test Set was found in QC/ALM."; } } if (result == string.Empty) { result = "Export performed successfully."; return(true); } else { return(false); } } catch (Exception ex) { result = "Unexpected error occurred- " + ex.Message; Reporter.ToLog(eLogLevel.ERROR, "Failed to export execution details to QC/ALM", ex); //if (!silentMode) // Reporter.ToUser(eUserMsgKey.ErrorWhileExportingExecDetails, ex.Message); return(false); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { try { TDConnection tdConn = new TDConnection(); tdConn.InitConnectionEx(qcUrl.Text); tdConn.ConnectProjectEx(qcDomain.Text, qcProject.Text, qcLogin.Text, qcPassword.Password); //MessageBox.Show((string)qcUrl.Text); //MessageBox.Show((string)qcDomain.Text); //MessageBox.Show((string)qcProject.Text); //MessageBox.Show((string)qcLogin.Text); //MessageBox.Show((string)qcPassword.Password); //MessageBox.Show((string)qcDomain.Text); //MessageBox.Show((string)testFolder.Text); //MessageBox.Show((string)testSet.Text); //RunFactory runFactory = (RunFactory)test.RunFactory;// //string testFolder = "^" + @"Root\MULTUM\Monthly Testing\SDK v4\"; //string testSet = "BNF SDKv4 Server and Update"; TestSetFactory tsFactory = (TestSetFactory)tdConn.TestSetFactory; TestSetTreeManager tsTreeMgr = (TestSetTreeManager)tdConn.TestSetTreeManager; TestSetFolder tsFolder = (TestSetFolder)tsTreeMgr.get_NodeByPath(testFolder.Text); TDAPIOLELib.List tsList = (TDAPIOLELib.List)tsFolder.FindTestSets((string)testSet.Text, false, null); //TDAPIOLELib.List tsTestList = tsFactory.NewList(""); //List tsList = tsFolder.FindTestSets(testSet, false, "status=No Run"); //Feature\Multum\Black Box\Monthly Testing\SDK v4 foreach (TestSet testset in tsList) { Console.WriteLine("Test Set Folder Path: {0}", testFolder); Console.WriteLine("Test Set: {0}", testset.Name); TestSetFolder tsfolder = (TestSetFolder)testset.TestSetFolder; //string testFolder = "^" + @"Root\MULTUM\Monthly Testing\SDK v4\"; TSTestFactory tsTestFactory = (TSTestFactory)testset.TSTestFactory; TDAPIOLELib.List tsTestList = tsTestFactory.NewList(""); //} foreach (TSTest tsTest in tsTestList)//no such interface supported { Console.WriteLine("Test Set: {0}", tsTest.Name); //Console.ReadLine(); string status = (string)tsTest.Status; Console.WriteLine("STATUS {0}", status); //Console.WriteLine("PARAMS {0}",tsTest.Params); Console.WriteLine("PARAMS {0}", tsTest.History); TDAPIOLELib.Run lastRun = (TDAPIOLELib.Run)tsTest.LastRun; // don't update test if it may have been modified by someone else if (lastRun == null) { RunFactory runFactory = (RunFactory)tsTest.RunFactory; TDAPIOLELib.List runs = runFactory.NewList(""); Console.WriteLine("test runs: {0}", runs.Count); String date = DateTime.Now.ToString("MM-dd_hh-mm-ss"); TDAPIOLELib.Run run = (TDAPIOLELib.Run)runFactory.AddItem("Run_" + date); //Run_5-23_14-49-52 var oRunInstance = (RunFactory)tsTest.RunFactory; //var oRun = (Run)oRunInstance.AddItem("Performance Test"); //run.Status = "Passed"; //run.Post(); //run.Refresh(); var oTest = (Test)tsTest.Test; var tsDesignStepList = oTest.DesignStepFactory.NewList(""); var oStepFactory = (StepFactory)run.StepFactory; foreach (DesignStep oDesignStep in tsDesignStepList) { var oStep = (Step)oStepFactory.AddItem(oDesignStep.StepName); //oStep.Status = "Passed"; //oStep.Post(); } } } } tdConn.DisconnectProject(); tdConn.Disconnect(); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); } }
public int Create( int TestSetId, int TestConfigId, TestStatus Status, string RunName, bool DraftRun, string[] Additional = default(string[])) { int runId = 0; try { if (!Connect(ServerUrl, Username, Password, Domain, Project)) { return(0); } if (!CanPerformAction("ac_run_manual_test")) { rr.AddErrorLine("Error: The user does not have permission to execute tests"); return(0); } string runStatus = NormalizeTestStatus(Status); TestSetFactory tsFact = tdc.TestSetFactory; TestSet targetTestSet = tsFact[TestSetId]; TSTestFactory tsTestFactory = targetTestSet.TSTestFactory; TDFilter filter = tsTestFactory.Filter; filter["TC_TEST_CONFIG_ID"] = TestConfigId.ToString(); List testInstanceList = filter.NewList(); if (testInstanceList.Count == 1) { TSTest testInstance = testInstanceList[1]; RunFactory runFact = testInstance.RunFactory; //Best practice is to provide a null value, but an ALM bug keeps the test status of the test instance unchanged unless a name is provided Run testRun = runFact.AddItem(RunName + "_" + DateTime.Now); testRun.Status = runStatus; if (DraftRun) { testRun["RN_DRAFT"] = "Y"; } //Set additional field values if (Additional != default(string[])) { foreach (string fieldPair in Additional) { string[] tempFieldArray = fieldPair.Split(new[] { ";;" }, StringSplitOptions.None); testRun[tempFieldArray[0]] = tempFieldArray[1]; } } testRun.Post(); runId = testRun.ID; //Console.Out.WriteLine(runId); } else if (testInstanceList.Count == 0) { rr.AddErrorLine("Error: The test configuration ID does not exist in the test set."); } else { //More than one instace of the test configuration exists in the test set //The integration cannot support duplicates rr.AddErrorLine("Error: multiple instances of the test configuration exist in this test set."); } } catch (COMException ce) { rr.AddErrorLine(HandleException(ce)); } finally { Disconnect(); } return(runId); }
public bool Run(TDConnectionClass tdConn, TestSet RunSet, string configPath) { try { //Console.WriteLine("Test run from Interface of IRunTest!"); AutoLog.Info("[CP Run]Test run from IRunTest: " + RunSet.Name); //Debug.Print("PAS: Test run from Interface of IRunTest!"); //Console.Out.WriteLine("----------[CP Run]Test run from IRunTest: " + RunSet.Name); TestConfigFile tConfig = new TestConfigFile(); bool success = false; //AutoLog.Info("[CP Run]Configuration file path: " + configPath); success = TestUtility.LoadConfigFile(ref tConfig, configPath); if (!success) { AutoLog.Info("[CP Run]Load Configuration file failed."); return(true); } // invoke the test execution TSTestFactory TSTestFact = RunSet.TSTestFactory as TSTestFactory; List runList = new List(); runList = TSTestFact.NewList("") as List; foreach (TSTest instance in runList) { //generate the run first RunFactory runFact = instance.RunFactory as RunFactory; DateTime now = DateTime.Now; Run instanceRun = runFact.AddItem("Run_" + now.ToShortDateString() + "_" + now.ToShortTimeString()) as Run; QCOperation.QCInformation info = new QCOperation.QCInformation(); // string runID = instanceRun.ID as string; //Initial the start status info.SetTestRunStatus(tdConn, instanceRun.ID.ToString(), "Not Completed"); //Add the run steps //info.SetTestRunStep(tdConn, runID, "Step 1", "Passed"); //info.SetTestRunStep(tdConn, runID, "Step 2", "Failed"); //Update the end status //info.SetTestRunStatus(tdConn, runID, "Failed"); //Download test case attachments string caseID = instance.TestId as string; ArrayList attachments = new ArrayList(); QCOperation.QCAttachment taa = new QCOperation.QCAttachment(); foreach (string downfile in tConfig.RunParameter.DownloadFile) { attachments.Add(taa.DownloadAttachment(tdConn, "TEST", caseID, downfile, @"C:\CSAutoTest\Temp")); } //When finish the test, record the summary in instance of testset string instanceID = instance.ID as string; string scriptFilename = null; string dataFilename = null; for (int i = 0; i < attachments.Count; i++) { ArrayList downList = attachments[i] as ArrayList; if (downList.Count > 0) { foreach (Object fileObj in downList) { string tempFilePath = fileObj as string; if (tempFilePath != null && tempFilePath.EndsWith("cod")) { scriptFilename = tempFilePath; } if (tempFilePath != null && tempFilePath.EndsWith("iod")) { dataFilename = tempFilePath; } } } } //AutoLog.Info("[CP Run]Config value of MacPath: " + tConfig.RunParameter.RemotePath); //AutoLog.Info("[CP Run]Config value of RunMac: " + tConfig.RunParameter.RunRemote.ToString()); if (tConfig.RunParameter.RunRemote) { dataFilename = ReplaceStringInFile(dataFilename, tConfig.RunParameter.RemotePath); } if (scriptFilename != null) { PAS.AutoTest.ScriptRunner.ScriptRunner sr = new PAS.AutoTest.ScriptRunner.ScriptRunner(); PAS.AutoTest.ScriptRunner.ExecuteResult er; //Debug.Print("PAS: Script file name: {0}", scriptFilename); //Debug.Print("PAS: Data file name: {0}", dataFilename); //Console.Out.WriteLine("----------[CP Run]Script file name: " + scriptFilename); AutoLog.Info("[CP Run]Script file name: " + scriptFilename); AutoLog.Info("[CP Run]Data file name: " + dataFilename); if (dataFilename != null) { er = sr.Run(scriptFilename, dataFilename, 1200); } else { er = sr.Run(scriptFilename, string.Empty, 1200); } switch (er.Result) { case PAS.AutoTest.TestData.TestResult.Done: info.SetTestRunStatus(tdConn, instanceRun.ID.ToString(), "Passed"); break; case PAS.AutoTest.TestData.TestResult.Pass: info.SetTestRunStatus(tdConn, instanceRun.ID.ToString(), "Passed"); break; case PAS.AutoTest.TestData.TestResult.Fail: info.SetTestRunStatus(tdConn, instanceRun.ID.ToString(), "Failed"); break; case PAS.AutoTest.TestData.TestResult.Incomplete: info.SetTestRunStatus(tdConn, instanceRun.ID.ToString(), "Not Completed"); break; //default: case PAS.AutoTest.TestData.TestResult.Warning: info.SetTestRunStatus(tdConn, instanceRun.ID.ToString(), "N/A"); break; } if (er.Result != PAS.AutoTest.TestData.TestResult.Incomplete) { info.SetTestInstanceSummary(tdConn, instanceID, tConfig.RunParameter.NumOfPassed, er.Output.Summary.Passed.ToString()); info.SetTestInstanceSummary(tdConn, instanceID, tConfig.RunParameter.NumOfTotal, er.Output.Summary.TotalRun.ToString()); string fileLog = ".log"; fileLog = "TEST_" + caseID + "_" + now.ToShortDateString() + "_" + now.ToShortTimeString() + ".log"; fileLog = ConvertChar(fileLog); er.Output.ConvertToXml(".\\Temp\\" + fileLog); bool uploadSuccess = false; uploadSuccess = taa.UploadAttachment(tdConn, "RUN", instanceRun.ID.ToString(), fileLog, GetCurrentRunDir() + "\\Temp\\"); if (uploadSuccess) { //Debug.Print("PAS: Upload test log sucess!"); //Console.Out.WriteLine("----------[CP Run]Upload test log sucess!"); AutoLog.Info("[CP Run]Upload test log success!"); } else { //Debug.Print("PAS: Upload test log fail!"); //Console.Out.WriteLine("----------[CP Run]Upload test log fail!"); AutoLog.Info("[CP Run]Upload test log fail!"); } } else { //Console.Out.WriteLine("----------[CP Run]Case run status is incomplete!"); AutoLog.Info("[CP Run]Case run status is incomplete!"); } } } } catch (Exception e) { //Debug.Print("PAS: Run test case error!"); //Console.Out.WriteLine("PAS: Run test case error!"); AutoLog.Info("[CP Run]Run test case exception: " + e.Message); } return(true); }
public bool Add(string TestSetFolderPath, string testsetName, string testName, string runName, string status, string _attachmentPath, string _attachmentName, string installogPath, string installlogName, List <RunSteps> steps) { TestSetFactory TestSetFact; TestSetTreeManager tsTreeMgr; TestSetFolder tSetFolder; List lst; TDFilter TestFilter; Run therun; tsTreeMgr = tdconn.TestSetTreeManager as TestSetTreeManager; tSetFolder = tsTreeMgr.Root as TestSetFolder; tSetFolder = tsTreeMgr.get_NodeByPath(TestSetFolderPath) as TestSetFolder; TestSetFact = tSetFolder.TestSetFactory as TestSetFactory; TestFilter = TestSetFact.Filter as TDFilter; TestFilter["CY_CYCLE"] = "'" + testsetName + "'"; lst = TestSetFact.NewList(TestFilter.Text); // list index from 1 TestSet ts = lst[1] as TestSet; TestFilter.Clear(); TSTestFactory tsF = ts.TSTestFactory as TSTestFactory; TestFilter = tsF.Filter as TDFilter; TestFilter["TS_NAME"] = "'" + testName + "'"; TSTest TestInstance = tsF.NewList(TestFilter.Text)[1] as TSTest; RunFactory rf = TestInstance.RunFactory as RunFactory; List runlist = rf.NewList(""); //update run is run exist for (int index = 1; index <= runlist.Count; index++) { therun = runlist[index] as Run; if (therun.Name == runName) { foreach (RunSteps runstep in steps) { runstep.Add(therun); } return(true); } } therun = rf.AddItem(runName) as Run; therun.Status = status; //therun["RN_DURATION"] = duration; therun.Post(); //add run if (File.Exists(_attachmentPath + "\\" + _attachmentName)) { AttachmentFactory attachFact = therun.Attachments as AttachmentFactory; Attachment attachfile; IExtendedStorage extStor; attachfile = attachFact.AddItem(_attachmentName) as Attachment; attachfile.AutoPost = true; extStor = attachFact.AttachmentStorage as IExtendedStorage; extStor.ClientPath = _attachmentPath; extStor.Save(_attachmentName, true); attachfile.Post(); } if (File.Exists(installogPath + "\\" + installlogName)) { AttachmentFactory attachFact = therun.Attachments as AttachmentFactory; Attachment attachfile; IExtendedStorage extStor; attachfile = attachFact.AddItem(installlogName) as Attachment; attachfile.AutoPost = true; extStor = attachFact.AttachmentStorage as IExtendedStorage; extStor.ClientPath = installogPath; extStor.Save(installlogName, true); attachfile.Post(); } therun.AutoPost = true; int count = 0; foreach (RunSteps runstep in steps) { ++count; Console.WriteLine("Uploading step " + count + ":" + runstep.StepName); runstep.Add(therun); } return(true); }
public void UploadResults(TestCase currentTestCase) { string testFolder = Convert.ToString(ExecutionSession.dictCommonData["QCFolder"]); string testSetName = currentTestCase.Category; TestSetFactory tsFactory = (TestSetFactory)qcConnect.TestSetFactory; TestSetTreeManager tsTreeMgr = (TestSetTreeManager)qcConnect.TestSetTreeManager; TestSetFolder tsFolder = (TestSetFolder)tsTreeMgr.get_NodeByPath(testFolder); List tsList = tsFolder.FindTestSets(testSetName, false, null); TestSet testSet = tsList[1]; tsFolder = (TestSetFolder)testSet.TestSetFolder; TSTestFactory tsTestFactory = (TSTestFactory)testSet.TSTestFactory; List tsTestList = tsTestFactory.NewList(""); // And finally, update each test case status: foreach (TSTest tsTest in tsTestList) { if (currentTestCase.TestCaseName == tsTest.Name.Remove(0, 3)) { RunFactory runFactory = (RunFactory)tsTest.RunFactory; List allfields = runFactory.Fields; String browserValue = tsTest["TC_USER_TEMPLATE_10"]; Run lastRun = (Run)tsTest.LastRun; string runName = runFactory.UniqueRunName; RunFactory objRunFactory = tsTest.RunFactory; Run theRun = objRunFactory.AddItem(runName); theRun.Name = runName; theRun.CopyDesignSteps(); StepFactory Step = theRun.StepFactory; List stepList = (List)Step.NewList(""); if (currentTestCase.OverAllResult == OverAllResult.PASS) { theRun.Status = "Passed"; } else { theRun.Status = "Failed"; } theRun.Post(); //Delete current attachment from QC test set test case AttachmentFactory objAttachmentFactory = tsTest.Attachments; var objCurrentAttachments = objAttachmentFactory.NewList(""); for (int objC = 1; objC <= objCurrentAttachments.Count; objC++) { try { objAttachmentFactory.RemoveItem(tsTest.Attachments.NewList("").Item(1).ID); } catch { } } IAttachment objAttachment = objAttachmentFactory.AddItem(DBNull.Value); objAttachment.FileName = currentTestCase.QCHTMLReportPath; objAttachment.Type = 1; objAttachment.Post(); string[] filePaths = System.IO.Directory.GetFiles(currentTestCase.QCScreenShotPath); foreach (string file in filePaths) { objAttachment = objAttachmentFactory.AddItem(DBNull.Value); objAttachment.FileName = file; objAttachment.Type = 1; objAttachment.Post(); } break; } } }
public void UploadResults(TB2.TestCase currentTestCase) { string testFolder = @"Root\WCS 7up Core - 5022\zz Automation\PracticeExecution\Temp_Prashant\QA72_7_31"; string testSetName = currentTestCase.Category; TestSetFactory tsFactory = (TestSetFactory)qcConnect.TestSetFactory; TestSetTreeManager tsTreeMgr = (TestSetTreeManager)qcConnect.TestSetTreeManager; TestSetFolder tsFolder = (TestSetFolder)tsTreeMgr.get_NodeByPath(testFolder); List tsList = tsFolder.FindTestSets(testSetName, false, null); TestSet testSet = tsList[1]; //foreach (TestSet testSet in tsList) //{ tsFolder = (TestSetFolder)testSet.TestSetFolder; TSTestFactory tsTestFactory = (TSTestFactory)testSet.TSTestFactory; List tsTestList = tsTestFactory.NewList(""); // And finally, update each test case status: foreach (TSTest tsTest in tsTestList) { //System.Console.Out.WriteLine("Test Case ID: " + tsTest.ID + ", Test Case Name: " + tsTest.Name + "\n"); if (currentTestCase.TestCaseName == tsTest.Name.Remove(0, 3)) { RunFactory runFactory = (RunFactory)tsTest.RunFactory; List allfields = runFactory.Fields; String browserValue = tsTest["TC_USER_TEMPLATE_10"]; // Console.WriteLine("Browser value : " + browserValue); Run lastRun = (Run)tsTest.LastRun; string runName = runFactory.UniqueRunName; RunFactory objRunFactory = tsTest.RunFactory; Run theRun = objRunFactory.AddItem(runName); theRun.Name = runName; //Get the count of test steps and compare it with the number of steps that were actually executed //and define the Execution status accordinagly theRun.CopyDesignSteps(); StepFactory Step = theRun.StepFactory; List stepList = (List)Step.NewList(""); if (currentTestCase.OverAllResult == OverAllResult.PASS) { theRun.Status = "Passed"; } else { theRun.Status = "Failed"; } theRun.Post(); //Delete current attachment from QC test set test case AttachmentFactory objAttachmentFactory = tsTest.Attachments; objSkipExec: var objCurrentAttachments = objAttachmentFactory.NewList(""); for (int objC = 1; objC <= objCurrentAttachments.Count; objC++) { try { objAttachmentFactory.RemoveItem(tsTest.Attachments.NewList("").Item(1).ID); } catch { } } if (objAttachmentFactory.NewList("").Count > 0) { goto objSkipExec; } IAttachment objAttachment = objAttachmentFactory.AddItem(DBNull.Value); objAttachment.FileName = currentTestCase.HTMLReportPath; objAttachment.Type = 1; objAttachment.Post(); string[] filePaths = System.IO.Directory.GetFiles(currentTestCase.ScreenShotPath); foreach (string file in filePaths) { objAttachment = objAttachmentFactory.AddItem(DBNull.Value); objAttachment.FileName = file; objAttachment.Type = 1; objAttachment.Post(); } break; // } } } }