码迷,mamicode.com
首页 > Web开发 > 详细

上传Test Result和attachment到ALM

时间:2015-10-11 10:09:15      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

之前在HP的时候用ALM,还是很好用的功能很强大的一个测试管理工具,当时用C#依照ALM的API实现了一个上传测试结果的程序,现在贴出来:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using TDAPIOLELib;

namespace ALMConnector
{
    public class ALMConnection
    {
        private TDConnection almConnection;
        private TestSetTreeManager tsTreeMan;
        private TestSetFolder rootFolder;

// 初始化建立到ALM的connection
public ALMConnection(string almURL_) { almConnection = new TDConnection(); almConnection.InitConnectionEx(almURL_); } ~ALMConnection() { // Extremely important to clean up and release resoures when done DisconnectProject(); Logout(); almConnection.ReleaseConnection(); } public string ServerULR { get { return almConnection.ServerURL; } } public string UserName { get { return almConnection.UserName; } } public string DomainName { get { return almConnection.DomainName; } } public string ProjectName { get { return almConnection.ProjectName; } } public TDAPIOLELib.List ProjectList { get { return almConnection.ProjectsList; } } //用户名密码登陆 public void Login(string userName_, string password_) { almConnection.Login(userName_, password_); }
//连接到项目,得到项目的testsuite rootfolder
public void ConnectProject(string domainName_, string projectName_) { if (almConnection.Connected) { almConnection.Connect(domainName_, projectName_); GetRootFolder(); } } //释放connection public void DisconnectProject() { if (almConnection.Connected) { almConnection.Disconnect(); } } //登出 public void Logout() { if (almConnection.LoggedIn) { almConnection.Logout(); } } //获取到testset的folder public bool FindTestSetFolder(string almFolderPath, out TestSetFolder almFolder) { almFolder = (TestSetFolder)tsTreeMan.get_NodeByPath(almFolderPath); return !(almFolderPath == null); } public TestSetFolder GetRootFolder() { if (tsTreeMan == null) { tsTreeMan = (TestSetTreeManager)almConnection.TestSetTreeManager; } if (rootFolder == null) { rootFolder = (TestSetFolder)tsTreeMan.Root; } return rootFolder; } //建立testset public bool CreateTestSet(TestSetFolder targetFolder_, string newTestSetName_, out TestSet testSetInstance_) { List tsList = targetFolder_.FindTestSets(newTestSetName_); if (tsList == null) { TestSetFactory tsFact = targetFolder_.TestSetFactory; TestSet tsNew = tsFact.AddItem(DBNull.Value); tsNew.Name = newTestSetName_; tsNew.Status = "Open"; tsNew.Post(); testSetInstance_ = tsNew; return true; } else if (tsList.Count == 1) { testSetInstance_ = tsList[1]; } else { testSetInstance_ = null; } return false; } //上传测试结果到testset public bool AddTestResultToTestSet(TestSet tsRun, TestResult tsResult) { TSTestFactory tsTestFact = tsRun.TSTestFactory; TSTest newTSTest = tsTestFact.AddItem(tsResult.TestId); newTSTest.Status = tsResult.TestStatus; newTSTest.Post(); return true; } //上传attachment到testset public void UploadAttachmentToTestSet(TestSet tsRun, String reportPath) { TestSet tSet = null; AttachmentFactory attfat = null; Attachment attobj = null; if (File.Exists(reportPath)) { Console.WriteLine("Find Attachment File,Uploading ..."); tSet = tsRun; attfat = tSet.Attachments; attobj = attfat.AddItem(System.DBNull.Value); attobj.FileName = reportPath; attobj.Type = 1; attobj.Post(); } } } }

 

上传Test Result和attachment到ALM

标签:

原文地址:http://www.cnblogs.com/goldenRazor/p/4868836.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!