Prior to the HP time with ALM, or very useful a very powerful test management tool, at that time in C # in accordance with the ALM API implementation of an upload test results of the program, now posted:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.IO;usingTdapiolelib;namespacealmconnector{ Public classalmconnection {Privatetdconnection almconnection; PrivateTestsettreemanager Tstreeman; PrivateTestsetfolder RootFolder;
Initialize the connection built into ALM PublicAlmconnection (stringAlmurl_) {almconnection=Newtdconnection (); Almconnection.initconnectionex (ALMURL_); } ~almconnection () {//extremely important to clean up and release resoures when doneDisconnectproject (); Logout (); Almconnection.releaseconnection (); } Public stringSERVERULR {Get { returnAlmconnection.serverurl; } } Public stringUserName {Get { returnAlmconnection.username; } } Public stringDomainName {Get { returnAlmconnection.domainname; } } Public stringProjectName {Get { returnAlmconnection.projectname; } } Publictdapiolelib.list projectlist {Get { returnalmconnection.projectslist; }}//user name password login Public voidLogin (stringUsername_,stringPassword_) {Almconnection.login (username_, Password_); }
Connect to the project and get the project Testsuite RootFolder Public voidConnectproject (stringDomainname_,stringprojectname_) { if(almconnection.connected) {almconnection.connect (domainname_, projectname_); GetRootFolder (); }}//Release Connection Public voidDisconnectproject () {if(almconnection.connected) {almconnection.disconnect (); }}//Log Out Public voidLogout () {if(Almconnection.loggedin) {almconnection.logout (); }}//get to Testset's folder Public BOOLFindtestsetfolder (stringAlmfolderpath, outTestsetfolder Almfolder) {Almfolder=(Testsetfolder) Tstreeman.get_nodebypath (Almfolderpath); return! (Almfolderpath = =NULL); } PublicTestsetfolder GetRootFolder () {if(Tstreeman = =NULL) {Tstreeman=(Testsettreemanager) Almconnection.testsettreemanager; } if(RootFolder = =NULL) {RootFolder=(Testsetfolder) tstreeman.root; } returnRootFolder; }//Establish Testset Public BOOLCreatetestset (Testsetfolder Targetfolder_,stringNewtestsetname_, outTestset 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; }//upload test results to Testset Public BOOLAddtestresulttotestset (Testset tsrun, TestResult tsresult) {tstestfactory tstestfact=tsrun.tstestfactory; Tstest newtstest=Tstestfact.additem (Tsresult.testid); Newtstest.status=Tsresult.teststatus; Newtstest.post (); return true; }//upload attachment to Testset Public voidUploadattachmenttotestset (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 (); } } }}
Upload test result and attachment to ALM