Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
joseph loyzaga Absent Member.
Absent Member.
7074 views

connect to QC using vbs

How can I connect to Qc using vbs where I prompt for the username, password, url/connection name and then receive the project/domain arrays because there may be multiple ones I can connect to and then choose which one (project/domain pair) I want to use? I have the code here that does that with hardcoded values but I want to prompt with vbs - I'm pretty sure I can do most but I don't know how to receive the domain/project values from a connection - can someone show me?

heres the code I have - I can take care of the prompts.....
Option Explicit
Const xlLeft = -4131
Const xlRight = -4152
Const xlCenter = -4108
Const xlGeneral = 1
Dim QCConnection
Set QCConnection = CreateObject("TDApiOle80.TDConnection")
Set oExcel = CreateObject("excel.application")
'oExcel.WindowState = "Minimized"

Var = oExcel.Run ("'C:\Data\MEVI\Resources\UserIDPassword.xls'!mymacro")
'Varrun = Var(1) + "-"+Var(0) +"-"+ Var(2) +"-" + Var(3) + "|" + InputBox("Starting point. Press OK to accept or type new start point. Include Header Row", _
' "Check Point Restart", 2) + "|" + InputBox("Ending point. Press OK to accept or type new end point.", "Check Point Restart", 0)
Environment = Var(0)
Scriptname = Var(1)
Uname = Var(4)
Passwd = Var(5)
AUT = Var(2)
Varfull(MyRow) = Varrun
Varnum = 12

totalvar = 11
Dim sUserName, sPassword
sUserName = "joseph.loyzaga" '<------------------- Change me.
sPassword = "password1" '<--------------------------- Change me.


QCConnection.InitConnectionEx "http://qualitycenter.det.nsw.edu.au:8080/qcbin/" '<------------------- Change me.


QCConnection.Login sUserName, sPassword

If (QCConnection.LoggedIn <> True) Then
MsgBox "QC User Authentication Failed"
WScript.Quit
End If

Dim sDomain, sProject
sDomain = "LEARNING_MANAGEMENT_SYSTEMS" '<-------------------- Change me.
sProject = "TBO_Service" '<-------------------------------- Change me.

QCConnection.Connect sDomain, sProject

If (QCConnection.Connected <> True) Then
MsgBox "QC Project Failed to Connect to " & sProject
WScript.Quit
End If
0 Likes
7 Replies
Knowledge Partner
Knowledge Partner

Re: connect to QC using vbs

If you are logged in the you can use property "VisibleDomains" or "VisibleProjects" of TDConnection object.
See the OTA API manual for details.
0 Likes
joseph loyzaga Absent Member.
Absent Member.

Re: connect to QC using vbs

can you give me an example?
0 Likes
Knowledge Partner
Knowledge Partner

Re: connect to QC using vbs

After "QCConnection.Login sUserName, sPassword" try this:
set listdom = QCConnection.VisibleDomains
msgbox listdom.Count
msgbox listdom.Item(1)
msgbox listdom.Item(2)
...
domname = listdom.Item(1)
set listproj = QCConnection.VisibleProjects(domname)
msgbox listproj.Count
msgbox listproj.Item(1)
msgbox listproj.Item(2)
...

See the OTA API manual.

0 Likes
joseph loyzaga Absent Member.
Absent Member.

Re: connect to QC using vbs

don't have the api
0 Likes
Knowledge Partner
Knowledge Partner

Re: connect to QC using vbs

If you have installed HPQC then you have also OTA API manuals.
Just login to th HPQC go to the Help menu and choose Documentations Library.
0 Likes
Alfred Noel
New Member.

Re: connect to QC using vbs

Set MSExcel = CreateObject("Excel.Application")
Set xlWBook = MSExcel.Workbooks.Open("c:\My.xls")
Set xlSheet = xlWBook.Worksheets("Updates")

RowCounter = 2

Dim MyDur, MyTestSet, MyBrow, MyBuild, MyReg, MyProdVer, MyRel, MyHost, objNet
Dim MyMonth, MyDay, MyHour, MyMin, MySec, MyRun
Set objNet = Createobject ("Wscript.NetWork") ' for Myhost to retrive Host Name (Computer Name)
StartTime = Now()
Do While xlSheet.Cells(RowCounter,5).Value <> ""

usid = xlSheet.Cells(RowCounter,1).Value
password = xlSheet.Cells(RowCounter,2).Value
domain = xlSheet.Cells(RowCounter,3).Value
project = xlSheet.Cells(RowCounter,4).Value

MyTestSet = xlSheet.Cells(RowCounter,6).Value
MyBrow = xlSheet.Cells(RowCounter,7).Value
MyBuild = xlSheet.Cells(RowCounter,8).Value
MyReg = xlSheet.Cells(RowCounter,9).Value
MyProdVer = xlSheet.Cells(RowCounter,10).Value
MyRel = xlSheet.Cells(RowCounter,11).Value

MyHost = objNet.ComputerName

                                MyMonth = Month(Now)
                                MyDay = Day(Now)                
                                MyHour = Hour(Now)
                                MyMin = Minute(Now)
                                MySec = Second(Now)

MyRun = ("Run_" & MyMonth & "-" & MyDay & "_" & MyHour & "-" & MyMin & "-" & MySec)



Set tdc = CreateObject("TDApiOle80.TDConnection")
tdc.InitConnectionEx "http://symqc.prod.fedex.com:7117/qcbin"
tdc.ConnectProjectEx domain,project,usid,password



Set tcTreeMgr = tdc.TestSetTreeManager
Set TestSetFolder = tcTreeMgr.NodeByPath(xlSheet.Cells(RowCounter,5).Value)

'msgbox "Test Path:" & xlSheet.Cells(RowCounter,5).Value & "          Test Set: " & xlSheet.Cells(RowCounter,6).Value

'msgbox "Path Found: " & TestSetFolder.Name

Set TestSetF = TestSetFolder.TestSetFactory                                      'Retreive test from given folder in test lab
Set aTestSetArray = TestSetF.NewList("")
'msgbox "Test Set Count: " & aTestSetArray.count
               For each cTestSet in aTestSetArray                                                                                          
                                
                                           'If cTestSet.Name = MyTestSet Then ' To select perticular Test Set
                                        
                                                Set TestCaseF = cTestSet.TSTestFactory                      'Retreive Test Sets
                                                Set aTestCaseArray = TestCaseF.NewList("")
                                                
                                                For each cTestCase in aTestCaseArray
                                                                                           
                                                                                           If cTestCase("TC_TEST_VERSION") = "1" or  cTestCase("TC_STATUS")="Failed"  or cTestCase("TC_STATUS")="Not Completed" or cTestCase("TC_STATUS")="Passed" Then
                                                                                           'msgbox "TC_TEST_VERSION :: " & cTestCase("TC_TEST_VERSION")
                                                                                           'msgbox "TS_NAME :: " & cTestCase("TS_NAME")
                                                                                           
                                                                                           Else
     
                                                                                                                                Dim runName 'should be the current date time.
                                                                                                                                runName = "Run_" & cTestCase.ID
                                                                                                                                Set RunF = cTestCase.RunFactory                  ' for managing test runs.
                                                                                                                                wait(1)
                                                                                                                                Set theRun = RunF.AddItem(runName)
                                                                                                                                
                                                                                                                                
                                                                                                                                Randomize   ' Initialize random-number generator.
                                                                                                                                MyDur = Int((100 * Rnd) + 44)   ' Generate random value between 44 and 100.
                                                                                                                                'RN_USER_03 - Steps
                                                                                                                                'RN_USER_04 - Failed cause
                                                                                                                                'theRun.field("RN_USER_05") = "My test" 'Comments
'                                                                                                                               theRun.field("RN_USER_01") = MyBrow      'Browser value
                                                                                                                                theRun.field("RN_USER_02") = MyBuild    'Product Build
                                                                                                                                theRun.field("RN_DURATION") = MyDur      'Test Duration random value
                                                                                                                                theRun.field("RN_USER_06") = MyReg       'Region
                                                                                                                                theRun.field("RN_USER_07") = MyProdVer       'Product Version
                                                                                                                                theRun.field("RN_USER_08") = MyRel              'Release
                                                                                                                                theRun.field("RN_RUN_NAME") = MyRun      'Run Name in format Run_1-6_12-55-22
                                                                                                                                theRun.field("RN_HOST") = MyHost                'Host Name (Computer Name
                                                                                                theRun.Status = "Passed"                   'Run Status
                                                                                                                                theRun.CopyDesignSteps
                                                                                                                                theRun.Post
                                                                                                Set runStepF = theRun.StepFactory
                                                                                                                                Set aTestStepArray = runStepF.NewList("")
                                           
                                                                                                                                For Each Item In aTestStepArray
                                           
                                                                                                                                                     Set runStep = Item
                                                                                                                                                     runStep.Status = "Passed"
                                                                                                                                                     runStep.Post
'                                                                                                                                                    runStep.field("ST_EXECUTION_DATE")=date
                                                                                                                                                     'runStep.field("ST_EXECUTION_DATE")="6/15/2014"
                                                                                                                                                     runStep.Post
                                                                                                                                                  
                                                                                                                                Next

                                                                                                     For i=1 to 2
                                                                                                                theRun.field("RN_EXECUTION_DATE") = "6/15/2014" 'Set outer grid execution date
                                                                                                                cTestCase.field("TC_EXEC_DATE")="6/15/2014"
                                                                                                                theRun.Post
                                                                                                                cTestCase.Post
                                                                                                     Next

                                                                                           End if
                                                Next
                                        'End If
                
              Next

           RowCounter = RowCounter + 1
Loop

Set xlSheet = Nothing
Set xlWBook = Nothing
MSExcel.Quit

Set MSExcel = Nothing

tdc.ReleaseConnection
set tdc = Nothing

'Msgbox "Finished! Operation started on " & StartTime & " and completed at " & Now()





0 Likes
Highlighted
Renan Gaspar Trusted Contributor.
Trusted Contributor.

Re: connect to QC using vbs

I added what you need in your code:

 

Option Explicit
Const xlLeft = -4131
Const xlRight = -4152
Const xlCenter = -4108
Const xlGeneral = 1
Dim QCConnection
Set QCConnection = CreateObject("TDApiOle80.TDConnection")
Set oExcel = CreateObject("excel.application")
'oExcel.WindowState = "Minimized"

Var = oExcel.Run ("'C:\Data\MEVI\Resources\UserIDPassword.xls'!mymacro")
'Varrun = Var(1) + "-"+Var(0) +"-"+ Var(2) +"-" + Var(3) + "|" + InputBox("Starting point. Press OK to accept or type new start point. Include Header Row", _
' "Check Point Restart", 2) + "|" + InputBox("Ending point. Press OK to accept or type new end point.", "Check Point Restart", 0)
Environment = Var(0)
Scriptname = Var(1)
Uname = Var(4)
Passwd = Var(5)
AUT = Var(2)
Varfull(MyRow) = Varrun
Varnum = 12

totalvar = 11
Dim sUserName, sPassword
sUserName = "joseph.loyzaga" '<------------------- Change me.
sPassword = "password1" '<--------------------------- Change me.


QCConnection.InitConnectionEx "http://qualitycenter.det.nsw.edu.au:8080/qcbin/" '<------------------- Change me.


QCConnection.Login sUserName, sPassword

If (QCConnection.LoggedIn <> True) Then
MsgBox "QC User Authentication Failed"
WScript.Quit
End If

Dim sDomain, sDomainId, sProject, sProjectId
Dim obj_DomList, obj_ProjList
Dim str_AvaiDomains, str_AvaiProjects
Dim i

'Select the Domain
set obj_DomList = QCConnection.VisibleDomains
i = 1
Do While i <= obj_DomList.Count
str_AvaiDomains = str_AvaiDomains & i & " - " & obj_DomList.Item(i) & VbCrLf
i = i + 1
Loop
sDomainId = InputBox("Please enter the number corresponding to the desired Domain:" & VbCrLf & VbCrLf & str_AvaiDomains, "Select the Domain")
sDomain = obj_DomList.Item(sDomainId)

'Select the Project
set obj_ProjList = QCConnection.VisibleProjects(sDomain)
i = 1
Do While i <= obj_ProjList.Count
str_AvaiProjects = str_AvaiProjects & i & " - " & obj_ProjList.Item(i) & VbCrLf
i = i + 1
Loop
sProjectId = InputBox("Please enter the number corresponding to the desired Project:" & VbCrLf & VbCrLf & str_AvaiProjects, "Select the Project")
sProject = listproj.Item(sProjectId)


QCConnection.Connect sDomain, sProject

If (QCConnection.Connected <> True) Then
MsgBox "QC Project Failed to Connect to " & sProject
WScript.Quit
End If

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.