public bool Attach( int TestSetId, AttachmentType Type, string Path, string Description = default(string), string Name = default(string)) { bool success = false; try { if (!Connect(ServerUrl, Username, Password, Domain, Project)) { return(false); } TestSetFactory tsFact = tdc.TestSetFactory; TestSet tSet = tsFact[TestSetId]; string tSetName = tSet.Name; //Strange ALM bug allows you to select a non existant tet set. Calling name ensures it exists AttachmentFactory attachFact = tSet.Attachments; Attachment attach = attachFact.AddItem(DBNull.Value); attach.FileName = Path; TDAPI_ATTACH_TYPE attachType = TDAPI_ATTACH_TYPE.TDATT_FILE; switch (Type) { case AttachmentType.File: case AttachmentType.file: attachType = TDAPI_ATTACH_TYPE.TDATT_FILE; break; case AttachmentType.URL: case AttachmentType.url: case AttachmentType.Url: attachType = TDAPI_ATTACH_TYPE.TDATT_INTERNET; break; } attach.Type = (int)attachType; if (Description != default(string)) { attach.Description = Description; } //Post will fail if attachment path is bad attach.Post(); if ((Name != default(string)) && (attachType == TDAPI_ATTACH_TYPE.TDATT_FILE)) { attach.Rename(Name); attach.Post(); } success = true; } catch (COMException ce) { //If we get an error, delete the attachment //If the file path is invalid and the attachment never uploads, ALM throws an error but posts the attachment anyways //returning no attachment object. So the only way to detect this is to look for 0 sized attachments and delete them TestSetFactory tsFact = tdc.TestSetFactory; TestSet tSet = tsFact[TestSetId]; AttachmentFactory attachFact = tSet.Attachments; List attachList = attachFact.NewList(""); foreach (Attachment a in attachList) { if (a.FileSizeEx == 0) { attachFact.RemoveItem(a.ID); } } rr.AddErrorLine(HandleException(ce)); } finally { Disconnect(); } return(success); }
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 bool Attach( int RunId, AttachmentType Type, string Path, string Description = default(string), string Name = default(string)) { bool success = false; try { if (!Connect(ServerUrl, Username, Password, Domain, Project)) { return(false); } RunFactory runFact = tdc.RunFactory; Run testRun = runFact[RunId]; //ALM bug allows selection of invalid runid; use name to catch it string runName = testRun.Name; AttachmentFactory attachFact = testRun.Attachments; Attachment attach = attachFact.AddItem(DBNull.Value); attach.FileName = Path; TDAPI_ATTACH_TYPE attachType = TDAPI_ATTACH_TYPE.TDATT_FILE; switch (Type) { case AttachmentType.File: case AttachmentType.file: attachType = TDAPI_ATTACH_TYPE.TDATT_FILE; break; case AttachmentType.URL: case AttachmentType.url: attachType = TDAPI_ATTACH_TYPE.TDATT_INTERNET; break; } attach.Type = (int)attachType; if (Description != default(string)) { attach.Description = Description; } //Post will not fail if attachment is bad (different than attaching to test set) attach.Post(); int attachId = 0; attachId = attach.ID; //Console.Out.WriteLine(attachId); if ((Name != default(string)) && (attachType == TDAPI_ATTACH_TYPE.TDATT_FILE) && attach.ID > 0) { attach.Rename(Name); attach.Post(); } //If the file path is invalid and the attachment never uploads, ALM throws an error but posts the attachment anyways //returning no attachment object. So the only way to detect this is to look for 0 sized attachments and delete them attach.Refresh(); if (attach.FileSize == 0 && attach.Type == (int)TDAPI_ATTACH_TYPE.TDATT_FILE) { attachFact.RemoveItem(attach.ID); success = false; } else { success = true; } } catch (COMException ce) { rr.AddErrorLine(HandleException(ce)); } finally { Disconnect(); } return(success); }
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; // } } } }