What is QuickTest Automation Object Model?
It's a way to write scripts so as to automate your QuickTest operations.
Some places where we can use AOM
This is a small list of places (but not limited to) where we can use AOM. Thumb Rule - Use it at any place where you find yourself doing repetitive tasks while using QTP.
- AOM can come handy when you have a large no of scripts to be uploaded to QC. A simple script can save you hours of manual work!
- Use AOM to initialize QTP options and settings like add-ins etc.
- You can use AOM to call QTP from other application: For ex: You can write a macro for calling QTP from excel.
Caution: AOM should be used outside of QTP and not within the script (during playback). Though there is no harm using it inside but some of the AOM statements might fail.
How to write AOM scripts?
You need to understand that the very root of QT AOM is Application Object. Every automation script begins with the creation of the QuickTest "Application" object. Creating this object does not start QuickTest. It simply provides an object from which you can access all other objects, methods and properties of the QuickTest automation object model.You can create only one instance of the Application object. You do not need to recreate the QuickTest Application object even if you start and exit QuickTest several times during your script. Once you have defined this object you can then successfully work and perform operations on other objects given in Quick Test Pro > Documentation > QuickTest Automation Reference.
For ex: Let us connect to TD QC using AOM and open a script "qtp_demo"
Dim qt_obj 'Define a Quick Test object
qt_obj = CreateObject("Quick Test.Application")
' Instantiate a QT Object. It does not start QTP.
qt_obj.launch ' Launch QT
qt_obj.visible ' Make QT visible
qt_obj.TDConnection.Connect "http://tdserver/tdbin",
_ 'Referencing TDConnection Object
"TEST_DOMAIN", "TEST_Project", "Ankur", "Testing", False
' Connect to Quality Center
If qt_obj.TDConnection.IsConnected Then
' If connection is successful
qt_obj.Open "[QualityCenter] Subject\tests\qtp_demo", False ' Open the test
Else
MsgBox "Cannot connect to Quality Center" ' If connection is not successful, display an error message.
End If
To quickly generate an AOM script with the current QTP settings. Use the Properties tab of the Test Settings dialog box (File > Settings) OR the General tab of the Options dialog box (Tools > Options) OR the Object Identification dialog box (Tools > Object Identification). Each contain a "Generate Script" button. Clicking this button generates a automation script file (.vbs) containing the current settings from the corresponding dialog box.
You can run the generated script as is to open QuickTest with the exact configuration of the QuickTest application that generated the script, or you can copy and paste selected lines from the generated files into your own automation script.
How To Run QTP Scripts at Scheduled Time?
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.
1) 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
2) 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
3) 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.
4) Click Browse and and select the .vbs file you just created.You will get this screen
5) Give a name to the task and select the frequency for performing the given tasks. For this demo we will select "One time only"
6) Select Start Time and Start Date. For this demo, select Start Time as current time+5 mins and Start date as todays date.
7) Next Screen Enter "UserName", "Password" and "Confirm Password" Click Next and you should get this screen.
8) Click on Finish and yay, you're done.
Note: The steps above are for Windows XP and may be different for other Operating Systems.
Use AOM to check if your application is already running
There are certain situations where you can't run two instances of same application OR before starting a test with QTP, you want out find out whether a particular process is already running. Ex: In case of Siebel Automation . To find the process, the workflow is, Go to "Windows Task Manager"[Ctrl-Shift-Esc] > Process tab > strain your eyes to sift the required process from the 100's of already running processes.
We can do this job with a simple VBScript. This will reduce the duration of workflow to < 2 sec and you get the result instantly at the click of a button.
Code:
Dim AllProcess
Dim Process
Dim strFoundProcess
strFoundProcess = False
Set AllProcess = getobject("winmgmts:") 'create object
For Each Process In AllProcess.InstancesOf("Win32_process") 'Get all the processes running in your PC
If (Instr (Ucase(Process.Name),"TASKMGR.EXE") = 1) Then 'Made all uppercase to remove ambiguity. Replace TASKMGR.EXE with your application name in CAPS.
msgbox "Application is already running!" 'You can replace this with Reporter.ReportEvent
strFoundProcess = True
Exit for
End If
Next
If strFoundProcess = False Then
msgbox "Go ahead!Application is not running" 'You can replace this with Reporter.ReportEvent
End If
Set AllProcess = nothing
To check whether this is working:
1) Copy the above code to a notepad and save file as test.vbs on your desktop.
2) Open the Windows Task Manager[Ctrl-Shift-Esc].
3) Double click on file created above(test.vbs)
4) You should get a message "Application is already running!"
5) Done...Enjoy!
You need to be a member of Quality Testing to add comments!
Join Quality Testing