There can be situations when you need to schedule your QTP scripts so that they can run when you are not present in front of your PC. I will show you a demo below.
Create a .vbs file to launch QTP with required settings, add-ins etc.
Here is a sample vbs code
Set App = CreateObject("QuickTest.Application") App.Launch App.Visible = True App.WindowState = "Maximized"' Maximize the QuickTest window App.ActivateView "ExpertView"' Display the Expert View App.open "C:Program Files/Mercury Interactive/ QuickTest Professional/Tests/Test1", False 'Opens the test in editable mode
Ok, for the first timers. Create a sample QTP test and save it as Test1 at the location above. Copy the code into notepad and name the file as testing.vbs
Now we will automate the opening of vbs file through Windows Scheduler.
Go To Start > Control Panel > Schedule Tasks > Click Add Schedule Tasks Click Next on the screen. Click Browse and and select the .vbs file you just created. You will get this screen
Give a name to the task and select the frequency for performing the given tasks. For this demo we will select “One time only”
Select Start Time and Start Date. For this demo, select Start Time as current time+5 mins and Start date as todays date.
On the next screen, Enter “UserName”, “Password” and “Confirm Password” of your windows machine. Click Next and you should see this screen.
Click on Finish and yay, you’re done.
Note: The steps above are for Windows XP and may be different for other Operating Systems.
Please let us know your feedback and comments below.
Hi,
I have created a vbs file to run testcases from vbs file and schedule it for night execution.QC credentials i have passed in my vbs file.
For me QTP is not launching and starting the execution when i am running it in batch using QC QTP util object.
Set QCConnection = CreateObject(“TDApiOle80.TDConnection”)
Scheduler is showing in the progress and test cases are listed in the scheduler but it is not proceeding further and not launching QTP to execute the script
myTSScheduler.Run (ts.ID)
I have checked the “Allow other HP products to run” checkbox.
Hi Ankur,
We have BPT scripts in QC and we wanted to schedule a test to run every night.
We are using ALm12.x with UFt12.x
I have tried schedule test feature in ALM12 It self and it didn’t work.
Thank you
Raj
HI Ankur,
can we Automate the scheduler. IF yes please send me the script.
i am running QTP scripts thru ALM. but when i am running those scripts in batch. i have to close browser and open it again.
Hi Ankur,
My requirement is to execute any particular script for every 30 min in case any failure we need to send a mail to user.
Hi Ankur,
Thanks in advance for your help!
I am trying to run .vbs script to open qtp (v#10) and run the test then close the qtp. (very simple test)
the code runs first time correctly without any issues. but when i try to do the samething again, it fails with ‘cannot run because the script is empty’.
Code is below which i am using.
Set qtApp = Createobject(“QuickTest.Application”)
qtApp.Launch
qtApp.Visible = True
qtApp.open “C:\Users\user1\Desktop\QTPNightlyScript\Scripts\Smoke1”, True
Set qtTest=qtApp.test
qtTest.Run
WScript.sleep 10000
qtTest.close
qtApp.quit
set qtTest = nothing
set qtApp=nothing
Hi Ankur
Recently I have been asked to schedule a Test case that is to be executed daily @12:00 pm. How can I achieve it ? Please help me with answer.
Thanks in advance.
Hi Ankir….Is there any way of launching Control Panel via QTP script?
@Amit Singh:
Yes, to launch the Control panel use this
CreateObject("WScript.Shell").Run "control.exe"
To launch a particular control panel applet, use this
CreateObject("WScript.Shell").Run "control.exe appwiz.cpl"
‘This will launch Add remove programs applet.Can Anyone Please Help me How to launch QTP using outlook email trigger
steps :
* unlock system
* Before starting QTP i want to replace test suite what ever i attached in that email in my framework design suite
* Get back results through outlook email
Thank you !!
Thank you so much. have a question can we run multiple scripts with one schedule task? or do i have to create new schedule for each script? for example if i have 500 scripts to run do i have to create 500 windows schedule?
@Waj: No.
May I ask you, how do you run 500 scripts when not using scheduler?
Is it possible to run the same script on two different machine at the same time.
I was able to run the scripts using vbscript. the problem here is machine Qtpaap.Run is waiting for the execution to be completed. once this is done its running the second machine.
is it possible to run at same time on both machine using vb or javascript
Really fantastic solution over the performance!!!
ShyamH
Hello, thanks to all of the post I was able to schedule and run my tests. I do need to either have the results show at the end of my scheduled run or save the results to a folder. Can anyone please assist me and let me know what I need to add to my script to make this happen?
Set App = CreateObject(“QuickTest.Application”)
App.Launch
App.Visible = True
App.WindowState = “Maximized” ‘ Maximize the QuickTest window
App.ActivateView “ExpertView” ‘ Display the Expert View
App.open “C:\Users\cramirez\Program Files\Mercury interactive\QuickTest Professional\Tests\Test1”, False
App.Test.Run ,True
I noticed many persons are having issue in App.open line. For this please check if it is Mercury Interactive or HP and replace this part + your test name.
App.open “C:\Program Files\Mercury Interactive
\QuickTest Professional\Tests\Test1″, False
Secondly, I noticed many people are not able to run the tests. For this use the following code after the App.open line
App.Test.Run ,True
Summing above, notepad should include these
App.open “C:\Program Files\Mercury Interactive
\QuickTest Professional\Tests\Test1″, False
App.Test.Run ,True
Thanks,
Nanda
Hi,
This just launched the script but did not run.How do i run it..??
Hey This just launched the script to me too….but did not run.How do i run it
Please help
Ankur,
Good job and very informative post, please keep posts like this coming.
Thanks,
shabeer
How do I access my QTP scripts if i only access them through Quality Center and if they are not saved in my local drive. I log into Quality Center to activate and kickoff my scripts through the “Test Lab”. Please let me know if you have a solution.
Thank you
Jon
Great peice of work. it helped me a lot! Keep posting these kind of updates. Thanks fro your awesome post
Good job. We are expecting more from this because it helps me in critical postion. Keep going dude..
Hi All, I wanted to give parameters of QC in Result location for e.g Project Name, Test Set Name, RunName and then Input parameters of the driver script.
Can anyone help me in this??
thanks
and ur given detail steps these are very much useful to like me testers
Hi All,
How do I schedule the QTP scrips according to time I want. Say if i want to run it 1st Nov, 13 Nov and then 5 Dec…. I mean is there any facility to take the scheduling details(time date) from an excel sheet and then schedule the scripts. Awaiting replies.
Great Tutorial, thank you!
I already run QTP using VBScript but now I would like to have one report for alle the testcases I start.
My VBScript runs testcases calling a sub called testcaseRunner() with the path to the testcase as parameter.
Now, there is a report for each testcase. Is there a possibility to put all the testcase reports in one html page (it would be great if it had the same look like the exported html file).
Thanks and best regards,
Timm
hi Ankur..am using QTP 10.0 version.Could you please explain me how can I run the script in QTP using a .vbs file in which my scripts are stored in QC.I am confused with the path to be given so that scripts can be fetched from QC.The scripts are stored in Test Plan module of QC.
Thanks,
I want to upload the results to Quality Center using QTP even if a certain testcase is locked by another user.It has to release the lock and then upload the results to QC.Can someone help me in this?
I have a specific problem,
How do I run a series of functions like…fns1,fns2,fnN with a for loop…
Please find what i’ve done and it says ’syntax error’
For i=1 to 4
ss=trim(CStr(“abc_gui_case_”&i))
ss ‘ //to call the function
Next
Public Function abc_gui_case_1
…
…
..
End Function
Public Function abc_gui_case_2
…
…
..
End Function
Public Function abc_gui_case_3
…
…
..
End Function
‘##################################################################################################################
‘Author: Nagarajan Gnesan
‘Date: July 15, 2009
”Input Parameters
‘ 1. strSubject – Subject Need To Write In The Mail
‘ 2. strMailID_From – Mail ID Of Sender
‘ 3. strMailID_To – Mail ID Of Recipient
‘ 4. strMessageBody – Text Which Need To Send The Recipient
‘ 5. strAttachment – Path Of Any Attachment Or Null (“”)
”##################################################################################################################
Public Function Send_Email(strSubject,strMailID_From , strMailID_To, strMessageBody, strAttachment)
Set objMessage = CreateObject(“CDO.Message”)
objMessage.Subject = strSubject
If strMailID_From <> “” Then
objMessage.From = strMailID_From
Else
objMessage.From = ” “
End If
objMessage.To = strMailID_To
objMessage.TextBody = strMessageBody
Set fso = CreateObject(“Scripting.FileSystemObject”)
If strAttachment <> “” Then
If fso.FileExists(strAttachment) = False Then
Reporter.ReportEvent micFail, “Mail Attachemnt”, “Attachment file – ” & strAttachment & ” not found”
Send_Email = False
Exit Function
End If
End If
objMessage.AddAttachment strAttachment
On Error Resume Next
objMessage.Send
If Err.Number <> 0 Then
Err.Clear
sch = “http://schemas.microsoft.com/cdo/configuration/”
Set cdoConfig = CreateObject(“CDO.Configuration”)
With cdoConfig.Fields
.Item(sch & “sendusing”) = 2 ‘ cdoSendUsingPort
.Item(sch & “smtpserver”) = “mail03.bedford.progress.com”
.update
End With
Set cdoMessage = CreateObject(“CDO.Message”)
With cdoMessage
Set .Configuration = cdoConfig
.From = strMailID_From
.To = strMailID_To
.Subject = strSubject
.TextBody = strMessageBody
End With
cdoMessage.AddAttachment strAttachment
cdoMessage.Send
If Err.Number <> 0 Then
Reporter.ReportEvent micFail, “Send Mail”, “Failed to send the email – Error # ” & CStr(Err.Number) & ” ” & Err.Description
Send_Email = False
Exit Function
End If
Set cdoMessage = Nothing
Set cdoConfig = Nothing
End If
Set objMessage = Nothing
Set fso = Nothing
Send_Email = True
End Function
‘ Posted Nagarajan.
‘ nagarazang@gmail.com
hi…
i am using qtp 9.5 ,in my product some applications are getting recorded but applications (like sfs or lookup ahead) not geeting recorded.plz give some suggestions.
gouse
How to invoke QTP using mail
Thanks the solution is really good
This is superb! thanks a ton Ankur and Priyaranjan.
I followed same steps but am not able to read data from excel..it only runs the scripts
I got the Task Scheduler to work. I am in need of the send mail function. I want to add a send mail function to notify me via when QTP detect error during testing/validation. I want to have email message like: “Error encounter. Unable to proceed. Please check error”.
Thanks in advance.
To run multiple scripts: simply create a master script and call all the scripts that u need to execute…now give the path of the master script in the vbs file….
Thank you. this article helped me to solve the problem
How do i save the results to Quality Center?
I have used the below lines of code (vbs file)to open and run the script. I was able to successfully save the results in the location as mentioned in a local directory.
Set qtApp = CreateObject(“QuickTest.Application”) ‘ Create the Application object
qtApp.Launch ‘ Start QuickTest
qtApp.Visible = True ‘ Make the QuickTest application visible
Set qtResultsObj = CreateObject(“QuickTest.RunResultsOptions”)
qtApp.Open “[QualityCenter] SubjectInfrastructureAutomation Testlaunchscript”, True ‘ Open the test in read-only mode
Set qtTest = qtApp.Test ‘set run settings for the test
qtResultsObj.ResultsLocation = “C:Documents and SettingsPgantaQTPresults” ‘ Set the results location
qtTest.Run ‘ Run the test
qtTest.Close ‘ Close the test
qtApp.quit
set qtResultsObj = Nothing ‘ Release the Run Results Options object
Set qtTest = Nothing ‘ Release the Test object
Set qtApp = Nothing ‘ Release the Application object
i tried with above example ,it just open the script but not executed the script.is there any thing i have to add in the script t\for execution of the script.Kindly let me know the solution
I tried to launch the application by using .vbs script but its giving an error access is denied even while creating the scheduled task and that’s why my .vbs script never runs and error saying “……access is denied…..”displayed. Is there any solution to this problem.
But if we want to do this on QCServer what should we do?
1. can we do this for multiple scripts?
2. Do we need a VBS editor or VB editor to open this, because i got an error at the scheduled time.
Datatable.ExportSheet” path to your storage location”
How to send test results in qtp to an excel file.
Can we do this for the more than scripts?
@Abhishek
Try to see where the Test Results are generally saved for your tests in QTP when you open QTP normally (You can verify this but clicking on the Run button in the QTP and you will get a window asking where to store your Test Results) that may help you find the test results when they are run using automated script.
Let me know if you tried some other way.
Hope this helped.
Soujanya
Hi Friends,
I tried the above code to run the QTP application according to scheduled task but i can’t see the test results after end of test can someone help on that how to get tese results after the successful execution of the test through above code.
Thanks
Abhishek Sharma
hi,
Thanks for your inputs on how to open the test in QTP from vbs.. but now my question is how to pass parameters to perticular action?
Same query from me guys – How to set QTP to send the result via email automatically? Vijay.
How can we email our qtp test results to outlook email?
Ankur,
I would really appreciate if you can tell us how we can email the qtp test results to outlook emails…..thanks!!!!!!!!!!
@Niranjan: Nice Q…You can try this[ http://www.softtreetech.com/24×7/archive/51.htm ] to unlock a computer through scripting.
Since I haven’t used this myself so please let me know how it worked for you.
How do you take care, if the machine is in locked mode at the specified time?
Hi
I have followed the step by step procedure for scheduling tasks thru scheduler in Control Panel.
im getting an error message for it…System is not opening the .vbs file which has the code.
Pls help as I am working on something similar. As already mentioned .vbs is opened ony thru QTP?
Please Clarify
Maniz & Ankur
Thanks you for this! This is realy cool!
Cheers from Switzerland
Patrick
The 4th step:
App.WindowState = “Maximized
is redundant as making this step as commented also opens the application in maximized window.
Thanks for the inputs. But this is useful only when the scriot mentioned here runs on its own and does not require any user input or a click.
Dim Test_path
Test_path = “C:Documents and SettingsMKrishaDesktopAutomationStreamline_Regression_Suites”
Dim qtApp ‘As QuickTest.Application ‘ Declare the Application object variable
Dim qtTest ‘As QuickTest.Test ‘ Declare a Test object variable
Set qtApp = CreateObject(“QuickTest.Application”) ‘ Create the Application object
qtApp.Launch ‘ Start QuickTest
qtApp.Visible = True ‘ Make the QuickTest application visible
‘ Set QuickTest run options
qtApp.Options.Run.RunMode = “Fast”
qtApp.Options.Run.ViewResults = False
qtApp.Open Test_path, True ‘ Open the test in read-only mode
‘ set run settings for the test
Set qtTest = qtApp.Test
qtTest.Run ‘ Run the test
qtTest.Close ‘ Close the test
qtApp.quit
Set qtTest = Nothing ‘ Release the Test object
Set qtApp = Nothing ‘ Release the Application object
I have the same question. wanna run the scripts completely unattended. otherwise no point opening a scripts as a scheduled task.
It is still a question how to launch the QTP scripts? .VBS file script only open QTP.
Thank u!! excelnt work
Excellent! Thanks for the detailed steps.