An Object model is a collection of classes or objects which can controlled by any program. An object model gives a facility to control the functionality of an application programmatically.
The UFT Automation Object Model(AOM) is a set of its classes and interfaces together with their properties, methods and events and their relationships.
Using AOM the functionalities of UFT can be controlled from any other applications/programs by using a scripting or programming language.
The functionalities that can be controlled are listed below but not limited to-
- Loads all the required add-ins for a test.
- Makes QTP visible while execution
- Opens the Test using the specified location
- Associates Function Libraries
- Specifies the Common Object Sync Time Out.
- Start and End Iteration
- Enable/Disable Smart IDentification
- On Error Settings
- Data Table Path
- Recovery Scenario Settings
- Log Tracking Settings
Generating Automation Script -
The UFT provides an easy option to generate automation scripts for few settings.
- Test Settings dialog box File---> Settings
- Options Dialog box Tools---> Options ----> GUI Testing
- Object Identification Dialog box Tools ---> Object Identification
These dialog boxes contain a generate script button which generates and automation script file (.vbs) by just clicking on it as shown below.
Write a script to start UFT, open an existing test and run the Test:
Dim qtApp, qtTest
'Create the QTP Application objectSet qtApp = CreateObject("QuickTest.Application")'If QTP is notopen then open itIf qtApp.launched <> True thenqtApp.LaunchEnd If'Make the QuickTest application visibleqtApp.Visible = True'Set QuickTest run options Instruct QuickTest to perform next step when error occursqtApp.Options.Run.ImageCaptureForTestResults = "OnError"qtApp.Options.Run.RunMode = "Fast"qtApp.Options.Run.ViewResults = False'Open the test in read-only modeqtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", True'set run settings for the testSet qtTest = qtApp.Test'Instruct QuickTest to perform next step when error occursqtTest.Settings.Run.OnError = "NextStep"'Run the testqtTest.Run'Check the results of the test runMsgBox qtTest.LastRunResults.Status'Close the testqtTest.Close'Close QTPqtApp.quit'Release ObjectSet qtTest = NothingSet qtApp = Nothing Write a script to launch UFT, Open an existing test and Run the Test andStore Run Results in Specified Folder:
Dim qtApp, qtTest, qtResultsOpt'Create the QTP Application objectSet qtApp = CreateObject("QuickTest.Application")'If QTP is notopen then open itIf qtApp.launched <> True thenqtApp.LaunchEnd If'Make the QuickTest application visibleqtApp.Visible = True'Set QuickTest run optionsqtApp.Options.Run.ImageCaptureForTestResults = "OnError"qtApp.Options.Run.RunMode = "Fast"qtApp.Options.Run.ViewResults = False'Open the test in read-only modeqtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", True'set run settings for the testSet qtTest = qtApp.Test'Instruct QuickTest to perform next step when error occursqtTest.Settings.Run.OnError = "NextStep"'Create the Run Results Options objectSet qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")'Set the results locationqtResultsOpt.ResultsLocation = "D:\Result"' Run the testqtTest.Run qtResultsOpt'Check the results of the test runMsgBox qtTest.LastRunResults.Status'Close the testqtTest.Close'Close QTPqtApp.quit'Release ObjectSet qtResultsOpt = nothingSet qtTest = NothingSet qtApp = Nothing
Write a script to launch UFT and open New test:
Dim qtApp, qtTest'Create the QTP Application objectSet qtApp = CreateObject("QuickTest.Application")'If QTP is notopen then open itIf qtApp.launched <> True thenqtApp.LaunchEnd If'Make the QuickTest application visibleqtApp.Visible = True' Open a new testqtApp.NewSet qtApp = Nothing ' Release the Application object
Write a script to launch UFT and Connect to Quality Center and run QC script:
'Declare the Application object variable
Dim qtApp'Create the QTP Application objectSet qtApp = CreateObject("QuickTest.Application")'If QTP is notopen then open itIf qtApp.launched <> True thenqtApp.LaunchEnd If'Make the QuickTest application visibleqtApp.Visible = TrueIf Not qtApp.TDConnection.IsConnected Then'Make changes in a test on Quality Center with version controlqtApp.TDConnection.Connect "QC URL","DOMAIN Name","Project Name","User Name",
"Password",FalseEnd If'Make Sure about your script path and script name in QCqtApp.Open "[QualityCenter] Subject\QCScriptPath\ScriptName", FalseqtApp.Test.RunqtApp.TDConnection.Disconnect'Close QTPqtApp.quit'Release ObjectSet qtApp = Nothing
Write a script to launch a UFT, open an existing test, associate Object Repositories and save the test:
Dim qtApp, qtTest
Dim qtRepositories
'Create the QTP Application objectSet qtApp = CreateObject("QuickTest.Application") 'If QTP is notopen then open itIf qtApp.launched <> True then qtApp.Launch End If 'Make the QuickTest application visibleqtApp.Visible = TrueqtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False' Get the object repositories collection object of the "SignIn" actionSet 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", 1End If'Save the testqtApp.Test.Save'Close QTPqtApp.quit'Release ObjectSet qtLibraries = NothingSet qtTest = NothingSet qtApp = Nothing
Write a script to launch UFT, open an existing test, associate libraries and save the test:
Dim qtApp, qtTest, qtLibraries
'Create the QTP Application objectSet qtApp = CreateObject("QuickTest.Application") 'If QTP is notopen then open itIf qtApp.launched <> True then qtApp.Launch End If 'Make the QuickTest application visibleqtApp.Visible = TrueqtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False'Get the libraries collection objectSet qtLibraries = qtApp.Test.Settings.Resources.Libraries 'If the library file "libraary.vbs" is not assiciates with theTest then associate itIf qtLibraries.Find("D:\libraary.vbs") = -1 Then qtLibraries.Add "D:\libraary.vbs", 1 End If'Save the testqtApp.Test.Save'Close QTPqtApp.quit'Release ObjectSet qtLibraries = NothingSet qtTest = Nothing ' Release the Test objectSet qtApp = Nothing 'Release the Application object
Write a script to launch UFT , Open an Existing Test and Define Environment Variables:
Dim qtApp,
'Create the QTP Application objectSet qtApp = CreateObject("QuickTest.Application") 'If QTP is notopen then open itIf qtApp.launched <> True then qtApp.Launch End If 'Make the QuickTest application visibleqtApp.Visible = True' Open the testqtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False' Set some environment variablesqtApp.Test.Environment.Value("Root") = "C:\"qtApp.Test.Environment.Value("Password") = "QuickTest"qtApp.Test.Environment.Value("Days") = 14' Save the testqtApp.Test.Save'Close QTPqtApp.quit'Release ObjectSet qtApp = Nothing
Write a script to launch a UFT with specified views:
Dim qtApp
'Create the QTP Application objectSet qtApp = CreateObject("QuickTest.Application") 'If QTP is notopen then open itIf qtApp.launched <> True then qtApp.Launch End If 'Make the QuickTest application visibleqtApp.Visible = True' Open the testqtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False' Set some environment variablesqtApp.Test.Environment.Value("Root") = "C:\"qtApp.Test.Environment.Value("Password") = "QuickTest"qtApp.Test.Environment.Value("Days") = 14' Save the testqtApp.Test.Save'Close QTPqtApp.quit'Release ObjectSet qtApp = Nothing
Write a script to launch a UFT, Open an Existing Test and Get All Available Action Names From the Test:
Dim qtApp'Create the QTP Application objectSet qtApp = CreateObject("QuickTest.Application")'If QTP is notopen then open itIf qtApp.launched <> True thenqtApp.LaunchEnd If'Make the QuickTest application visibleqtApp.Visible = TrueqtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False, False'Get count of Action in a testoActCount=qtApp.Test.Actions.CountFor iCounter=1 to oActCount' Get the first action in the test by index (start from 1)MsgBox qtApp.Test.Actions(iCounter).NameNext'Close QuickTestqtApp.Quit' Release the Application objectSet qtApp = Nothing
Write a script to launch UFT, Open and minimize UFT Window:
Dim qtApp'Create the QTP Application objectSet qtApp = CreateObject("QuickTest.Application")'If QTP is notopen then open itIf qtApp.launched <> True thenqtApp.LaunchEnd If'Make the QuickTest application visibleqtApp.Visible = TrueqtApp.WindowState = "Minimized" ' Maximize the QuickTest windowqtApp.WindowState = "Maximized" ' Maximize the QuickTest window'Release ObjectSet qtApp = Nothing
No comments:
Post a Comment
Note: only a member of this blog may post a comment.