• Tech Travel Hub is your one stop, ultimate tour guide to all things tech, travel, visas and digital nomads
  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact
Menu
  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact
View Blog
April 6, 2023April 6, 2023

How To Work With Automation Object Model In UFT?

What is Automation Object Model In UFT?

AOM stands for the Automation Object Model. This is a way to use UFT/QTP  and its resources. By this approach, we can control the QTP from a separate program like-a VBS, macro. This is accomplished using the COM interface. that gives them the freedom to access the all most 90% of the components of the software.

Using UFT/QTP we can automate the application under test, and using the AOM- Automatic Object Model, we can automate the UFT/QTP itself. By Using the objects, methods, and properties exposed by the UFT/QTP automation object model, we can write scripts that configure UFT/QTP options and run components instead of performing these operations manually using the UFT/QTP interface.

Based on COM, AOM can communicate with the components. (access different methods, properties, object). It provides a set of controls, methods to help a developer/automation tester to execute the script without touching UFT. It is externally useful while triggering batch run from Jenkins or making one-click automation.

What is the proper use case for Automation Object Model?

Automation scripts are especially useful for performing the same tasks multiple times or on multiple components, or quickly configuring UFT/QTP according to our needs for a particular environment or application.

we can use the UFT/QTP Professional automation object model to write scripts that automate our UFT/QTP operations. The UFT/QTP automation object model provides objects, methods, and properties that enable us to control UFT/QTP from another application.

  • This is useful when we want to change the QTP /UFT options during run time
  • Want to control UFT/QTP from our other application
  • Want to do some repetitive task in a regular interval
  • Migrating to continuous integration
  • I want to schedule scripts in a machine.

AOM is the better solution for the above uses. It uses COM (Component Object Model)- In the below section, we will see how to create an object of UFT application and work with different components of it.

What is AOM- Automatic Object Model ?

Essentially all configuration and run functionality provided via the UFT/QTP interface is in some way represented in the UFT/QTP automation object model via objects, methods, and properties.Although a one – on – one comparison cannot always be made, most dialog boxes in UFT/QTP have a corresponding automation object, most options in dialog boxes can be set and/ or retrieved using the corresponding object property, and most menu commands and other operations have corresponding automation methods.

We can use the objects, methods, and properties exposed by the UFT/QTP automation object model, along with standard programming elements such as loops and conditional statements to design our script.

Automation scripts are especially useful for performing the same tasks multiple times or on multiple tests or components, or quickly configuring UFT/QTP according to our needs for a particular environment or application.

For example, we can create and run an automation script from Microsoft Visual Basic that loads the required add-ins for a test or component, starts UFT/QTP invisible mode, open the test or component, configures settings that correspond to those in the Options, Test or Business component Settings, and Record and Run Settings dialog boxes, runs the test or component and saves the test or component.

We can then add a simple loop to our script so that our single script can perform the operations described above for multiple tests or components.

we can also create an initialization script that opens UFT/QTP with specific configuration settings. We can then request all our test engineers to open UFT/QTP using the automation script to ensure that all of our testers are always working with the same configuration.

Stategies when to use Automation of UFT/QTP

Creating a useful UFT/QTP automation script requires planning, design time and testing we must always weigh the initial investment with the time and human – resources saving us from automating potentially long or tedious tasks.

Any UFT/QTP operation that we must perform many times in a row or must perform on a regular basis is a good candidate for a UFT/QTP automation script.

The following are just a few examples of useful UFT/QTP automation scripts:

  • Initialization scripts – we can write a script that automatically starts UFT/QTP and configures the options and the settings required for recording on a specific environment.
  • Maintaining our tests or components – we can write a script that iterates over our working collection of tests and components to accomplish a certain goal.
  • Updating values – we can write a script that opens each test or component with the proper add-ins, runs it in update run mode against an updated application and saves it when we want to update the values in all of our tests and components to match the updated values in our application.
  • Applying new options to existing tests or components – When we upgrade to a new version of UFT/QTP, we may find that the new version offers certain options that we want to apply to our existing tests and components. we can write a script that opens each existing test and component, sets values for the new options, then saves and closes it.
  • Calling UFT/QTP from other applications -we can design our own applications with options or controls that run UFT/QTP automation scripts. For an example, we can create a Web form or simple Windows interface from which a product manager can schedule UFT/QTP runs, even if the manager is not familiar with UFT/QTP.
  • Basic Elements of Automatic Object Model

    Like most automation object models, the root object of the UFT/QTP automation object model is the Application object. The Application object represents the application level of UFT/QTP.

    we can use this object to return other elements of UFT/QTP Test such as the Test object (Which represents a test or component document), Options object represents(which represents the Options dialog box), or Addins collection (which represents a set of add – ins from the Add in manager dialog box), and to perform operations like loading add – ins starting UFT/QTP, opening and saving tests or components, and closing UFT/QTP.

    Each object returned by the Application object can return other objects, perform operations related to the object and retrieve and/ or set properties des associated with that object.

    Every automation script begins with the creation of the UFT/QTP Application object. Creating this object does not start UFT/QTP. It simply provides an object from which we can access all other objects,methods and properties of the UFT/QTP automation object model.

     

    There are three popular ways to create an object of the quick test-

    Visual Basic Way:

    Dim qtApp as QuickTest.Application
    set qtApp=New QuickTest.Application
    qtApp.Launch

    VBScript way:

    Dim qtApp
    set qtApp=CreateObject("QuickTest.Application")
    qtApp.Launch

    Java Script way

    var qtApp=new ActiveXObject("QuickTest.Application")
    qtApp.Launch

    You can choose anyone. But in this blog I am going to take Vb scripting: The structure for the rest of our script depends on the goals of the script. we may perform a few operations before we start UFT/QTP such as retrieving the associated to add – ins for a test or component, loading add – ins, and instructing UFT/QTP to open in visible mode.

    After we perform these preparatory steps, if UFT/QTP is not already open on the computer, we can open UFT/QTP using the Application. Launch method. Most operations in our automation script are performed after the Launch method.

    When we finish performing the necessary operations, or we want to perform operation require closing and restarting UFT/QTP, such as changing the set of loaded add – in, we need to use Application.Quit method.

     

    Basic Settings

    Dim qtApp
    set qtApp=CreateObject("QuickTest.Application")
    qtApp.Launch  ' launch QTP/UFT
    qtApp.Activateview "Expertview" 'Open Expert View can be "keyWordView"
    qtApp.showPaneScreen "ActiveScreen",True 'show the Active Screen can also be set 
    'as "Debugviewer",True or "DataTable" False
    qtApp.WindowState="Maximized" 'Maximize the UFT,can aslo be set as "Minimized"
    qtApp.Test.Settings.web.BrowserNavigationTimeOut=50000
    qtApp.Test.Settings.web.ActiveScreenAccess.userName="myUserName"
    qtApp.Test.Settings.web.ActiveScreenAccess.password="password"

    Run Options

    qtApp.options.run.ImageCaptureForTestResult="onError"
    qtApp.options.run.RunMode="Fast" can be set to Normal or slow based on the network speed
    qtApp.options.run.viewResult=False ' can be true if you want the qtp result to display 
    'after a run
    qtApp.Test.Settings.Run.ObjectSyncTimeOut=100000
    qtApp.Test.Settings.Run.DisableSmartIdentification=false 'can be true
    

    Run Settings

    This can be achieved in two ways …

    1. Either you follow the hierarchy
    2. Or create an object of the test module

     

    set qtTest=qtApp.Test
    qtTest.settings.run.IterationMode="AllIterations" ' can be rngIterations or rngAll
    'to run from iteration x to iteration y
    qtTest.settings.run.startIteration=1
    qtTest.settings.run.EndIteration=3
    qtTest.settings.run.onError="NextStep" 'can be stopped by passing "Stop"
    ' or we can show error dialog by passing "Dialog"
    

    Result Settings

    Dim qtResultOpt
    set qtResultOpt=CreateObject("quickTest.Run ResultsOptions")
    qtResultOpt.ResultqtTest.Run qtResultOpt

    if you move all result to a file:

    const forReading=1
    const forWritting=2
    dim fso,f,result
    set fso=CreateObject("scripting.FileSystemObject")
    set f=fso.openTextfile("c:testresult.txt",forWritting,True)
    'you can create the text file by using fso
    set qtResultOpt=CreateObject("quickTest.Run ResultsOptions")
    qtResultOpt.ResultqtTest.Run qtResultOpt
    result=qtTest.LastRunresults.Status
    f.write("test1:Name of the test")
    f.write(result)
    f.writeBlankLines(1)
    'close f,set objects to null if you have no further use
    

    Library Settings

    dim qtlibs
    qtlibs=qtApp.Test.Settings.Resolurces.libraries
    'to remove all
    qtLibs.removeAll
    Add a library:
    If qtLibs.find("path of the lib"abc.vbs")=-1 then
    qtlibs.Add "path of the lib"abc.vbs",1
    End If
    qtApp.Test.Save ' in this case you have to open the test in edit mode,readonly flse

    Repository Settings

    set qtRepositories=qtApp.Test.Action("Action Name").ObjectRepositories ' for which the 
    'repository needs to be added
    If qtRepositories.find("path of the lib"abc.tsr")=-1 then
    qtRepositories.Add "path of the lib"abc.tsr",1
    End If
    

    Environment Variable Settings

    qtApp.Test.Environment.value("userName")="myUserName"
    qtApp.Test.Environment.value("password")="password"
    

    Action Settings

    qtApp.Test.Actions.Count 'return the actions present in the test
    qtApp.Test.Actions("Name of the action like 'Action1'").Description
    'returns the description
    qtApp.Test.Actions("Name of the action like 'Action1'").Name
    'returns the name
    'run a particular action by index
    qtApp.Test.Actions(index as 1/2).Run
    or
    setqtTest=qtApp.Test.Action(index)
    RunAction "Action2",oneIteration 'can be multiple iterations by providing the iteration number
    

    Recovery Settings

    'removing all recovery
    set qtTestRecovery=qtApp.Test.Settings.Recovery
    If qtTestRecovery.count>0 then
    qtTestRecovery.RemoveAll
    End If
    'add recovery
    qtTestRecovery.Add "path of the recovery file","Name of the recovery",1,"description"

    ‘enabling the recovery:

    For intIndex=1 to qtTestRecovery.count
    qtTestRecovery.item(intIndex).Enabled=True
    Next
    or
    qtTestRecovery.Enabled=true
    'specify when to activate
    qtTestRecovery.setActivationMode="onError"

    Datatable Settings

    qtApp.Test.Settings.Resources.DataTablePath="Path of your data table"
    

    Log tracking Settings

    with qtApp.Test.Settings.LogTracking
    .Includeinresult=False
    .port=18081
    .IP="127.0.0.1"
    .MinTriggerLevel="Error"
    .EnableAutoConfig=False
    .RecoverConfigAfterRun=False
    .configFile=""
    .MinConfigLevel="Warn"
    End With
    

    There are two launchers available out of the box.

    1. Web Application
    2. Window Application
    3. Web launcher Settings

      qtApp.Test.Settings.Launcher("Web").Activate=true 'can be false
      qtApp.Test.Settings.Browser="IE", Can be chrome,firefox if supports
      qtApp.Test.Settings.Address="www.google.com"
      qtApp.Test.Settings.CloseOnExit=true

      Windows Application launcher Settings

      qtApp.Test.Settings.Launcher("Window Application").Activate=true 'can be false
      qtApp.Test.Settings.Applications.RemoveAll 'removes all pre loaded Applications
      qtApp.Test.Settings.RecordOnQTDescendant="False" 'record settings
      qtApp.Test.Settings.RecordOnSpecifiedApplications=True

      Addins Settings

      arrAddins=qtApp.GetAssociatedAddinsForTest("Test path and Test Name")
      'check if loading is successful
      blnAddinRequired=False
      For Each testAddin in arrAddins
      If (qtApp.Addins(testAddin)).status <> "Active" then
      blnAddinRequired=True
      Exit for
      End if
      Next
      'if change in the loaded addins is necessary
      If blnAddinRequired Then
      Dim blnActivateOk
      blnActivateOk=qtApp.SetActiveAddins(arrAddins,error description)
      If Not blnActivateOk Then
      WScript.quit
      End if
      End if 
      

      Set Parameters

      To work with these, we need to create these parameters in QTP first.

      Set pDefcoll=qtApp.Test.ParameterDefination
      Set qtpParam=pDefcoll.GetParameters()
      on Error Resume Next
      qtpParam.Item("UserName").value="myUserName"
      qtpParam.Item("Password").value="myPassword"
      

      How to save Test

      If qtApp.Test.IsNew Then
      qtApp.Test.SaveAs "path of the script and Script Name"
      Else
      qtApp.Test.Save
      End If
      

      How to Connect To ALM/QC

      qtApp.TDConnections.Connect "QCURL","Domain","Project Name","UserName","Password",false
      

      How to Run a Test from ALM/QC

      qtApp.TDConnections.Connect "QCURL","Domain","Project Name","UserName","Password",false
      If qtApp.TDConnection.IsConnected Then
      qtApp.Open [QualityCentre]Subjectpathscript Name,False
      qtApp.Test.Run
      qtApp.TDConnections.Disconnect
      

      How to Log a bug in ALM/QC
      Here is a complete guide of the code: Here is a small different way to do:

      Dim qcApp
       Dim BugFact,NewBug
      Set qcApp = CreateObject("TDApiOle80.TDConnection")
      'Intilizing the QC connection
      qcApp.InitConnectionEx "https://alm.com/qcbin"
      'Verifying User is connected
      If qcApp.Connected Then
      Print "User Connected to ALM Server"
      Else
      Print "User is not Connected to ALM Server"
      Exit Function
      End If
      'Filling the UserName and Password for ALM
      qcApp.Login sUName,sPwd
      'Verifying User is Logged into ALM
      If qcApp.LoggedIn Then
      Print "User is Logged into ALM Server"
      Else
      Print "User is not Logged into ALM Server"
      Exit Function
      End If
      'Connects user to specified Domain and Project
      qcApp.Connect sDomain,sProject
      Set BugFactory=qcApp.BugFactory
      Set Bug=BugFactory.AddItem(Nothing)
      Bug.Status="New"
      Bug.Summary="Test Bug"
      Bug.Priority="3-Medium"
      Bug.AssignedTo="Dev Team"
      Bug.DetectedBy=myUserName
      Bug.Post
      

      Easy Way to Build this AOM file: Setup everything in UFT/QTP:

      Option 1: Go to test settings->General Tab->Object Identification Tab->Click on Generate button->Provide the path->Provide the name->Click on save

      Option 2: Go to Test->Settings->Properties Tab->Click on Generate button->Provide the path->Provide the name->Click on save

      Option-3:Go to tools->Option->General Tab->Click on Generate button->Provide the path->Provide the name->Click on save after few settings you will be able to understand the settings.

    4. How to Close Any Application From VBA,QTP,VBScript?

      Few other things that can be done via AOM:
      This is the code where you can close any application.Even from QTP/UFT, You can give this command to stop any application. Logic The steps are…

      • Go to Task Manager.
      • Find out which application you want to close.
      • Right-click on it.
      • Go to the process and Select it.
      • It will navigate you to the Process page.
      • Just remember the process name of the corresponding application.
      • Private Function CloseAppliction()
        Set objWMIService = GetObject("winmgmts:\.rootCIMV2")
        Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = qlock.exe'")
        For Each objProcess in colProcess
        objProcess.Terminate()
        Next
        Set objWMIService = Nothing
        Set colProcess = Nothing
        End Function
        
        Public Function fn_close_all_excel_files()
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootcimv2")
        Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'EXCEL.EXE'")
        For Each objProcess in colProcessList
        objProcess.Terminate()
        Next
        End Function
         

        How to Connect QTP or UFT with QC?

        
        Set qtApp = CreateObject("QuickTest.Application")
        If qtApp.TDConnection.IsConnected Then
        msgbox "QC"
        Else
        msgbox "Local"
        End If
         

        Another way:

        
        if QCUtil.IsConnected then
        Reporter.ReportEvent 0, "Connected", "Connected to server: " + QCUtil.QCConnection.ServerName + chr (13) +"Project: " +
        QCUtil.QCConnection.ProjectName + chr (13) + "Domain: " + QCUtil.QCConnection.DomainName
        else
        Reporter.ReportEvent 1, "Not connected", "Not connected to Quality Center"
        end if
         

        Refer the below code under Library Settings

        dim qtlibs
        qtlibs=qtApp.Test.Settings.Resolurces.libraries
        'to remove all
        qtLibs.removeAll
        Add a library:
        If qtLibs.find("path of the lib"abc.vbs")=-1 then
        qtlibs.Add "path of the lib"abc.vbs",1
        End If
        qtApp.Test.Save ' in this case you have to open the test in edit mode,readonly false
        

        But there two ways to do that:
        1. Execute File <path of the VBS/qfl file>
        You have to write these lines for all library files one by one.
        2. LoadFunctionLibrary <path of qfl/vbs> We can give many library files path with names separated by comma(,). I could have opted for one of these two methods, but one issue compelled me to think otherwise. The issue was, there could be multiple libraries as and when the project grows up.

        So every time, if a person going to add a new function library, Somebody needs to update the above lines in code just to load the files. That triggered the cost of maintenance during function library addition.

        Below is a way I have coded to handle addition of all libraries with our script dynamically using AOM way : The precondition is to have a folder called Libraries where we need to place all libraries.

        Dim qtApp
        Set qtApp=CreateObject("QuickTest.Application")
        Set objFso=CreateObject("Scripting.FileSystemObject")
        objLibPath=path of our Library folder ' Like C:TestLibrary
        Set objFolder=objFso.GetFolder(objLibPath)
        Set colFiles=objFolder.Files
        qtApp.Launch ' launch QTP/UFT
        Set objLib=qtApp.Test.Settings.Resources.Libraries
        For Each objFile in colFiles
        fileName=objFile.Name
        If Not instr(fileName,".lck") Then ' sometimes I have seen .lck files are
        'created and not destroyed even if the QTP is closed
        if objLib.Find(objLibPath&fileName)=-1 Then
        objLib.Add objLibPath&fileName
        End If
        Else
        objFile.Delete 'Delete the .lck file
        End If
        Next
        

        How To Get Desktop Path Dynamically In QTP or UFT?

        In my initial days with QTP, frequently I needed to download some file to upload or download from or to the desktop.
        To be on safe side I always used an Environment variable which carried the value of the Desktop path.
        Like -Environment(“Desktop”).value= “path of the machine”
        So in every release, I use to tag this script as needs update during rerun in different machines.

        Later I found a nice solution to find out the desktop path dynamically.

        Set WSHShell = CreateObject("WScript.Shell")
        strShortcutLoc = WSHShell.SpecialFolders("Desktop")
        

        This is a Tested code that can be used to any machine. My problem resolved.

        How to make a script location independent in UFT or QTP?

        When my manager takes the script, he wants to run them from his D drive. But I have written the scripts in such a way that it gets executed and stores the results in an Excel at C drive. To avoid this, I want to get the current folder path. How to do that?

        The way to make script location-neutral

        what is required is to take the test path dynamically i.e how to make a script drive/area independent?

        let’s do it…

         

      • now go to
      • Script location independent UFT

        This is the option by which QTP determines from here the script is running. These are all environmental variables. Now what you need to do is to take the path by using the environment variable.

      • now if you are using this command…i.e. environment of test path…this will dynamically give you the path of the test running folder.

        now configure your testing here I mean the path and the folder structure. your problem is solved.

        How to Stop Screensaver or Screenlock in UFT or QTP via code?

        The scrips while running on unattended mode, needs this feature to disable screensaver or screen lock during script execution.

        This section is useful while we perform automation testing for more than 200 rows of data. As per our office or company policy, if a system is untouched for 15 minutes, the screen lock feature gets activated and we need a password to open the screen again. Automation faces regular challenges due to this activity. It is not always okay for UFT to get the screen locked. UFT/QTP may be unresponsive or may halt or stop the execution.

        Interestingly this screenslock creates issue with other testing tools like Selenium or TOSCA as Well. So even though this post talks about UFT,but we can apply them for Selenium or TOSCA or any other tools as well

        Process-1

        This sample piece of code gives a mouse move which stops to activate screen saver.. Here we are simulating a mouse click just to tell the Operating system(Windows) that the machine is not free and there is an active user working on it.

        
        Function Handle_SystemLock(Object, Method, Arguments, retVal)
        Set o=CreateObject("Mercury.DeviceReplay")
        o.mouseMove second(now),100
        Set o=Nothing
        End Function

        Screensaver or Screenlock

        Process-2

        We can use runtime co-ordinates “x” and “y” with mercury device replay feature,this should help us click on the item.

        
        xcord=Browser("ABC").Page("XYZ").getroproperty("x")
        ycord=Browser("ABC").Page("XYZ").getroproperty("Y")
        set obj=createobject("Mercury.devicereplay")
        obj.mousemove xcord + somevalue , ycord+somevalue
        obj.mousedblclick xcord + somevalue , ycord+somevalue,0

         

        Screensaver or Screenlock

        Process-3

        I have read this book posted here
        This is also an interesting solution.

        
        Dim WShShell,Value,Saved
        Dim Password
        'Password=Inputbox ("Enter Password")
        'If Password <> "running" then Wscript.quit
        Set WshShell=WScript.CreateObject("WScript.Shell")
        On Error Resume Next
        Value = WshShell.RegRead("HKCUControl PanelDesktopScreenSaveActive")
        Saved = WshShell.RegRead("HKCUControl PanelDesktopSaveScreenSaved")
        Err.Clear
        'MsgBox Value & "-" & Saved
        On Error Goto 0
        If Saved <> "1" then
        WSHShell.RegWrite "HKCUControl PanelDesktopSaveScreenSave",Value
        WSHShell.RegWrite "HKCUControl PanelDesktopSaveScreenSaved","1"
        WshShell.RegWrite "HKCUControl PanelDesktopScreenSaveActive","0"
        end if
        WScript.Quit(0)
        and this restores it...
        '::Title Restore Saved Screen Saver
        '::Version 0 - Date 05 Nov 2000
        Option Explicit
        Dim WShShell,Value,Saved
        Set WshShell=WScript.CreateObject("WScript.Shell")
        On Error Resume Next
        Value = WshShell.RegRead("HKCUControl PanelDesktopSaveScreenSave")
        Saved = WshShell.RegRead("HKCUControl PanelDesktopSaveScreenSaved")
        Err.Clear
        'MsgBox Value & "-" & Saved
        On Error Goto 0
        If Saved = "1" then
        WSHShell.RegWrite "HKCUControl PanelDesktopScreenSaveActive",Value
        WSHShell.RegWrite "HKCUControl PanelDesktopSaveScreenSaved","0"
        end if
        WScript.Quit(0)
        

        Screensaver or Screenlock

        Process-4

        
        Function DisablescreenSaver()
        Dim WSHShell, RegKey, ScreenSaver, Result
        Set WSHShell = CreateObject("WScript.Shell")
        RegKey = "HKCUControl PanelDesktop"
        ScreenSaver = WSHShell.RegRead (regkey & "ScreenSaveActive")
        If ScreenSaver = 1 Then 'Screen Saver is Enabled
        Result = MsgBox("Your screen saver is currently active." & _
        vbNewLine & "Would you like to disable it?", 36)
        If Result = 6 Then 'clicked yes
        WSHShell.RegWrite regkey & "ScreenSaveActive", 0
        End If
        Else 'Screen Saver is Disabled
        Result = MsgBox("Your screen saver is currently disabled." & _
        vbNewLine & "Would you like to enable it?", 36)
        If Result = 6 Then 'clicked yes
        WSHShell.RegWrite regkey & "ScreenSaveActive", 1
        End If
        End If
        End Function
        

        How to Use these codes:

        Copy these lines of codes into a notepad and save the notepad as “Test.VBS” to a the test’s main directory. Either you double click on it to activate before the test or using Execute command run this file.

      • How to Run Excel Macro using UFT?:

        This section talks about a generic problem in our daily testing life. Say I have a scenario where I need to generate some output through UFT and based on that output I need to do some operation in Excel.

        There are two ways to do that Either generate the output first to and excel and try to excel coding through UFT or simple generate the output and call a inbuilt macro that will do rest. I found the later one is the best solution…

        1.I have an excell sheet that needs to be run and execute its in built macro
        2. After the executed result of the macro,I need to add that output excell to UFT and start UFT execution

        We were having problems as the excell sheets data are dynamic and there was a manual intervention every time when we tried to do Step-1 and Step-2 one after another. Later the solution is found..
        The solution is:
        Strat the QTP execution->QTP will trigger the Macro->Then it will import the executed sheet ->do its normal execution.

        The code is:

        
        Set objExcel = CreateObject("Excel.Application")
        objExcel.Workbooks.Open("C:filename.xls")
        objExcel.Visible = True
        'Replace "macroname", "params1", "param2" with' the appropriate values
        objExcel.Run "macroname", "params1", "param2"
        'If there is no parameter for your macro .You can leave this place blank
        like
        objExcel.Run "macroname"
         

        How To Use Sendkey Function in QTP or UFT or VBScript

        Sendkey- the term says us that this is related to some key that needs to be sent. Now Questions are where ?? when?? how??

        Consider a scenario when you need to delete a few things from your drive or you need to select all the files or you need to take a screenshot automatically through scripting.

        There might be a scenario where QTP/UFT fails to record a step and still you need to automate that scenario.

        How do you go through manually…yes by keying Delete key or Alt+A or by pressing PrtSc.
        Right Now if the same has to done through QTP/UFT, we need to educate QTP regarding the same. Well, most of the time, we need to use sendkey function while doing an end to end Testing…I am not going in-depth of the idea… let’s go directly to the point…I am incorporating some basic codes which can be used.

        Let’s check out how to write a small function that does our work…

        
        Sub ctrlA()
        //This is for Ctrl+a command
        set WshShell = CreateObject("WScript.Shell")
        WshShell.Sendkeys "^"+"{a}"
        set WshShell = Nothing
        End Sub
         

        Let’s see some more examples…

        
        Sub shiftDel()
        //this is for Shift delete command
        set WshShell = CreateObject("WScript.Shell")
        WshShell.Sendkeys "+"+"{DEL}"
        set WshShell = Nothing
        End Sub
         

        Yes, you got the idea right…Now u need the list of all keys which can be sent during the runtime.
        Click on the link:http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx
        to get the list of all keys that can be sent.

        This is a very popular solution while working with UFT and advanced framework. Also, read VBScript Datatype for further understanding. While working with sendkeys don’t forget to use comments for readability.

        Happy sending..:)

        How To Enable UFT code to use Microsoft Word Spell Check

        The following (QTP) code shows a function for checking the number of spelling and grammar errors in a string. This function is also used to check the accuracy of a specific property in all the objects of a given application.

        
        Function NumberOfSpellErrors(strText) 
        Dim objMsWord 
        Set objMsWord = CreateObject("Word.Application") 
        objMsWord.WordBasic.FileNew 
        objMsWord.WordBasic.Insert strText 
        NumberOfSpellErrors = objMsWord.ActiveDocument.SpellingErrors.Count 
        objMsWord.Documents.Close (False) 
        objMsWord.Quit ' close the application 
        Set objMsWord = Nothing' Clear object memory 
        End Function 
        

        The following function uses the Spell errors function to check a specific property. Of all the objects with a given description which are under a given parent

        
        Sub CheckAllObjects(ParentObj, ObjDesc, PropName) 
        Dim ObjCol, idx, PropValue, OldReportMode 
        OldReportMode = Reporter.Filter 
        Reporter.Filter = 2 ' Report only errors 
        If (IsNull(ParentObj)) Then 
        Set ObjCol = Desktop.ChildObjects(ObjDesc) 
        Else 
        Set ObjCol = ParentObj.ChildObjects(ObjDesc) 
        End If 
        For idx=0 to ObjCol.count-1 
        PropValue = ObjCol.Item(idx).GetROProperty(PropName) 
        RetVal = NumberOfSpellErrors(PropValue) ' The actual spell check result 
        If (RetVal > 0) Then 
        ReportText = "Object #" & idx+1 & ": The '" & PropName & "' Property has " & RetVal & " spell errors (" & PropValue & ")" 
        Reporter.ReportEvent 1, "Spell Check", ReportText 
        End If 
        Next 
        Reporter.Filter = OldReportMode 
        End Sub

        How to Toggle Between Faster Mode and Normal Mode In QTP .

        Normally we run all our QTP Scripts in Normal mode. This is required as Scripts might interact with web pages or Some applications (may be desktop or some other applications).

        Think of some other scenarios, where our script will not interact with other application like testing painting or analog scripting testing. For those cases we don’t need not run our script in Normal mode. We can go with Faster mode.

        Again there might be scenarios where our script might do some analog activity and can interact with other applications. For this mixture  applications we need to run some portion of our script in Faster mode and some part will run in normal mode.

        For solving this third point we need to toggle between faster mode and normal mode.

        Now how to code in QTP which will toggle between faster and normal mode..
        Setting Run mode as Normal

        Dim App 'As Application
        Set App = CreateObject("QuickTest.Application")
        App.Visible = True
        App.Options.Run.RunMode = "Normal"
        App.Options.Run.StepExecutionDelay = 100

        Setting Run mode as Faster

        Dim App 'As Application
        Set App = CreateObject("QuickTest.Application")
        App.Visible = True
        App.Options.Run.RunMode = "Fast"

         

        There is also one more run mode called Maintenance Mode run.

Post navigation

Previous post
Next post

Umer Umer

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Zoom Meeting Outfits: 4 Comfortable Yet Dressy Tops to Wear on Your Next Video Call
  • Zoom Clone: 6 Significant Benefits To Lure You In Launching
  • Your Shopify Store – Top 5 Essential Inventory Management Apps
  • All-inclusive You Need To Know About Skirting Beyond 2020
  • Yohuton Health and Fitness Smartwatch for Men Beyond 2020

Categories

  • Adventure
  • Agile Methodology
  • AI
  • All world Tour
  • Android Development
  • Ansible
  • App
  • App Development
  • Artificial Intelligence
  • AWS
  • Bitcoin
  • BlockChain
  • Blogging
  • Box Packing
  • Business
  • business
  • Business Communication
  • buying guide
  • C
  • car
  • Care
  • Certification
  • Certification
  • Chatbot
  • cinema
  • Cloud Tech
  • Companies
  • Content Marketing
  • Corporate
  • covid-19
  • crucible
  • Cryptocurrency
  • Database
  • DevOps
  • DevOps
  • Digital Marketing
  • Drawing
  • Dress
  • Earn Money Online
  • Educational
  • Employment
  • Entertainment
  • Exceptions In Java
  • Fashion
  • Festivals
  • Finance
  • Fitness
  • Food
  • Game
  • Gift ideas
  • Graphic Designers
  • Groovy
  • Health
  • Health
  • home
  • home improvement
  • HR
  • IllegalThreadStateException in Java
  • India Tour
  • Instagram
  • Ios
  • ISO
  • Java
  • Javascript
  • job
  • Kids Section
  • Kitchen
  • Law
  • Life Style
  • Lifestyle
  • Lifestyle Home Improvement
  • Magento
  • Main Stories
  • Management
  • Mattress
  • Motorable
  • Movie
  • nursing
  • Office Productivity
  • Pendrive
  • Perspective
  • Pet
  • Popular
  • Programming
  • Python
  • RDT
  • Relationships
  • Selenium
  • SEO
  • Skin
  • SOA
  • SOAPUI
  • Social Media
  • Social Media Marketing
  • Software
  • software development
  • Software Development Model
  • Software Engineering
  • Software Testing
  • Sports
  • Startup
  • T Robot
  • TDD
  • Tech
  • Tech News
  • Tech News
  • Technology
  • Tool
  • Tour Guide
  • Tour Guide
  • Travel
  • UFT
  • Uncategorized
  • USB Cable
  • VBscript
  • VPN
  • Web Development
  • WebHosting
  • WebServices
  • Wildlife
  • Wordpress
  • Yoga
  • Youtube

Tags

Instagram Instagram Marketing Marketing SEO Thoptv App

Categories

  • Tech
  • Travel
  • Visas
  • Digital Nomad
  • Tech
  • Travel
  • Visas
  • Digital Nomad

Publishing

If you would like to publish on our site, please email admin@techtravelhub.com

Quick Links

  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact
  • Home
  • Blog
    • Technology
      • General Tech
      • Blogging
      • Java
    • Lifestyle
      • General Lifestyle
    • Travel
    • Educational
    • Business
  • About
  • Contact

Contact

Tech Travel Hub LLC

Address:
8 The Green STE A
Dover
Delaware, 19901

Phone: +1 302 956 9948