QC & QTP – How to schedule a recurring test set

by Joe Colantonio on November 30, 2011

Post image for QC & QTP – How to schedule a recurring test set

Problem - Quality center's issue with running periodic testsets

This has been a long standing issue with me and Quality Center. You can use QC to schedule a testset to run at a given time but the issue is when you need to have a testset run at a recurring time -- say every day at 5:00 am.

Solution

To get testsets to run periodically you can use Vbscript with QC's OTA API and Windows scheduler.

Vbscript code needed to run testset in QC

First you need to setup a VBScript that calls the Quality Center's testset that you want to run:

set tdc = createobject("TDApiOle80.TDConnection")
tdc.InitConnectionEx "http://qcURL/qcbin/"
tdc.login "yourUserName","yourPassword"
tdc.Connect "yourDomain","yourProject"

Set objShell = CreateObject("WScript.Shell")
Set TSetFact = tdc.TestSetFactory
Set tsTreeMgr = tdc.TestSetTreeManager
Set tsFolder = tsTreeMgr.NodeByPath("Root\Formal Tests\YourTestDirectory")
Set tsList = tsFolder.FindTestSets("Your TestSet name. This is case sensitive!")
 
Set theTestSet = tsList.Item(1)
Set Scheduler = theTestSet.StartExecution("")
Scheduler.RunAllLocally = True
Scheduler.run

Set execStatus = Scheduler.ExecutionStatus

Do While RunFinished = False
 execStatus.RefreshExecStatusInfo "all", True
 RunFinished = execStatus.Finished
 Set EventsList = execStatus.EventsList

 For Each ExecEventInfoObj in EventsList
  strNowEvent = ExecEventInfoObj.EventType
 Next

 For i= 1 to execstatus.count
  Set TestExecStatusobj =execstatus.Item(i)
  intTestid = TestExecStatusobj.TestInstance
 Next
Loop


Window's Scheduled Tasks

Next you need to setup the windows scheduler to run at the desired time. See video for step by step instructions.

RunTestSet.exe - Another option

If you do not want to create your own VBScript to run your testsets you can also try an unsupported tool from HP - RunTestSet.exe. RunTestSet is a VC++ console application that you can send command line options to in order to run a QC testset. You can download RunTestSet and its documentation from HP or from http://www.joecolantonio.com/downloads

{ 53 comments… read them below or add one }

byzoor December 2, 2011 at 9:32 am

Hi Joe,
Woww… Nice… in 2007 one of my wipro officemate ‘ Jagdeswaran Elumalai ‘did for the same. But one more point . He using triger mail, mail will triger the vbscript, script will triger to QC 8.2. once exceution complte automatically send status report to mail to user.
Thanks for sharing the scripts.

Reply

Joe Colantonio December 5, 2011 at 10:11 pm

byzoor » Thanks – glad you like it! Good point — there is a SendMail method that can be email (using QC) a high level report. I’m sure, like you said, a fancier report could be created that is automatically sent. Cheers~Joe

Reply

Rob January 6, 2012 at 1:15 pm

Hi Joe,

Its Awesome.Its really helpful for some one learning OTA.

However , i have put this script in a note pad and saved it as .vbs file . After i double click on that , its through errors
“—————————
Windows Script Host
—————————
Script: C:\Documents and Settings\nap0587\Desktop\test.vbs
Line: 6
Char: 1
Error: ActiveX component can’t create object: ‘WSscript.Shell’
Code: 800A01AD
Source: Microsoft VBScript runtime error

—————————
OK
—————————

and

“—————————
WScript.exe – Application Error
—————————
The instruction at “0x100dfacf” referenced memory at “0x0195724c”. The memory could not be “read”.

Click on OK to terminate the program
—————————
OK
—————————

Set tdc = CreateObject(“TDAPIOLE.TDConnection”)
tdc.InitConnectionEx “http://qcurl/qcbin”
tdc.Login “username”, “password”
tdc.Connect “Domain”, “Project”

Set objShell = CreateObject(“WSscript.Shell”)
Set tsetfact = tdc.TestSetFactory
Set tstreeMgr = tdc.TestSetTreeManager
Set tsFolder = tstreeMgr.NodeByPath(“Root\Google”)
Set tsList = tsFolder.Findtestsets(“Phase1″)
Set theTestSet = tsList.Item(1)
Set Scheduler = theTestSet.StartExecution()
Scheduler.RunAllLocally = True
Scheduler.run

Set execstatus = Scheduler.ExecutionStatus

Do While RunFinished = False
execstatus.RefreshExecStatusInfo “all”,True
RunFinished = execstatus.Finished

Set EventsList = execstatus.EventsList

For Each ExecEventInfoObj in EventsList
strNowEvent = ExecEventInfoObj.EventType
Next

For i= 1 to execstatus.count
Set TestExecStatusobj =execstatus.Item(i)
intTestid = TestExecStatusobj.TestInstance
Next
Loop
WSscript.quit

I request you to please assist.

Thanks,
Rob

Reply

Joe Colantonio January 6, 2012 at 2:08 pm

Rob » Thanks Rob! This error usually means that your machine has an issue with ActiveX. I found the following fix. Can you try these steps:

Click Start, Run and type:
regsvr32 wshom.ocx
regsvr32 scrrun.dll

If the above does not help, or if you receive an error message when running the two commands above, then you may need to reinstall Windows Script 5.6 from Microsoft site.
Let me know if this helps. Cheers~Joe

Reply

Andrei January 13, 2012 at 10:27 am

Hi, joe
I have the same problem as Rob, but your solution with regsvr32 didn’t help me. Neither reinstall of Windows Script.
Do you have any ideas what else can helps to resolve this issue?

Thanks

P.S. the only difference is that I got error on line “Set Scheduler = theTestSet.StartExecution()”
P.P.S. I’m running on Windows 2003 SP2 x86

Reply

Benoit February 6, 2012 at 2:53 pm

Hello,

Thx Joe ;)

But i have the same problem too. “ActiveX component can’t create object” on line “Set Scheduler = theTestSet.StartExecution(“”))

… :S

Benoit.

Reply

Joe Colantonio February 9, 2012 at 1:32 pm

Benoit » What I usually try, on the machine that is giving me issues,is the following:

1) Navigate to QC (even if this is just a qtp run test machine) and let it download the QC active-x control
2) Install or Re-Install the HP Quality Center Connectivity add-in
3) Install or Re-Install the QuickTest Pro Add-in

Please let me know if this helps. Cheers~Joe

Benoit February 10, 2012 at 8:33 am

Hello,

Thank you for your answer.

Running the “ALM Client Registration” solved my problem: http://XXXX/qcbin/start_a.jsp?common=true

Best regards,
Benoit.

Rob January 9, 2012 at 5:21 am

Hey Joe,

Thank you so much its working :)

Appreciate your effort and support.

Regards,
Rob

Reply

Joe Colantonio January 9, 2012 at 2:30 pm

Rob » Excellent news Rob!

Reply

rishim February 7, 2012 at 10:56 am

Hi Rob,
Could you pls tell me the steps as how it works ?

Reply

Ben February 8, 2012 at 9:45 am

Hello,

My last comment was moderate about the issue with the ActiveX. Anyway i resolved the problem and i wanted to share with you the solution.
I just run the ALM Client Registration. I’m using ALM 11 so the link is: http://:8080/qcbin/start_a.jsp?common=true. It works fine right after for me.

But, i have an other problem.. I use your code in a VAPI-XP program. And i never get out of the While Loop. The “execstatus.Finished” is always False even after the end of the test. Actually it’s even worse it returns nothing, so i use the code below if i want the executionStatus returns something but it is always False.

(This code below run QTP scripts on a remote virtual machine by the way. This part works fine.)

——————-
——————-

Set TestSetFact = TDConnection.TestSetFactory
Set tsTreeMgr = TDConnection.TestSetTreeManager

Set TestSetFact = tdc.TestSetFactory
Set tsTreeMgr = tdc.TestSetTreeManager

‘Get the test set folder.
Set tsFolder = tsTreeMgr.NodeByPath(“”)

‘On Error GoTo RunTestSetErr
Set tsList = tsFolder.FindTestSets(“”)
If tsList.Count > 1 Then
MsgBox “FindTestSets found more than one test set: refine search”
ElseIf tsList.Count < 1 Then
MsgBox "FindTestSets: test set not found"
End If

Set theTestSet = tsList.Item(1)

'Start the scheduler on the local machine.
Set Scheduler = theTestSet.StartExecution("")

''''''''''''''''

Set TSTestFact = theTestSet.TSTestFactory
Set tsFilter = TSTestFact.Filter
tsFilter.Filter("TC_CYCLE_ID") = theTestSet.ID
Set testList = TSTestFact.NewList(tsFilter.Text)

'For each test instance, set the host to run depending
'on the planning in the test set.
For Each TSTst In testList
Scheduler.RunOnHost(TSTst.ID) = TSTst.HostName
Next
Scheduler.RunAllLocally = False

''''''''''''''
Scheduler.Run

'set execStatus = Scheduler.ExecutionStatus
'execStatus = Scheduler.ExecutionStatus.Finished
While (RunFinished = False)
'execstatus.RefreshExecStatusInfo “all”,True
'RunFinished = execstatus.Finished
Scheduler.ExecutionStatus.RefreshExecStatusInfo "all", True
RunFinished = Scheduler.ExecutionStatus.Finished

'Set EventsList = execStatus.EventsList
'For Each ExecEventInfoObj In EventsList
' strNowEvent = ExecEventInfoObj.EventType
'TDOutput.Print strNowEvent
'Next

'For i = 1 To execStatus.Count
' Set TestExecStatusObj = execStatus.Item(i)
' intTestID = TestExecStatusObj.TestInstance
'TDOutput.Print intTestID
'Next
Wend
——————-
——————-

Any help would be very appreciate.
Thank you for your time.

Best regards,
Ben.

Reply

Ben February 15, 2012 at 1:02 pm

Hello,

For you information. I’m using the Test Run Scheduler now. I call it from a VAPI-XP program. It works fine.

It works when i run the tests on a remote host. But It does not work when i run them in local. It seems the VAPI-XP window block the execution of QTP. I don’t know why. If you have any idea..

Thank you.

Regards,
Ben.

Reply

shar February 19, 2012 at 7:33 am

Hi Joe,

I’m an novice on using on QC and just trying to install it. After at least one week wrestling with the installation process and getting stuck in multiple integrity issues with my db… now I’m stuck with a jboss integration issue. As jboss zip file coming along with the QC pkg didn’t unpack, I had to do a workaround and point the QC config tool to my own instance jboss which I downloaded myself. I did run the run script for jboss so I could get things going. However, for launching QC I’m still hitting the wall. I get this error: The requested resource (/qcbin/SiteAdmin.jsp) is not available. The QC bin is somehow still stuck in the war file. Any idea? I do appreciate your help. Thanks. Shar

Reply

Joe Colantonio February 20, 2012 at 3:40 pm

shar » Hi Shar – I’m not sure what is happening. I do not see any known issues. What version of QC are you trying to install? Also what verison of Jboss and what db are you using? Has anyone else seen issue similar QC/jboss install issues?

Reply

shar February 21, 2012 at 7:37 am

Hi. Thanks for your reply. I’ve been looking for clues and similar problems and even used HP’s self-solve km to look for issues like this. But I’ve not found much. I’m using ALM 11, jboss 5.1 and sql server 2005. Any thoughts? Thanks.

Reply

Changa February 24, 2012 at 6:57 am

Hi Joe,

I am trying to run my QTP(v11) scripts using Windows Scheduler. I have created a vbs file to launch the application and open the QTP script and run it.

But when tasks gets executed, .vbs file is getting opened instead of launching an application and running the script.

Could you please let me know what might be the problem.

Thank you

Reply

Changa February 24, 2012 at 6:58 am

Environment: Windows7 OS

Reply

Changa March 5, 2012 at 6:00 am

Hi Joe,

Any idea pls, how can we schedule QTP scripts in Windows7.

Thank you

Reply

Lorena March 8, 2012 at 7:29 pm

I have been trying tio use the RunTestSet method with no luck.

I have my Run set as:
“C:\Documents and Settings\a641422\Desktop\RunTestSetScheduler\Release\RunTestSet.exe \s:http:\qc-alm.wellsfargo.com\qcbin \n:W_S \d:BS \u:a641400 \p:$Mikie201 \f:O:\QTP Tests \t: 1 – Image Access by ENV-5 \l”

And my Start In set as:
“O:\QTP Tests\NightlyRegressionTesting”

am I missing anything?

Reply

Lor March 14, 2012 at 8:55 pm

I have been working with your document TestSet Sceduler Solution with no luck. Can we get a copy of your vbs file?

I also need to run the scheduler after my system has timed out or logged off due to inactivity.

Any ideas on this?

Reply

Joe Colantonio March 15, 2012 at 6:47 pm

Lor » HI Lor – I placed a copy of one of my vbs testset sceduler scripts (QC_TestSet_scheduler.vbs) on my downloads section:

http://www.joecolantonio.com/downloads/

Also on all my lab machines I have the screensaver turned off and a registry setting that automatically logs me on to the machine.

Hope this helps,

Joe

Reply

Johan March 22, 2012 at 9:10 am

Hi Joe,

I created a similar solution for running automated tests (BPT) using QTP11 and QC11 where the user plans tests in QC and they are run on the specified date/time on a specified remote host.
Nevertheless, I do have some trouble with the automatic logon. As you are saying “a registry setting that automatically logs me on to the machine”, I suppose that you have a solution for this problem. Can you specify which regkey you are manipulating?

Thanks!
Johan

Reply

Joe Colantonio March 30, 2012 at 1:06 pm

Johan » Hi Johan – Sorry I thought I added a link to the Microsoft KB article on “How to turn on automatic logon in Windos XP” (FYI-I also use this on WIn7 machines without issues) Hope this helps. Cheers~Joe

Reply

Lor March 15, 2012 at 7:05 pm

I guess that is my issue. I cannot turn my screen saver off. I thought I had Admin rights but I guesss not. I think I will need to run via QC or contact the help desk to configure my system.

I did look in my regestry but I could not find any settings to turn off the screedn saver or change my settings to automaticlly log me in. We have tons of security systems monitoring our every key punch.

thx Joe

Reply

aditya July 5, 2012 at 10:38 pm

Hi,

I am trying something similar for HP Service Test scripts.I need to download the “replay log file” after executing the Test.Please inform how can i download the log file after execution.

Thanks,
Aditya Reddy

Reply

Joe Colantonio July 27, 2012 at 5:45 pm

aditya » Hi Aditya – when you say “replay log file” are you referring to the Output>Run results? If so I don’t think they are stored in QC (i’m not 100% sure). After you run a ST test the log files are stored locally under ST>Tools>Open Containing Folder> There should be a Log directory. The file named vtd_user.log contains the output>run results. You could create code that attaches each output results to a test lab in QC. Please let me know if I’m misunderstanding your question. Cheers~Joe

Reply

Tony August 17, 2012 at 3:51 pm

hello Joe–thanks for providing this resource! i have been using RunTestSet.exe, but have recently run into an issue where it crashes trying to disconnect from the TD Server.

given that, i’m looking forward to implementing this solution. One thing though, with RunTestSet, i point to a host group so that the tests are spread out to all of my QTP machines. how can i do this with the above example? i see “Scheduler.RunAllLocally = True”, which implies to me there could be a way i could point to a particular host group (?). if that’s the case, could you explain the syntax to achieve that?

much appreciated.

Reply

Tony August 17, 2012 at 5:31 pm

i seem to have it working. had to add Scheduler.TdHostName = “” and remove Scheduler.RunAllLocally. when i just changed that from True to False, I received an error.

Reply

Joe Colantonio August 17, 2012 at 6:59 pm

Tony » Cool you got it. Yup QC doesn’t like when you try to use the RunAllLocally property when you are running on a specified remote machine.

Reply

Manish August 21, 2012 at 5:14 pm

Hi Joe,
your solution worked perfectly for me to schedule batch jobs on QC 11 (ALM) and QTP 11. Thanks for your help and insight. I was trying to take it a step further by trying to invoke the automatic email generated with results summary (under the Automation tab) from QC which works when your run tests thru QC but doesnt generate when the tsts are executed thru batch job. have you had any experience with this feature?

Thanks
Manish

Reply

Joe Colantonio August 30, 2012 at 8:46 pm

Manish » Hi Manish does using the SendMail method in your scheduling vbscript help?

set tdc = createobject("TDApiOle80.TDConnection")
tdc.SendMail "listOfEmailAddress","","Subject","Message"

Reply

Vikas Gholap September 3, 2012 at 7:51 am

Hi Joe,
I want to execute all the test sets in a given folder, so I modified above code as below. However it execute only first test set from test folder and wscript.exe get closed. Second test set does not execute.
My test folder contains 5 test sets.
below is the code
‘********************************************************************
TSFolderPath = “Root\Z.Delete\A TEST\”
Set TSetFact = tdc.TestSetFactory
Set tsTreeMgr = tdc.TestSetTreeManager
Set tsFolder = tsTreeMgr.NodeByPath(TSFolderPath)
Set tsList = tsFolder.FindTestSets(“”) ‘ Get all test sets
If tsList.count >= 1 Then
For tsIndex = 1 to tsList.count
Set theTestSet = tsList.Item(tsIndex) ‘ TestSet Object
Set Scheduler = theTestSet.StartExecution(“”)
Scheduler.RunAllLocally = True
Scheduler.run
Set execStatus = Scheduler.ExecutionStatus
Do While RunFinished = False
execStatus.RefreshExecStatusInfo “all”, True
RunFinished = execStatus.Finished
Set EventsList = execStatus.EventsList

For Each ExecEventInfoObj in EventsList
strNowEvent = ExecEventInfoObj.EventType
Next

For i= 1 to execstatus.count
Set TestExecStatusobj =execstatus.Item(i)
Next
WScript.Sleep 5000
Loop
Next ‘Go to next TestSet
else
Msgbox “Test Set not found under test folder : ‘” & TSFolderPath & “‘.”
End If

Please tell me where I have to modify the script.

Thanks,
Vikas

Reply

Vikas Gholap September 5, 2012 at 11:20 am

Hi Joe,
I’m able to execute all automated BPT test set in a given test folder.
Thanks for this code.
Vikas

Reply

Viki September 5, 2012 at 11:24 am

One more query.
How we can execute fixed number of test cases from a single test set?
Consider I have a test set with 20 test cases.
I want to execute only first 10 test cases out of 20 from a test set. Where I have to change the code.

Please suggest.

Reply

Joe Colantonio September 11, 2012 at 4:55 pm

Viki » You can hard code the test case count in the script. So for the line that has For i = 1 to execStatus.Count change to the value to 10

Reply

Pradeesh September 6, 2012 at 9:06 am

Hi Joe,
I’m trying to run the script on windows 7 32 bit with QC 9.0.When i run manually from browser my test case is running fine.When I tried use this script It starts the TD test run scheduler but wont execute the test and it stops at that point. Same code is working in Windows XP. Using Msgbox i tried to display testcase ID ,name. Its returning it properly.Its failing at the point of execution. I tried everything mentioned in the site. Still it dint work for me.Its really urgent for me as i wasted 1 week already on troubleshooting this.

Reply

Joe Colantonio September 11, 2012 at 4:51 pm

Pradeesh » Sorry I have not tested this approach with QC 9.0. Rather than use the custom vbscript have you tried using RunTestSetScheduler tool? You can download it from http://joecolantonio.com/downloads/ RunTestSetScheduler.zip.

Reply

Vincent September 18, 2012 at 4:55 pm

Hi Joe,

Very good job. It works here. One more concern, in the third line of your script:
“set tdc = createobject(“TDApiOle80.TDConnection”)
tdc.InitConnectionEx “http://qcURL/qcbin/”
tdc.login “yourUserName”,”yourPassword”

I need put my username&password here, so there is a security concern here. Can we encrypt password here like what QTP does?

Reply

Joe Colantonio September 19, 2012 at 6:58 pm

Vincent » HI Vincent – We use a generic ALM/QC user for our scheduler scripts so we don’t usually encrypt the password. You could store the password in a DB and write some code that reads the password from the DB but I don’t think that would be super secure. Anyone else have any ideas?

Reply

Rohith October 10, 2012 at 6:21 am

Hi Joe,

Thanks for the helpful post. I had tried the RunTestSet.exe. It was successful. Moreover, I found an issue that, in the email notification the test set name and tester name are displaying in symbols..Any thought on this?? Thanks in advance

Regards
Rohith

Reply

Joe Colantonio October 11, 2012 at 11:11 am

Rohith » Hi Rohith – unfortunately I cannot think of what would cause this behavior. Anyone else have any suggestions?

Reply

Madhu Suthanan October 17, 2012 at 7:34 am

@ zoor
I know this guy Jagadeeswaran Elumalai.
What is the tool name that will schedule the qtp scripts in batch mode?
To run independently.
I forgot that application.

Reply

Saro November 19, 2012 at 4:58 pm

Hi All,.
I am looking for QTP code for Sending the email with Test Result attachment from QC through Lotus Notes.
I did QTP script to attach the Test Results in Test Lab module, but the email is triggered without the attachment.

Can any one please help me on this.

Thanks

Reply

Jez December 20, 2012 at 1:05 pm

Hey Rob,
My question is related to Saro’s, I have an email notification set on my testset in case of a failure, but since IE doesn’t actually open QC can’t send the email upon failure. Is there a way to run this script with QC being visibly open? Thanks.

Reply

Priyank December 27, 2012 at 3:27 pm

hi Joe,

After running above steps, my Test Run scheduler is opening but getting error “the requested operation requires elevation”. Tried both the methods, but getting same error in Test Run scheduler. I am using Win 7. Please assist.

Thanks in advance

Reply

Joe Colantonio December 28, 2012 at 7:46 pm

Priyank » Verify your QC/ALM and local machine permissions. I’ve never seen this error before but I’ve seen similar errors caused by permission or misspelling errors. Anyone else seen this before?

Reply

Sam January 7, 2013 at 7:29 pm

I have question in QTP n QC…

Scenario: how to run multiple QTP scripts from QC on different remote machines, say for example 100 script in QC test lab, to run on 5 machines, each machine having 20 scripts, while running all at a time from QC, if one of the machine’s h/w got crashed, these scripts are stopped, so at any cost we need to execute them (not manually) those scripts should automatically distribute or run on any available machine.

Plz help me in this

-thanks,
SK

Reply

Jürgen P. February 19, 2013 at 8:38 am

Hi Joe,

I’ve tried the RunTestSetScheduler tool from your website and ran into the following issue:

C:\>RunTestSet /s:https://myalmserver/qcbin /n:DOMAIN /d:Project /u:myUser /p: /l /t:MyTestSet /f:Root\folder
Initializing TDServer https://myalmserver/qcbin
Connecting to DOMAIN.Project project
Checking TestSet : Root\folder\MyTestSet
Opening Scheduler…
Error: Error: Class not registered

Do you have any idea what’s wrong? It “feels” like Opening Scheduler times out:

printf(“Opening Scheduler…\n”);
// get scheduler
ITSSchedulerPtr spScheduler = spTestSet->StartExecution(_T(“”));

I have the Remote Agent installed as well as the connection AddIn. Are there any requirements I missed?

Thanks!

Reply

Jürgen P. February 21, 2013 at 8:04 am

Joe,.

in the meatime I’ve solved the issue.

I had to reregister the HP ALM client from https://xxx/qcbin/start_a.jsp?common=true. I’ve seen this solution here before, but it did not work for me the first time.

But after deleting the client directory at
C:\Users\All Users\Application Data\HP\ALM-Client it was successfully installing the client and registering all DLLs.

All issues gone now. Hope this helps!

Reply

Joe Colantonio February 21, 2013 at 11:50 am

Jürgen P. »Sorry I planned to get back to you today.The registering of the ALM client does tend to solve a lot of these types of issues. Thanks for the update!

Reply

Pradeep March 26, 2013 at 3:12 pm

hi Joe,

Nice job, I am able to run the whole test set using the above code. But is there a way where we can just run only the failed scripts in a test set and also can we run only few scripts from a give test set. Like only 5 scripts from a test set which as 20 scripts.

thanks,

Reply

Gaurav April 17, 2013 at 9:50 pm

HI,
I have created batch runner as above. I am taking Test set name value from Excel file. There will be more than 25 testsets I will be executing from batchrunner.
Now, batchrunner is running for first testset and it is trying for second one before first completes run. I can not put wait as i do not know how much time each test will take to execute.
Now I want to put wait time so until one test set gets executed, Loop should not go to next test set from Excel.
I need to do it. Can someone help to resolve issue?

Reply

Leave a Comment

Previous post:

Next post: