Tricentis Tosca 16.0 Released on Feb-2023 ----- UFT has been upgraded from UFT 15.0.1 to UFT One 15.0.2, Beginning at November 2020.

Tuesday, 26 June 2018

CreateObject in QTP/vbScript

CreateObject is function which creates a reference to the specified object. You can then use the reference object to access the methods/properties of the specified object.

As createobject returns a reference to object, you must use Set to assingn it to a variable.

Set objExcel=CreateObject(“Excel.Application”)
'Adding a workbook
Set objWorkBooj= objExcel.Workbooks.Add
'Activating the sheet
Set objSheet=objWorkBook.Worksheets("Sheet1")
'Writing values to excel
objExcel.Cells(row,column)=<”Your value>


Below is the list of most commonly used objects. I hope you find it useful.


S.No
Object
Description
1
Set ObjectName= CreateObject("Wscript.shell")
Provides access to the native Windows shell. Provides functions to read system information and environment variables, to work with the registry and to manage shortcuts.
2
Set ObjectName = CreateObject("WScript.Network")
Provides access to the shared resources on the network to which the computer is connected.
3
Set ObjectName = Createobject("Excel.Application")
Perform operations on MS Excel.
4
Set ObjectName = CreateObject("Word.Application")
Perform operations on MS Word.
5
Set ObjectName = CreateObject("Outlook.Application")
Perform operations on MS Outlook.
6
Set ObjectName = CreateObject("InternetExplorer.Application")
Perform operations on Internet Explorer.
7
Set ObjectName = Createobject("QuickTest.Application")
Perform operations on Quick Test Professional (QTP).
8
Set ObjectName = CreateObject("QuickTest.UpdateRunOptions")
A collection of properties that indicate preferences for the Update Run in QTP.
9
Set ObjectName = CreateObject("QuickTest.RunResultsOptions")
A collection of properties that indicate preferences for the run results in QTP.
10
Set ObjectName = CreateObject("Scripting.FileSystemObject")
To work with the Windows file system structure: files, folders, drives.
11
Set ObjectName = CreateObject("Mercury.DeviceReplay")
Perform mouse or key operations exactly as they occur on the mouse or keyboard drivers.
12
Set ObjectName = CreateObject("Mercury.ObjectRepositoryUtil")
Perform an operation on QTP Object Repository.
13
Set ObjectName=CreateObjcet("Scripting.Dictionary")
Creates a dictionary object
14
Set ObjectName=CreateObject("vbScript.RegExp")
Creates a regular expression object
15
Set ObjectName = CreateObject("Mercury.FileCompare")
To compare two files.
14
Set ObjectName = CreateObject("Mercury.Clipboard")
Perform clipboard functionality.
15
Set ObjectName = CreateObject("Msxml2.DOMDocument")
Creates a DOMDocument object to perform operations related to XML document.
16
Set ObjectName = DotNetFactory.CreateInstance (TypeName [,Assembly] [,args])
Returns a COM interface for a .NET object.
17
Set ObjectName = Createobject("shell.application")
To instantiate the Shell object, to program the Shell which can be used to access the file system, to launch programs, and to change system settings.
18
Set ObjectName= Createobject("TDApiOle80.TDConnection.1")
An object that enables to manage the Quality Center connection and retrieve the TDOTA object, which provides full interaction with Quality Center.
19
Set ObjectName = CreateObject("Microsoft.XMLDOM")
To access and manipulate XML documents via the XML DOM implementation, as exposed by the Microsoft XML Parser.
20
Set ObjectName = XMLUtil.CreateXML()
Creates and returns an object of type XMLData. If a root name is specified, a new document is created containing the specified root tag.
21
Set ObjectName = CreateObject( "AcroExch.App")
Acrobat OLE Automation Objects.
Set ObjectName = CreateObject( "AcroExch.AVDoc")
Set ObjectName = CreateObject( "AcroExch.PDDoc")
Set ObjectName = CreateObject( "AcroExch.HiliteList")
Set ObjectName = CreateObject( "AcroExch.PDBookmark")
Set ObjectName = CreateObject( "AcroExch.Rect")
22
Set ObjectName = CreateObject("ADODB.Connection")
Creates an instance of the ADO connection to connect to database.
23
Set ObjectName = CreateObject("ADODB.Recordset")
Creates an instance of the recordset object. To be able to read database data, the data must first be loaded into a recordset.
24
Set ObjectName =CreateObject("msscriptcontrol.scriptcontrol")
Perform operations to MS Windows Scripting Engine.
25
Set ObjectName = CreateObject("SAPI.SpVoice")
Auditory voice feedback during a test run, done by utilizing the Microsoft Speech API.
26
Set ObjectName = CreateObject( "UserAccounts.CommonDialog")
Object to provide users with a standard File Open dialog box
27
Set ObjectName = CreateObject("CDO.Message")
Windows CDO object is suitable for creating and sending automated emails.

Approach for Automating SAP Application

You can approach in the following method for SAP testing.

1. Transaction Testing: Testing a single transaction (e.g. VA01 Create Sales Order).
2. In-Stream Testing:  Testing of a flow within 1 single process. In-Stream Testing is testing chains of transactions that flow together and which reflect important business process and scenarios
3. Cross-Stream Testing: End-to-end testing of integrated processes through execution of predefined business flows.
4. Acceptance Testing: In-Stream or Cross-Stream Tests by the user community with the objective of formal acceptance. In some cases, and for practical reasons, the Acceptance Tests are combined with Cross- or even In-Stream Tests.

How to log in to SAP server using user ID & password.

You can use the SAPGuiutil object to open connections. All you need to do is to pass the server name taht you want to log into followed by userid and password. Please find the below code

Sapguiutil.OpenConnection “A:Test Server”
SAPGuiSession("Session").SAPGuiWindow("SAP").SAPGuiEdit("User").Set UserID
SAPGuiSession("Session").SAPGuiWindow("SAP").SAPGuiEdit("Password").SetSecure Password
SAPGuiSession("Session").SAPGuiWindow("SAP").SAPGuiButton("Enter").Click

Launching SAP Using UFT/QTP


Here is an utility object from QTP for SAP . It is “SAPGuiUtil”. SAPGuiUtil supports multiple methods. Below is the list of them with small description.

Autologon ::: Connects and logs on to an SAP Server
AutoLogonByIP ::: Connects and logs on to SAP server according to its IP address.
CloseConnections ::: Closes any SAP connections that were opened by QTP or by user.
 OpenConnection  ::: Opens a connection to the specified SAP server.
OpenConnectionByIP :::  Opens a connection to the specified SAP server according to its IP.

Let’s have a look at each one of them.

1. Autologon :  The AutoLogon method opens a new connection even if an open session already exists.

Syntax :

SAPGuiUtil.Autologon <ServerDescription>,<Client>,<User>,<Password>,<Language>

'The following example uses the AutoLogon method to connect to client "100" of the "ERPNext" SAP server, using the logon information for the MAster user. The Password argument is parameterized to take the encrypted value from the Data Table.

SAPGuiUtil.AutoLogon "ERPNext", 100, "MAster", DataTable("Password",dtLocalSheet),”EN”
2. AutoLogonByIP : Connects and logs on to an SAP server according to its IP address.

“SAPGuiUtil.AutoLogonByIP <ConnectionString>, <Client>, <User>, <Password>, <Language>, [SystemNumber], [RoutingServers]”

Below is the example

'The following example uses the AutoLogonByIP method to log on to the "ERPNext" SAP server
'using its IP address instead of its name.'The Password argument is parameterized to take the encrypted value from the Data Table.

SAPGuiUtil.AutoLogonByIP "/H/212.199.95.5/S/3200", "100", "QA01", DataTable("Password", dtGlobalSheet), "en", "00"

3. CloseConnections  : Closes any SAP connections that were opened by QuickTest or by the user.
                Syntax: SAPGuiUtil.CloseConnections

4. OpenConnection   : Opens a connection to the specified SAP server.

SAPGuiUtil.OpenConnection ServerDescription

Below is an example.

Sapguiutil.OpenConnection “A:Test Server”
SAPGuiSession("Session").SAPGuiWindow("SAP").SAPGuiEdit("User").Set strUserID
SAPGuiSession("Session").SAPGuiWindow("SAP").SAPGuiEdit("Password").SetSecure strPassword
SAPGuiSession("Session").SAPGuiWindow("SAP").SAPGuiButton("Enter").Click

5. OpenConnectionByIP : Opens a connection to the specified SAP server according to its IP address.

Syntax: object.OpenConnectionByIP ConnectionString, [SystemNumber], [RoutingServers]

Below is the example.

SAPGuiUtil.OpenConnectionByIP "10.168.11.57", 0

Sunday, 10 June 2018

What is ReplayType in UFT/QTP...?

ReplayType is QTP Web Add-in setting. It can be used to change how the events are replayed on the browser. There are two modes of ReplayType
  • Events (1) – Replay of events using the Browser methods (something similar to DOM).
  • Mouse (2) – Replay of events using the mouse and keyboard simulation.
When to change ReplayType?
Use of ReplayType can be best explained by a below example. In below sample textbox we need to type in any value and see that the button gets enabled when there some text in the textbox and disabled when there is not text. Click on the button will display the values inside the textbox.

importance:

For few of the objects, though the objects reference available and able to recognize in applications and perform script execution without any issues, it doesn't perform expected action in the application.

Example: There is button in the application Object is available in Object Repository and we are able to highlight it During script execution, it executes without any issue but on clicking button it is able to move to next screen(in fact it is not clicking on button).

In order to handle such issues, UFT has an option use ReplayType which will change the execution with mouse/keyboard control(this means similar to manually taking control with hand), Below line of the script can be used for this.

Setting.WebPackage("ReplayType") = 2
If you want to change it again then below line of script can be used.
Setting.WebPackage("ReplayType") = 1
Example:
Setting.WebPackage("ReplayType") = 2
Browser("google").Page("google").WebEdit("txtReplayType").Set "Knowledge"
Browser("google").Page("google").WebButton("Type and enable me").Click
Setting.WebPackage("ReplayType") = 1

Saturday, 9 June 2018

DOM Objects in UFT/QTP

The Document Object Model (DOM) is an application progamming interface (API) developed by the World Wide Web Consortium (W3C) to create and modify HTML pages and XML documents. The document object model can be used with any programming or scripting languages.


HTML DOM – A Standard object model for HTML documents

XML DOM – A Standard object model for XML documents
DOM is especially useful for indenidentifying:

Event Handlers
  • Parent Nodes
  • Previous and Next Elements
  • Ready State
  • Source Index
When we cannot use DOM?
  • Not for Browser Compatibility Testing
  • Not for FireEvents
  • Not for Edit Box, Combo Box Validation

HTML DOM Objects

A HTML document is made up of frames, Tables, Links, Buttons and Input Data fields.. etc. But  when it comes to DOM, every object is a node in a HTML document. The relations between the nodes are parent, children, previous sibling and next sibling.
A UFT for every web object there is a  property called “object”. Using this property the internal methods and properties can be accessed for any web object.
Syntax: WebObjectClass(“PropertyName:=PropertyValue”).Object
Creating document object for IE (Without UFT)
Set IE = CreateObject(“internetexplorer.application”)
IE.Visible = True
IE.Navigate = “http://google.co.in”
Set PageObject = IE.Document
Creating document object (With UFT)
Set docObj = Browser(“browser”).Page(“page”).Object.Document
Properties
  • activeElement Property – Retrieves the object that has the focus when the parent document has focus.
  • cookie Property – Sets or retrieves the string value of a cookie.
  • documentElement Property – Retrieves a reference to the root node of the document.
  • readyState Property – Retrieves a value that indicates the current state of the object.
  • URL Property – Sets or retrieves the URL for the current document.
  • URLUnencoded Property – Retrieves the URL for the document, stripped of any character encoding.
Collections
  • all – Returns a reference to the collection of elements contained by the object.
  • frames – Retrieves a collection of all window objects defined by the given document or defined by the document associated with the given window.
  • images – Retrieves a collection, in source order, of img objects in the document.
  • links – Retrieves a collection of all objects that specify the HREF property and all area objects in the document.
Methods
  • getElementById Method – Returns a reference to the first object with the specified value of the ID attribute.
  • getElementsByName Method – Retrieves a collection of objects based on the value of the NAME attribute.
  • getElementsByTagName Method – Retrieves a collection of objects based on the specified element name.

How to Use HTML DOM in UFT/QTP ..?

If we are testing a web application then we will know the limitations of UFT/QTP as far as identification of objects is concerned.

Many web objects have same properties. So QTP tries to identify the objects using Index - Ordinal Identifier.

The disadvantage of using index is that It makes the script weak. What I mean here is that If developer adds new objects of similar types, Index of the existing objects also change. So QTP fails to identify the object due to changed index.

So How we can use HTML DOM to handle such scenarios.

Using html DOM we extract all kind of information from page as we can access source code of the page in the form of HTML.

HTML DOM has many method and properties associated with it like getElementById, nextsibling etc.

To access these methods you must create the DOM object first.

Syntax to create a DOM object is - 

Set domObject = Browser("google").Page("google").object

Above statement will create the DOM object for the page called google.

Now we can access the methods of the DOM object

Now let us use the dom object we have created above to get more information of the page currently displayed in the application.

Print domObject.getElementById("myid").innerText         
' Prints the text inside the Element - myid

Print domObject.getElementById("myid").innerHTML     
' Prints the inner HTML of Element - myid

How to access the parent object of given DOM Object

We can also find the parentobject, nextsibling, previoussibling of the given dom object using built in properties as mentioned below.

Set parentObj = domObject.getElementById("myid").parentNode  ' gets the parent object of myid

Set nextsiblingObj = domObject.getElementById("myid").nextsibling 'gets the next sibling object of myid

Set previoussiblingObj = domObject.getElementById("myid").previoussibling


Ok ..Now we are able to create DOM object...What Next?

Once we have created the DOM Object, we can access the text associated with that object. After getting the text you can process that as per your testing requirement.

Print domObject.getElementById("myid").innerText         ' Prints the text inside the Element - myid
Print domObject.getElementById("myid").innerHTML     ' Prints the inner HTML of Element - myid

Some of the example of html dom in QTP are given below.

Accessing HTML element using DOM..?
Dim docObj, objIndex
Set docObj = Browser(“Sample Document”).Page((“Sample Document”).Object.getElementsByTagName(“a”)
msgbox domObj.length
for objIndex=0 to docObj .length-1
         msgbox domObj(objIndex).href

Next
How to get the collection of all TD (table data cells) elements of the table using HTML DOM in QTP/UFT?

Set tdtags =Browser(“abc”).Page(“mypage”).WebTable("mytable").Object.getElementsByTagName("TD")

How to get the collection of all TH (table header cells) elements of the table using HTML DOM in QTP/UFT?

set thtags = Browser(“abc”).Page(“mypage”).WebTable("mytable").Object.getElementsByTagName("TH")

How to get the value of attribute of any element using HTML DOM in QTP?

Set myobj = Browser(“abc”).Page(“mypage”).WebTable("mytable").Object
Print myobj.getAttribute("class") 'This will print the value of class attribute of myobj - table 

How to get the collection of all table rows using HTML DOM in QTP?

Set tableObj =Browser(“abc”).Page(“mypage”).WebTable("mytable").Object
Set trtags = tableObj.getElementsByTagName("tr")

How to find the total number of rows in table Using HTML DOM in QTP?
print trtags.length

How to get the value inside table cell Using HTML DOM in QTP?

Set tdtags =Browser(“abc”).Page(“mypage”).WebTable("mytable").Object.getElementsByTagName("TD")
Print tdtags(0).innerText 'print the text displayed inside first td tag in table