Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Automation Object Model in QTP : Questions and Answers

In this article, we will try to understand Automation Object Model in QTP through subjective and multiple choice questions:

Question 1: What is UFT AOM?


Answer: AOM stands for Automation Object Model.The UFT AOM is a set of objects, methods, and properties that enable you to control essentially all test settings ad test options. Using the objects, methods, and properties exposed by the UFT automation object model, along with loops and conditional statements, we can perform following tasks using Automation object model:
1.   Execution of Test Scripts from VB Script. This helps in execution of tests from QTP and scheduling tests to run on remote machine. Test can be run in host machine/remote machine but QTP needs to be installed in host/remote machine in which test script needs to be executed.
2.  We can change configurations (Test Settings and options) at runtime of QTP tests.
3.  We can save test or component using AOM.
4.  Using Initialization script that launch UFT automatically can enable same settings/options executing from multiple machines.

Question 2: We can create an object of Quick Test in VBScript using ......


a.      Set qtApp = CreateObject("QuickTest.Application", "MyServer")
b.      Set qtApp = CreateObject("QuickTest.Application")
c.       Set qtApp As CreateObject("QuickTest.Application")
d.      Set qtApp as CreateObject(“Scripting.QuickTest”)

Answer: We can create an object of QuickTest in VBScript using a) or b). We need to provide server details as shown in option a), in case we need to run test on a remote machine. In case we have to run test in the same machine, we can use option b), i.e without Server Parameter.

Question 3: How can we associate a library at runtime with QTP test using AOM?


Answer: We can add a library using AOM as follows:

Create an object of QTP object.
Set qtApp = CreateObject(“Quicktest.Application”);

Multiple libraries can be associated with test as follows:
qtApp.Test.Settings.Resources.Libraries.Add "C:\Common_Func.vbs"
qtApp.Test.Settings.Resources.Libraries.Add "C:\Business_Func.vbs"
files = "C:\Common_Func.vbs| C:\Business_Func.vbs"
qtApp.Test.Settings.Resources.Libraries.Add(files)
In addition to AOM, we can associate libraries using function LoadFunctionLibrary FileName or ExecuteFile FileName

Question 4: Can we generate script automatically for all test settings and options: Yes/No


Answer: We can generate AOM scripts for all test settings, and test options in QTP.
a.      Script for all the test settings can be generated from File>Settings>Properties
b.      Script for all the test option can be generated from Tools>Options>GUI Testing>General

Question 5: How can we associate repositories with a test in QTP using AOM?


Answer: An object Repository is associated with action in the test and not the test as whole. We can associate object repository with an action as shown in the example below:

Set Qtpapp = createObject(“Quicktest.Application”)
Qtpapp.Open “C:\SampleTest1”,False,False
Set qtrep = Qtpapp. qtApp.Open "C:\Tests\Test1", False, False ' Opens a test in qtp
Set qtRepositories = qtApp. Test.Actions(“Action1”).ObjectRepositories  ‘Creates an object of repository collection i.e all repositories associated with a test action
If qtRepositories.Find(“C:\ORTest.tsr”) = -1 Then ‘If OR is already associated with a test, do nothing else add the required shared object repository.
    qtRepositories.Add “C:\ORTest.tsr”, 1
End If

Question 6: Can we stop a test execution through AOM?


Answer: Yes, we can stop a test from AOM, but the question arises, why do stop test from AOM when we can stop a test using exitTest statement. Many a times,exit statement does not work in QTP 11 when the exit statement was called from inside functions called from function in vbs library. In case exitTest statement does not work we can exit a test using below code:

Set qtAppObj = CreateObject("quicktest.application")
qtAppObj.Test.Stop

Question 7: Which of the following method of recovery object is used to activate recovery scenario through AOM?

a.      Activate
b.      Add
c.       Enabled
d.      Focus
Answer: we can enable a recovery scenario using enabled method of recovery object.

Question 8: How can we connect to ALM using VBScript?


Answer: Using the below code, we can connect to ALM through VBScript using QuickTest Application object as shown below:
Set qtApp = CreateObject ("QuickTest.Application")
If  qtApp.launched <> True then
     qtApp.Launch
End If
qtApp.Visible = "true"
If Not qtApp.TDConnection.IsConnected Then
      qtApp.TDConnection.Connect QCurl, DomainName, ProjectName, UserName, Password, False
End If


3 comments:

  1. It is very informative. Thanks for sharing.

    But I have a question. Lets say i have a scenario where in between the execution i need to restart my system and start the execution where i stopped it.

    So my requirement is, when stopping the script / restarting the system i need to store the state and values of all the objects and variables and when i restart the system i need to access those state/values and continue the execution. Is it possible?

    Please give me your comments / suggestions.

    Thank you

    ReplyDelete
  2. Hi Pratap,

    Thanks for liking the post.

    Once system is restarted, the execution can not proceed from the same step. In case you are executing the test from QC or an external machine, what I can suggest is ::

    1. Divide the test into two tests, once with step before execution and rest with steps after execution.
    2. From another remote machine/qc, Run test 1, wait for 300 sec(expected time to machine to restart) by inserting sleep statement in vbscript if executing form vbs file or another test in another machine just waiting for required time if running from ALM.
    3. Before completion of test 1, save all the required variables in a vbs file or excel file(data file) and this data can be used by test2) once machine is restarted.

    Anyone, please suggest if better approach than this

    ReplyDelete
  3. I have 2 questions and I'm seeking advice.

    1. I have 2 Windows based PCs that I need to run/share my web applications test scripts on - one is Windows 7 and the other is Windows 8. Both have UFT installed, same version.
    I need to be able to run the same scripts on both from time to time. Is this not a good idea, and if it's not unusual, what is the best way to switch from machine to machine? I'm hoping one machine won't add bits to the script that the other won't recognize causing errors.


    2. Is there a recommendation you can make for best settings in UFT?

    ReplyDelete