Monday, 21 May 2012

Different Ways To Get And Count Objects In QTP

Getting and counting the number of objects on a web page is important factor as part of Automation testing. This article explains the different ways available to get and count the objects.

Descriptive Programming:
This approach uses Description Object, which contains a mask for objects we would to get.
Code Snippet:
 Set oDesc = Description.Create
 Set Links = Browser("aaa").Page("bbb").Page("ccc").ChildObjects(oDesc)
 MsgBox "Total Links" &Links.count

The method ChildObjects returns the collection of child objects matched the description ("micclass" is "Link") and containted within the object Page("ccc").

Object QTP property Collections:
As we know that QTP can work with Document Object Model(DOM).
Code Snippet:
 Set Links = Browser("aaa").Page("bbb").Page("ccc").Objects.Links
 MsgBox "Links Count" & Links.Length
 We used Object property of a page object which represents the HTML Document in a given browser. The HTML document contains different collections like forms, frames, images, linls. etc. We used Length property to get the number of items in the collection.

Object QTP Property & GetElementByTagName:
We can get access to the HTML Document by using Object property of the page and use its GetElementByTagName method to get the number of links on the page.
Code Snippet:
Set Links = Browser("aaa").Page("bbb").Object.GetElementByTagName("a")
MsgBox "Total Links" & Links.Length
We can use the above methods for finding the images,webedits, list of objects on a web page.

Capturing Tool Tip Of A Link In QTP

As we know that the Tool tip or infotip or a hint is a common graphical user interface element. It's used in conjunction with a cursor,usually a pointer.The user hovers the pointer over an item without clicking it, and a tooltip may appear - a small "hover box" with information about the item being hovered over.

Capturing Toop Tip(TT) in QTP is not a difficult task. We need to follow some steps to achieve this.

01. Place the mouse cursor over the link
02. Wait for tool tip
03. Get Text of the shown tool tip

Use the following code snippet to capture the text of a tool tip.

'Place the mouse cursor over the link
Browser("aaa").Page("bbb").WebElement("text:=Link Name").FireEven "onmouseover"
Wait 3
'Grab the tool tip

Please read the following steps which explains the details about the above code snippet.

01.We use FireEvent("onmouseover") to simulate mouse placing over the link.
02.Function Wait waits for 3 seconds for a tool tip.
03.To get tool tip we used the "("nativeclass:=tooltips_class32").GetROProperty("text")"

We can compare the captured tool tip with the expected if required. I hope this article is helpful in capturing the Tool tip of any link

Monday, 14 May 2012

VBScript Syntax Rules And Guidelines

Case Sensitive:
VBScript is not case sensitive.It means that it doesn't differentiate between upper case and lower case spelling of words, variables, objects and methods names or constants.

For example, Browser("aaa").Page("bbb").WebList("today").Select "131"
Browser("aaa").Page("bbb").WebList("Today").Select "131"will be treated in same way by QTP.

Text Strings:
When a value is entered as a text string, we should add quotation mark before and after the string.But we need to remember that the numbers also should be surrounded by quoatation marks, beacuse it's a text string that represent a number not a numeric value when the number is entered into a text box.

One more should be considered that the variables should not be surrounded by quotation marks.

For example: Browser("aaa").Page("bbb").WaitProperty("variable name", variable,20000)

We can use the variable to store strings,integers,arrays and objects.Using variables is very helpful to make the scripts more readable and flexible.

To achieve the desired result and to avoid errors,it's important that we use parenthesis() correctly in our statements.

We can indent or out-dent our script to reflect the logical structure of the nesting of the statements.

We can add the comments before writing a line or at the end of the statement.We have to use apostrophe(') to represent the comments.It's recommended to add the comments wherever possible, to make our scripts easier to understand and maintain.

We can add spaces in our script to improve clarity. These spaces are ignored by VBScript.

Thursday, 10 May 2012

QTP Driver Script

Actually we are using VBScript in most of the areas in QTP. But the Driver Script is the only QTP script, remaino all are VBscript files(.VBS).

Driver script is mainly useful to organize the Tests Exection and stores Test Logs in the specified file/folder.


adding sheets to runtime data table
datatable.AddSheet ("Module")
datatable.AddSheet ("Testcase")
datatable.AddSheet ("Teststep")

'Adding data sheets to runtime data table

Tcrowcount=datatable.GetSheet ("Testcase").getrowcount
        For j=1 to Tcrowcount step 1
           datatable.SetCurrentRow (j)
           If moduleid=moduleid1 and Ucase(tcexe)="Y" Then
               For k= 1 to Tsrowcount step 1
                   If TcId= TcId1 Then
                       keyword= datatable.Value(3,"Teststep")
                       Select Case keyword
                       Case "ln"
                       Case "ca"
                       Case "op"
                        End Select
                    End If
            End If
    End If
datatable.ExportSheet "D:\Automation\Testlog\results.xls","Teststep"

Sample Initialization Script:

Initialization Script launches QTP Tool and Calls Driver Script, Driver Script execute Tests and Stores Results.
Finally   Initialization Script Closes QTP tool

Option Explicit
Dim qtApp
set qtApp=createobject("QuickTest.Application")
qtApp.Open "D:\Automation\Testscripts\Driver"

Wednesday, 9 May 2012

Input And Output Operations in QTP

Am going to explain some of the input and output functions used in Test Automation script which will be useful in debugging the script as well as giving the input dynamically at run time.

InputBox Function:
This function is used to give the user input at run time.The behavior will be,
01.Displays a prompt will be displayed in a dialog box.
02.Waits for the user input text/click.
03.Returns the content of the text box.

Dim input
input=InputBox("Enter your name:")
MsgBox("You Entered:" & input)

MsgBox Function:
This function is mainly useful when debugging the script.The behavior will be,
01.Displays a message in dialog box.
02.Waits for the user to click a button
03.Returns a value indicating which button the user clicked.

Dim output
output =MsgBox("Hello World!",70,"MsgBox Example!")
Output variable contains either 1 or 2 depending on which button is clicked.

Tuesday, 8 May 2012

Dynamic Handling Of Object Repositories in QTP

This article gives the details about the dynamic handling of Object Repositories.Dynamic Handling of Object Respositories represents the Finding the path of the object repository,Loading the Object Repository and Removing the Object repository during run time.

Dynamic Handling is very helpful to improve the QTP performance.To do this, QTP is providing an object called "RepositoriesCollection".

Loading Object Repository:
Use the following code snippet to load a specific Object Repository.

RepositoriesCollection.Add "Path of the repository file"

Finding Object repository:
Use the following code snippet to find a specific object repository.

RepositoriesCollection.Find("Path of the Object repository")

Removing Object Repositories:
Use the following code snippet to remove the Object Repository during run time.


We can remove all the loaded Object Repositories by using the following code snippet.


SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").WinEdit("Agent Name:").Set "softwaretestingcommunity"
Dialog("Login").WinEdit("Password:").SetSecure "mercury"

Monday, 7 May 2012

Database Connections In QTP

Database connection is a facility in computer service which allows the client software to interact with Database irrespective of the Database location. It means that we can access the database from any of the system.

I am going to give the code snippets which will be useful when writing database connection scripts.

SQL Server Connection Strings:
Standard Security:
"Driver="SQLServer",Server= Your_Server_Name;Database=Your_DB_Name;Uid=Your_User_Name;Pwd=Your_Password;"
Trusted Connection:
SQL OLE DB Strings:
Standard Security:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog=Your_Data_Base_Name;Uid=Your_user_name;Pwd=Your_Password;'
Trusted Connection:
"Provider=SQLOLEDB;Data Sourcer=Your_Server_Name;Initial Catalog=Your_Database_Name;Integrated Security=SSPI;"
SQL SqlConnection .NET strings:
Standard Security:
"Data Source=Your_Server_Name;Initial Catalog= Your_Database_Name;UserId=Your_Username;Password=Your_Password;" < br>2. "Server=Your_Server_Name;Database=Your_Database_Name;UserID=Your_Username;Password=Your_Password;Trusted_Connection=False"Trusted connection:
1."Data Source=Your_Server_Name;InitialCatalog=Your_Database_Name;Integrated Security=SSPI;"

MS Access connection strings:
MS Access ODBC connection strings
Standard Security:
"Driver= {MicrosoftAccessDriver(*.mdb)};DBQ=C:\App1\Your_Database_Name.mdb;Uid=Your_Username;Pwd=Your_Password;"
"Driver={Microsoft Access Driver (*.mdb)}; Dbq=C:\App1\Your_Database_Name.mdb; SystemDB=C:\App1\Your_Database_Name.mdw;"
Exclusive "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\App1\Your_Database_Name.mdb; Exclusive=1; Uid=Your_Username; Pwd=Your_Password;"
MS Access OLE DB & OleDbConnection (.NET framework) connection strings
Open connection to Access database:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; User Id=admin; Password="
Open connection to Access database using Workgroup (System database):
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; Jet OLEDB:System Database=c:\App1\Your_System_Database_Name.mdw"
Open connection to password protected Access database:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; Jet OLEDB:Database Password=Your_Password"
Open connection to Access database located on a network share:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\Server_Name\Share_Name\Share_Path\Your_Database_Name.mdb"
Open connection to Access database located on a remote server:
"Provider=MS Remote; Remote Server=http://Your-Remote-Server-IP; Remote Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb"

MySQL connection strings
MySQL ODBC connection strings
Open connection to local MySQL database using MySQL ODBC 3.51 Driver
"Provider=MSDASQL; DRIVER={MySQL ODBC 3.51Driver}; SERVER= localhost; DATABASE=Your_MySQL_Database; UID= Your_Username; PASSWORD=Your_Password; OPTION=3"
MySQL OLE DB & OleDbConnection (.NET framework) connection strings
Open connection to MySQL database:
"Provider=MySQLProv;Data Source=Your_MySQL_Database;User Id=Your_Username; Password=Your_Password;"

Oracle connection strings:
Oracle ODBC connection strings:
Open connection to Oracle database using ODBC
"Driver= {Microsoft ODBCforOracle};;Uid=Your_Username;Pwd=Your_Password;"
Oracle OLE DB & OleDbConnection (.NET framework) connection strings
Open connection to Oracle database with standard security:
"Provider=MSDAORA;Data Source= Your_Oracle_Database;UserId=Your_Username;Password=Your_Password;"
 "Provider= OraOLEDB.Oracle;Your_Oracle_Database;UserId=Your_Username;Password=Your_Password;"

Open trusted connection to Oracle database
"Provider= OraOLEDB.Oracle;DataSource=Your_Oracle_Database;OSAuthent=1;"

Back To Top