For the past few weeks, I have been actively working on Quality Center (ALM) and its integration with QuickTest Professional. One of the mini-projects I’ve worked on is creating a custom object that executes a test set and sends an email to the supplied distribution list from ALM TestSet’s Automation tab (as shown below):
Note: The above part (EMailTo) can be modified by either hard-coding it, or supplying an input from the Class Constructor.
I’ve extensively used the OTA API Reference to build this object and to understand how the API works. .NET developers having difficulty converting the VBScript code, please post in the comments section and I will mail you the class library (currently only C#).
Download (ALM Only)
QCRunTestSet is available for download, but comes as-is and currently executes TestSets on the localHost. However, I would be more than happy in helping you to modify this code to suit your needs.
QCRunTestSet.cls.vbs.zip [for ALM] (2866)
If you’re having issues creating an instance of the TSScheduler object, please read this thread carefully. You may need to upgrade to a higher patch or perform a client registration on the execution machine.
Running QCRunTestSet from CommandLine
If you would like to pass parameters from the CommandLine instead of hard-coding them in the code, use WScript to pass arguments and WScript.Arguments to retrieve them in the class library. Example:
'Passing arguments wscript C:\QCRunTestSet.cls.vbs "http//<server>:8080/qcbin" myUser myPassword myDomain _ myProject myTestSetPath myTestSetName |
'Retrieving arguments Set args = WScript.Arguments QCServer = args(0) UserName = args(1) Password = args(2) QCDomain = args(3) QCProject = args(4) QCTestSetPath = args(5) QCTestSetName = args(6) |
I hope you find this helpful. Thanks for visiting Relevant Codes! :)
{ 65 comments… read them below or add one }
So I got it working, but when my test set is done (59 scripts 1.5 hours later) it fails to send email on below line
TSFolder.Refresh : WScript.Sleep(5000)
due to the connection being closed(probably a X minute inactivity kickoff). I tried to write the below into the Class_Terminate() but no luck… any help please? Thanks
Private Sub Class_Terminate()
If IsObject(TSScheduler) Then
If Not TSScheduler Is Nothing Then
‘JayAvondoglio: TRY: Server Connection was lost so need to disconnect and reconnect here
On Error Resume Next
‘Disconnect TD session
TDConnection.Disconnect
‘Disconect and quit QTP
If IsObject(qtApp) Then
If qtApp.TDConnection.IsConnected Then qtApp.TDConnection.Disconnect
qtApp.Quit
End If
On Error Goto 0
Call isQCConnected
‘JayAvondoglio: END
TSFolder.Refresh : WScript.Sleep(5000)
‘Send an email to the distribution list
TDSendMail()
Set TSScheduler = Nothing
End If
End If
On Error Resume Next
‘Disconnect TD session
TDConnection.Disconnect
‘Disconect and quit QTP
If IsObject(qtApp) Then
If qtApp.TDConnection.IsConnected Then qtApp.TDConnection.Disconnect
qtApp.Quit
End If
On Error Goto 0
Set qtApp = Nothing
Set TDConnection = Nothing
End Sub
I love what I see, but right now I have a blank password and it will not allow it. I am sure I can set my password to be something other than blank in QC and this will work, but is there any way to modify it. I tried to take a look using common sense, and have found the location of the error, but am not sure where to tweak it.
sErr = “Unable to execute RunTestSet. Please provide the ”
arrArgs = Array(“QCServer”, “UserName”, “Password”, “QCDomain”, “QCProject”, “QCTestSetPath”, “QCTestSetName”)
bExit = False
Thanks for any help.
Hi,
Thanks for the article.
I have many testsets which I wanted to executed. But each testset contain few Passed scripts and few failed. I just wanted to executed passed scripts only from each test set. So how to modify the code so that it executes testset with custom filters like ‘Status = Failed’
Appriciate any indicator.
Thanks
RKJ
Greetings,
I want to run only certain tests in a test set and also on a specific host group. I have a query for my selected tests below (basically any test. Also, I just want a simple email that is send when all tests are completed. All of this is very new to me and I appreciate all the help I have already gotten from you.
Thanks
Select ts_name as TestName
from td.TESTCYCL T
inner join td.CYCLE C on c.CY_CYCLE_ID = T.TC_CYCLE_ID
inner join td.CYCL_FOLD cf on c.cy_folder_id = cf.cf_item_id
inner join td.TEST E on e.TS_TEST_ID = t.TC_TEST_ID
Where c.CY_CYCLE = ‘Demo’ and TS_Status != ‘Repair’ and TC_status in (‘No Run’,'Not Completed’)
Order by ts_name
Greg, if you would like to run this using OTA, then how are you running this query against the DB? I assume you’re using a RecordSet object. What does it return?
Hi Anshoo,
I wanted to know that, how we can attach the results to the email sending option what you mentioned above. Please help me out in this.
Regards,
Shiv
Shiv, there are 2 ways you can do this:
1. Add the emails to the EmailTo field in ALM
2. Manually specify the recipients in the class library by modifying the caller function:
Public Sub RunTestSet(Server, UserName, Password, QCDomain, QCProject, QCTestSetPath, QCTestSetName, EmailTo) Dim QCTestSetExec, sErr, arrArgs, ix, arg, bExit sErr = "Unable to execute RunTestSet. Please provide the " arrArgs = Array("Server", "UserName", "Password", "QCDomain", "QCProject", "QCTestSetPath", "QCTestSetName") bExit = False For ix = LBound(arrArgs) To UBound(arrArgs) Execute "arg = " & arrArgs(ix) If arg = "" Then MsgBox sErr & arrArgs(ix) & ".", vbOkOnly, "Error!" bExit = True End If Next If bExit Then Exit Sub Set QCTestSetExec = New QCRunTestSet With QCTestSetExec .Server = Server .UserName = UserName .Password = Password .QCDomain = QCDomain .QCProject = QCProject .QCTestSetPath = QCTestSetPath .QCTestSetName = QCTestSetName .EmailTo = EmailTo .Run End With Set QCTestSetExec = Nothing End SubWould you please send me the class library, i’m very interested? Thanks
Tracy, the link to the class library is in the article itself. Alternatively, you can use this: http://relevantcodes.com/wp-content/plugins/download-monitor/download.php?id=10
Thank a lot. This will also help me to run the scripts in batch mode from command line
I am not able to successfully execute the vbs file. It reports that the activeX component can not create Object . Please advice
Narayan,
If you are running the script in a win7 system then open the command fom Start- Accessaries – Right click on command promt and select “Run as Administrato”. Then go to type
cd\ Enter
then CD c:\windows\SysWOW64 Enter
Now fom this directory run the vbs file.
Try it out and reply back
Narayan, in addition to what Avinandan said, please also make sure you have ALM/QC 11.0 installed with QTP on the target machine. This error just means the correct COM object was not found, or is not registered.
Greeting,
I have a QC test which is automated using QTP, i want to run that test case automatically. Help please.
I tried the way it’s mentioned in this thread but it’s not working.
can someone help me here ?
Thanks,
Amit
Amit, this article will execute the entire Test Set. Also, there are some commands used which are only available with QC 11.0. If you are using version 11.0, can you share the code you’ve used to execute the Test Set?
Dim TSetFact, tsList Dim theTestSet Dim tsTreeMgr Dim tsFolder Dim Scheduler Dim execStatus Dim tdc Dim nPath Dim TSTestFact, testList Dim tsFilter Dim TSTst Set tdc = CreateObject("TDAPIOLE80.TDConnection") If (tdc Is Nothing) Then MSGBOX "Connection is not created" Else MSGBOX "Connection is created" End If tdc.InitConnectionEx "http://symqc.prod.fedex.com:7117/qcbin" tdc.Login "685495", "Syntel24" tdc.Connect "BSTATS", "fedex-com-FedExWebIntegWizard" Set TSetFact = tdc.TestSetFactory Set tsTreeMgr = tdc.TestSetTreeManager nPath = "Root\" & Trim("SANDBOX\Amit Chaudhary") MSGBOX nPath Set tsFolder = tsTreeMgr.NodeByPath(nPath) If (tsFolder Is Nothing) Then MSGBOX "Folder is not found" Else MSGBOX "Folder is found" End If Set tsList = tsFolder.FindTestSets("OTA") If tsList.Count > 0 Then MSGBOX "FindTestSets found more than one test set" ElseIf tsList.Count < 1 Then MSGBOX "FindTestSets: test set not found" End If Set theTestSet = tsList.Item(1) 'MSGBOX theTestSet.ID 'Set TSTestFact = theTestSet.TSTestFactory 'Set tsFilter = TSTestFact.Filter 'tsFilter.Filter("TC_CYCLE_ID") = theTestSet.ID 'Set testList = TSTestFact.NewList(tsFilter.Text) 'For Each TSTst In testList 'MSGBOX "Name: " & TSTst.Name & " ID: " & TSTst.ID Set Scheduler = theTestSet.StartExecution("") Scheduler.RunAllLocally = True Scheduler.Run Set execStatus = Scheduler.ExecutionStatus 'MSGBOX execStatus 'Next set obj = theTestSet.StartExecution("LocalHost") obj.RunAllLocally = True obj.Run() Set tdc = NothingAmit, the one thing you are missing is the part where you have to wait until the execution is complete. You will have to retrieve the Scheduler status and check if it has finished execution. Besides this, your code seems correct. You didn’t specify it though – what is the issue you are having?
Hi Anshoo,
Sorry, i was away from this project for a while. Can you please help me to resolve the issue as you mentioned of wait until execution is completed ?
Issue is – test cases status is not initiating for execution ?
Many thanks in advance for help !
Thanks,
Amit
Getting error – ActiveX component can’t create object.
Hi Anshoo,
Still the issue is not resolved, can you please quickly check on some solution for this ?
Amit, you were missing the polling mechanism:
Private Sub WaitWhileTestRunning(ByVal ExecutionStatus) Dim RunFinished: RunFinished = False While RunFinished = False ExecutionStatus.RefreshExecStatusInfo "all", True RunFinished = ExecutionStatus.Finished WScript.Sleep(60000) Wend End SubAmit: Are you still getting an ‘ActiveX cannot create Component’ error?
Hi Anshoo,
Error is gone now,but actual test case is not runinng.
FYI…it’s a BPT test case.
Help please.
Thanks,
Amit
Hi Anshoo,
Can you please help me on this ?
Thanks,
Amit Chaudhary
Amit, I am not sure what is causing it. Use the library in this post and run the following command:
Call RunTestSet("http://symqc.prod.fedex.com:7117/qcbin", UserName, Password, "BSTATS", "fedex-com-FedExWebIntegWizard", "Root\" & Trim("SANDBOX\Amit Chaudhary"), "OTA")What behavior do you see? Does the test set run? Are there any error messages? Does an incorrect test set run?
One other thing, are there any other test-sets with the word “OTA” in them?
Hi Anshoo,
I am using ALM 11 and QTP 11. I updated your code with my testset info and run it from the command line. After the testset finish running, the Test Run Scheduler still active. After a couple of minutes, the same testset automatically ran again. Why is that?
Thanks.
MTL: I am not sure why this would happen. I tested this library in the morning via command line and the Test Set was run only once and there was no execution afterwards. Please share the code you’ve used to run via command line.
Hi Anshoo,
Query on – QC 11-QTP11 Integration
Precondition :- Selected 4 qtp scripts in QC TEst Set and Selected only 2 and run them
Problem :-
When it start execution, it opens QTP and run the first selected script multiple times and does not stop ?
Is it a known issue ? Or is there any workaround ?
Thx for your time,
SAM
Sam, I haven’t encountered this issue. Are you on the current patch level for QC? Can you share the code?
Hi Anshoo,
Unfortunately cannot share the code.. But this is very weird scenario observed.. will try on few other scripts and will keep posted ..
Thx for ur time
Can u please elaborate ‘Current patch level’for QC.. Do I need to check with QC 11.0′s latest patch on HP site ?
Hi Anshoo,
Got to know the issue – its with Datatable issue with QTP 11 and QC 11 integration and there is a patch for it. Even though patch works fine but the issue is really a major one with this 11.0 version
Thx
Sam, are you on version 11.0 or 11.5? Patch 01 for 11.5 was released last night.
just to add to previous question i have been using QTP11.0 with QC9.2.
Hi Anshoo
I was trying to run the vbs file through command prompt with little modification in user name,password,domain,i have been getting an erros “Invalid server response”, please let me know what could be the reason.
Ashish, this library is only compatible with ALM (QC 11.0).
I may have gotten around this issue below…
‘TSReport represents the execution report settings for the current test set
”TODO::may need to comment this out and hardcode, while on QC 10.00
‘ Set TSReport = TestSet.ExecutionReportSettings
‘ TSReport.Enabled = True
‘This retrieves the EMail list from the recipients list from QC
‘ EMailTo = TSReport.EMailTo : Me.EMailTo = EMailTo
EMailTo = “javondo”
Hi Anshoo,
I have installed your solution on XP and executed succefully. But recently I upgraded my OS to WIN7. And during run in Win7 I am getting following error “unable to create an instance of the Test Director API OLE (Test Director Connection) Object.” Please help me to resolve.
avinandan,
open notepad and save this as a bat file:
bcdedit /set {current} nx Alwaysoff
Run bat file.
Avinandan, this should only occur if the following statement fails:
Set TDConnection = CreateObject("TDApiOle80.TDConnection")Do you have the QC add-in installed on this box?
I had the same issue and I fixed it like so(in my case due to 32/64 bit):
C:\Windows\SysWOW64\wscript C:\QualityCenterSchedul……..
So I got it working, but when my test set is done (59 scripts 1.5 hours later) it fails to send email on below line
TSFolder.Refresh : WScript.Sleep(5000)
due to the connection being closed(probably a X minute inactivity kickoff). I tried to write the below into the Class_Terminate() but no luck… any help please? Thanks
Private Sub Class_Terminate()
If IsObject(TSScheduler) Then
If Not TSScheduler Is Nothing Then
‘JayAvondoglio: TRY: Server Connection was lost so need to disconnect and reconnect here
On Error Resume Next
‘Disconnect TD session
TDConnection.Disconnect
‘Disconect and quit QTP
If IsObject(qtApp) Then
If qtApp.TDConnection.IsConnected Then qtApp.TDConnection.Disconnect
qtApp.Quit
End If
On Error Goto 0
Call isQCConnected
‘JayAvondoglio: END
TSFolder.Refresh : WScript.Sleep(5000)
‘Send an email to the distribution list
TDSendMail()
Set TSScheduler = Nothing
End If
End If
On Error Resume Next
‘Disconnect TD session
TDConnection.Disconnect
‘Disconect and quit QTP
If IsObject(qtApp) Then
If qtApp.TDConnection.IsConnected Then qtApp.TDConnection.Disconnect
qtApp.Quit
End If
On Error Goto 0
Set qtApp = Nothing
Set TDConnection = Nothing
End Sub
Please delete this duplicate comment(and this one). Sorry, could not remove myself.
Hi ,
I have a different problem. I hope Anshu or someone could help.
I an trying to write an exe using QC OTA to update the status of my test cases in QC.I am facing two issues:
1. When I am using run.Status =”Pass”; getting an error saying Field requires a value from the corresponding list
2. How to provide several other information for test case updation like OS,Locale,IE version, Product Version.
I am using QC 10.0.0.2248 on Win7 SP1 Ultimate32 bit
My code snippet is
foreach (TSTest tsTest in tsTestList)
{ Console.WriteLine(tsTest.Name);
Run lastRun = (Run)tsTest.LastRun;
Console.WriteLine(lastRun.Name);
RunFactory runFactory = (RunFactory)tsTest.RunFactory;
String date = DateTime.Now.ToString(“yyyyMMddhhmmss”);
Run run = (Run)runFactory.AddItem(“Run” + date);
run.Status = “Pass”;
run.Post();
}
Any help in this regard is highly appreciated as this is the first time I am using QC.
Hi Nitin,
you need to pass the status “Passed” insted of “pass”.
I hope it will work for you.
Thanks.
Hi,
I had a small concern as this coode works superb but TestSet.Tefresh does not work and i get the same status of the test case in the test set.
Please let me know how to change the status or maybe refresh the status of a test script.
Is this compatible with QC9.2?
Hi,
Is it possible to filter witch tests of the TestSet should be executed? For example: in the last execution 2 tests of a 10 tests Testset failed and I only want to execute those 2 that failed. Is that possible to archive via the OTA API?
Hi very good implementation, thanx.
My test sets take parameters.
How can i set test set parameters with this function?
Cherry the “TD object not found” error message can be a few different things. In order for this script to work you must be able to run QC from IE (Not QCExplorer.exe). Also if you are using a 64 bit system the script must be ran from a 32 bit prompt…
%windir%\SysWOW64\cscript.exe //nologo …
If you are using a 64 bit system getting QC 9.5 running in IE is a complicated setup.
Hi Anshoo,
I need to download report from QC via vb script or QTP Script.Can u help me in doing this?I need this urgently.
Thanks
Hi
Can anyone share the VB script to Connect ALM 11/QC11 and QTP10.00.
I see an error TD object not found
I had this script – Used to download the file from QC to Temp Directory
Func_GetFolderAttachmentPath(sTDFolderPath, sTDAttachmentName)
Dim oAttachmentFactory, oAttachment, oAttachmentList, oAttachmentFilter, oTreeManager, oSysTreeNode, iNdId,sPath
Set oTreeManager = QCUtil.TDConnection.TreeManager
Set oSysTreeNode = oTreeManager.NodeByPath(sTDFolderPath)
Set oAttachmentFactory = oSysTreeNode.Attachments
Set oAttachmentFilter = oAttachmentFactory.Filter
iNdId = oSysTreeNode.NodeID
oAttachmentFilter.Filter(“CR_REFERENCE”) = “‘ALL_LISTS_” & iNdId & “_” & sTDAttachmentName & “‘”
Set oAttachmentList = oAttachmentFilter.NewList
If oAttachmentList.Count > 0 Then
Set oAttachment = oAttachmentList.Item(1)
oAttachment.Load True, “”
sPath = oAttachment.FileName
End If
Func_GetFolderAttachmentPath = sPath
Set oAttachmentFactory = Nothing
Set oAttachment = Nothing
Set oAttachmentList = Nothing
Set oAttachmentFilter = Nothing
Set oTreeManager = Nothing
Set oSysTreeNode = Nothing
End Function
Hi,
I am currently using QTP 10 and QC9.5. Can any body help me out how to download scripts, attachments etc… from qc to local machine so that i can run from local machine and fix the fixes to the code.
Regards,
Srinivas
Srinivas: After connecting QTP to QC from your machine, you can open any of the resources in Quality Center from QTP.
Hi Anshoo, As per the client requirement we need to download all the resources which are there in QC to local machine and map them (resources) to locally and execute them. Its a one time activity to download them for the test cycle. Can you explain how we can do this. One of my colleague said we can do it using OTA to download and map the resources locally but not sure about it. Can u send any relevant code for the same.
Thanks in advance
Srinivas
can any one help me ,
how to automate test cases from JSP(java)
???
Hi Anshoo
This is very generic question regarding Testing
Our software has its own Object model and corresponding methods .attributes defined ( taken fro VB). Now in the new requirement another new 2 editors are getting added C# and VB.NET so users can use this two editors for Scripting.I have to test this scenario whether the Object model is ported correctly to C# and .NET or not.
Can you suggest any suitable automation method for this?
Thanks in advance
Hi ,
Can QC can be installed at my home system , I mean is it freely available or licence one.If it is can u plz provide me the link of the site from where i can download it.
Thanks!!
AK: I believe you can download a trial version for a short period of time. The last time I installed QC, the trial version lasted for 30 days. You will be directed to the downloads section from this link + you will need to be registered to download the software.
Hi,
How to export QTP batch test results to QC using OTA API.
For example I have three manual test cases in QC(id :100,101,102)for those manual test cases I have three automation scripts. I wan to execute these three automation scripts from QTP and want to send the results to QC(just update the manual test case status as PASS OR FAIL in QC automatically).Please help me.
Regards,
Kumar
Hi Anshoo,
I have saved one excel sheet in Test Resources of QC. But I am not able to access that excel sheet value.
Can you please let me how can we access the excel sheet saved in QC.
Thanks,
Rajasekhar
Anshoo,
I removed the code to send an email from the VBS file and executed it from CMD. Noticed the status of each script initially is N/A and for couple of scripts the status remained same, in other words only FEW scripts from testset were executed.
I am unable to see the results in CMD prompt (not sure if it shows any) as the scripts close all open files(browsers and cmd prompts at the start of each script ). How can I check the executionStatus of the Execution Controller (TSScheduler) when scripts are executing ,can you please shed some light?
I’m not sure why some of the scripts in test set are not being executed. Thanks in Advance!
-Sri
Hi Anshoo,
I executed the vbs file from commandline, received an error “Object doesn’t support this property or method: ‘TestSet.ExecutionReportSettings’
All I did is updated theVBS file with the values to the QC URL,ID/pwd,test folder and testset.
Executed using cscript.exe QCRunTestset.cls.vbs
Also, We are using QualityCenter 10.0 and QTP 10.0 versions.I do not see select Fields section under Automation tab in QC to notify by email. Is this something customized by QC Admin?or QC 11.0 feature?
I would love to do the same setup, receive an email with Test results report.
PS. I am trying to perform get this setup so scripts can be executed automatically following builds.
Sri: You received this error because the Interface ITestSet2 was introduced in QC 11/ALM. There are several enhancements made to this code and it only supports version 11.
Srinivas, I cannot send you the code as I do not have access to ALM. Your colleague has pointed you in the right direction though. First, download the resources to local machine, use LoadFunctionLibrary to associate. You can also directly connect to ALM before running the test and use resources directly from ALM.