Skip to main content

Automation Object Model

Automation Object Model


♦ Automation object model is nothing but collection of objects,methods and properties which are used to perform quicktest operations.Through out this object model we can perform any operation described in QTP interface. For every option in QTP menus(Interface) have Objects,methods and properties are there in this model.

♦ AOM is the concept to automate QTP itself.

Start  QTP, open an existing test and Run the Test:
Dim qtApp
Dim qtTest

'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application") 

'If QTP is notopen then open it
If  qtApp.launched <> True then 

qtApp.Launch 

End If 

'Make the QuickTest application visible
qtApp.Visible = True

'Set QuickTest run options
'Instruct QuickTest to perform next step when error occurs

qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False

'Open the test in read-only mode
qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", True 

'set run settings for the test
Set qtTest = qtApp.Test

'Instruct QuickTest to perform next step when error occurs
qtTest.Settings.Run.OnError = "NextStep" 

'Run the test
qtTest.Run

'Check the results of the test run
MsgBox qtTest.LastRunResults.Status

' Close the test
qtTest.Close 

'Close QTP
qtApp.quit

'Release Object
Set qtTest = Nothing
Set qtApp = Nothing 

Start  QTP, open an existing test and Run the Test  And Store Run Results in Specified Folder: 
Dim qtApp
Dim qtTest
Dim qtResultsOpt

'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application") 

'If QTP is notopen then open it
If  qtApp.launched <> True then 

qtApp.Launch 

End If 

'Make the QuickTest application visible
qtApp.Visible = True

'Set QuickTest run options
qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False

'Open the test in read-only mode
qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", True 

'set run settings for the test
Set qtTest = qtApp.Test

'Instruct QuickTest to perform next step when error occurs
qtTest.Settings.Run.OnError = "NextStep" 

'Create the Run Results Options object
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")

'Set the results location
qtResultsOpt.ResultsLocation = "D:\Result"

' Run the test
qtTest.Run qtResultsOpt 

'Check the results of the test run
MsgBox qtTest.LastRunResults.Status

'Close the test
qtTest.Close 

'Close QTP
qtApp.quit

'Release Object
Set qtResultsOpt = nothing
Set qtTest = Nothing
Set qtApp = Nothing

Start  QTP and open New test:
Dim qtApp
Dim qtTest

'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application") 

'If QTP is notopen then open it
If  qtApp.launched <> True then 
qtApp.Launch 
End If 

'Make the QuickTest application visible
qtApp.Visible = True

' Open a new test
qtApp.New 

Set qtApp = Nothing ' Release the Application object

 Open QTP and Connect to Quality Center and run QC script:
Dim qtApp ' Declare the Application object variable

'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application") 

'If QTP is notopen then open it
If  qtApp.launched <> True then 
qtApp.Launch 
End If 

'Make the QuickTest application visible
qtApp.Visible = True
If Not qtApp.TDConnection.IsConnected Then

' Make changes in a test on Quality Center with version control
qtApp.TDConnection.Connect "QC URL","DOMAIN Name","Project Name","User Name","Password",False

'QC URL = QC Server path
'DOMAIN Name = Domain name that contains QC project
'Project Name =Project Name in QC you want to connect to
'Username = Username to connect to Project
'Password = Password to connect to project
'False or True = Whether ‘password is entered in encrypted or normal. 
'Value is True for encrypted and FALSE for normal

'Example : qtApp.TDConnection.Connect
'"http://200.168.1.1:8080/qcbin","Default","proj1","qtpworld","qtp",false

End If

'Make Sure about your script path  and script name in QC
qtApp.Open "[QualityCenter] Subject\QCScriptPath\ScriptName", False
qtApp.Test.Run
qtApp.TDConnection.Disconnect

'Close QTP
qtApp.quit

'Release Object
Set qtApp = Nothing

Start  QTP, open an existing test, associate Object Repositories and save the test:
 
Dim qtApp
Dim qtTest
Dim qtRepositories

'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application") 
'If QTP is notopen then open it
If  qtApp.launched <> True then 
qtApp.Launch 
End If 

'Make the QuickTest application visible
qtApp.Visible = True
qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False
 
' Get the object repositories collection object of the "SignIn" action
Set qtRepositories = qtApp.Test.Actions("SignIn").ObjectRepositories 

' Add  Object repositry "Reposit.tsr" if it's not already associated wit action "SignIn"

If qtRepositories.Find("D:\Reposit.tsr") = -1 Then 
    qtRepositories.Add "D:\Reposit.tsr", 1
End If

'Save the test
qtApp.Test.Save

'Close QTP
qtApp.quit

'Release Object
Set qtLibraries = Nothing
Set qtTest = Nothing
Set qtApp = Nothing

 Start  QTP, open an existing test, associate libraries and save the test:
 
Dim qtApp
Dim qtTest
Dim qtLibraries

'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application") 

'If QTP is notopen then open it
If  qtApp.launched <> True then 
qtApp.Launch 
End If 

'Make the QuickTest application visible
qtApp.Visible = True

qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False

'Get the libraries collection object
Set qtLibraries = qtApp.Test.Settings.Resources.Libraries 

'If the library file "libraary.vbs" is not assiciates with the Test then associate it
If qtLibraries.Find("D:\libraary.vbs") = -1 Then 
    qtLibraries.Add "D:\libraary.vbs", 1  
End If

'Save the test
qtApp.Test.Save

'Close QTP
qtApp.quit

'Release Object
Set qtLibraries = Nothing
Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object

Start QTP, Open an Existing Test and Define Environment Variables:
 
Dim qtApp

'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application") 

'If QTP is notopen then open it
If  qtApp.launched <> True then 
qtApp.Launch 

End If 

'Make the QuickTest application visible
qtApp.Visible = True
' Open the test

qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False

' Set some environment variables
qtApp.Test.Environment.Value("Root") = "C:\"
qtApp.Test.Environment.Value("Password") = "QuickTest"
qtApp.Test.Environment.Value("Days") = 14

' Save the test
qtApp.Test.Save

'Close QTP
qtApp.quit

'Release Object
Set qtApp = Nothing

Start QTP with specified views: 
Dim qtApp

'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application") 

'If QTP is notopen then open it
If  qtApp.launched <> True then 
qtApp.Launch 

End If 

'Make the QuickTest application visible
qtApp.Visible = True
' Open the test

qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False

' Set some environment variables
qtApp.Test.Environment.Value("Root") = "C:\"
qtApp.Test.Environment.Value("Password") = "QuickTest"
qtApp.Test.Environment.Value("Days") = 14

' Save the test
qtApp.Test.Save

'Close QTP
qtApp.quit

'Release Object
Set qtApp = Nothing

Start QTP, Open an Existing Test and Get All Available Action Names From the Test: 
Dim qtApp
'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application") 

'If QTP is notopen then open it
If  qtApp.launched <> True then 
qtApp.Launch 
End If 

'Make the QuickTest application visible
qtApp.Visible = True

qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False, False

'Get count of Action in a test
oActCount=qtApp.Test.Actions.Count

For iCounter=1 to oActCount
' Get the first action in the test by index (start from 1)

MsgBox qtApp.Test.Actions(iCounter).Name

Next

'Close QuickTest
qtApp.Quit

' Release the Application object
Set qtApp = Nothing

Open and minimize QTP Window: 
Dim qtApp
'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application") 

'If QTP is notopen then open it
If  qtApp.launched <> True then 
qtApp.Launch 
End If 

'Make the QuickTest application visible
qtApp.Visible = True
qtApp.WindowState = "Minimized" ' Maximize the QuickTest window
qtApp.WindowState = "Maximized" ' Maximize the QuickTest window

'Release Object
Set qtApp = Nothing

Comments

Popular posts from this blog

JMeter Exceeded Maximum Number of Redirects Error Solution

While running performance test, JMeter allows maximum 5 redirects by default. However, if your system demands more than 5 redirects, it may result in JMeter exceeded maximum number of redirects error. In this post, we have listed down steps to overcome this error. Actual error in JMeter: Response code: “Non HTTP response code: java.io.IOException” Response message: “Non HTTP response message: Exceeded maximum number of redirects: 5” This error is noticed because  JMeter  allows maximum 5 redirects by default and your system may be using more than 5 redirects. You need to increase this count to more than 5 in jmeter.properties file. Follow below steps to achieve this. Navigate to /bin directory of your JMeter installation. Locate jmeter.properties file and open it in any editor. Search for “httpsampler.max_redirects” property in opened file. Uncomment the above property by removing # before it. Change to value to more than 5 Eg. 20. Save the file and restart JMet...

SSO with SAML login scenario in JMeter

SAML(Security Assertion Markup Language) is increasingly being used to perform single sign-on(SSO) operations. As WikiPedia puts it, SAML is an XML-based open standard data format for exchanging authentication and authorization data between parties, in particular, between an identity provider and a service provider. With the rise in use of SAML in web applications, we may need to handle this in JMeter. This step-by-step tutorial shows SAML JMeter scenario to perform login operation. First request from JMeter is a GET request to fetch Login page. We need to fetch two values ‘SAMLRequest’ and ‘RelayState’ from the Login page response data. We can do this by using  Regular Expression Extractor . These two values need to be sent in POST request to service provider. Refer below image to see how to do this. We will get an HTML login page as a response to the request sent in 1st step. We need to fetch values of some hidden elements to pass it in the next request. We...

VBScript Code - Function to convert CSV file into excel and viceversa in QTP using VBScript

We at times are required to convert excel files into csv to read as flat files and sometime require to convert a csv file into excel file to use excel features on the data.   Below function shows how to convert an csv file into excel file and vice versa. We can also convert to other formats based on constants Here constant value 23 is used to create a csv file and constant -4143 to save a file as xls file. Once the destination file is created, we can delete the source file as shown below.  In case of any issue in understanding the code, please add in comment section Call func_ConversionCSVExcel("E:\Test.csv", "E:\Test_converted.xls", "csvtoexcel") Public Function func_ConversionCSVExcel(strSrcFile, strDestFile, Conversion) on error resume next Set objExcel = CreateObject("Excel.application") set objExcelBook = objExcel.Workbooks.Open(strSrcFile) objExcel.application.visible=false objExcel.application.displayalerts=...