Showing posts with label QTP Tutorial. Show all posts
Showing posts with label QTP Tutorial. Show all posts

Friday, 15 August 2014

Array Functions in QTP


1)Array() in QTP


-> The Array function returns a  variant containing an array.

-> The first element of array index is zero.



Syntax

Array(arglist)


Here,

arglist - Required. Its contains value seperated by comma. and values represented as array.


Example:


a=array(3,5,8)
msgbox a(1)


Here the values are,

a(0)=3
a(1)=5
a(2)=8




2) Filter() in QTP

-> Filter function used to create another array variable from another array variable by using some filter creteria.


Syntex:

Filter(Source_arrayvariable,value[,include[,compare]])


Here,


Source_arrayvariable = Required. one dimensional array. This is source string

value = Required. Used for search string in Source_arrayvariable. Its case- sensitive.

include = Optional, Boolean value
 True = Default. Return String as per matched with above given value.
 False = Return string that is not matched as per above given value.
Compare = Optional. Specifies the string comparison to use.
0 = vbBinaryCompare - Perform a binary comparison
1 = vbTextCompare - Perform a textual comparison



Return Values:

Return new array with values from Source_arrayvariable as per the filter creteria.



Example:


a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=filter(A,"Sun",true)
For each str  In b
print str
Next



O/P
Sunday




3) IsArray() function in QTP

-> IsArray() returns boolean value and its indicates that given variable is array variable or normal variable.

->  If the variable is an array, it returns True, otherwise, it returns False.


Syntex :

IsArray(variable)

Variable : Required. Any variable


Return type:

True : If the variable is an array
False : If the variable is NOT an array,


Example:

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
print msgbox(IsArray(A))


O/P

TRUE



4) Join() funtion in QTP

The Join() function used to join all elements from array.


Syntex:

Join(Array_Variable[,delimiter])

Here,

Array_Variable = Required. one dimensional array variable name.
delimiter = optional, used to add delemiter char with end of all element(Sub String) in given array variable.


Return Types:

Its return String which contains all number of element (substrings) in an array.


Example :

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
print join(a,"#")

o/p

Sunday#Monday#Tuesday#Wednesday#Thursday#Friday#Saturday



5) Split Function in QTP


Split function used to zero based, one dimensional array that contains specified number of sub string.


Syntax:

Split(expression[,delimiter[,count[,compare]]])

Here,


6) LBound Function in QTP

Returns the smallest subscript for the indicated dimension of an array

LBound(arrayname[,dimension])





7) UBound Function in QTP

Returns the largest subscript for the indicated dimension of an array


UBound(arrayname[,dimension])

String Function in QTP



1) Instr function in QTP

Instr returns first occurance of the string1 with in another string2.

Syntex:

Instr([start,] String1,String2, [compare])

Here,

Start   = optional, Postion of the start search from String1
String1 = Required, This is main String.
String2 = Required, This is sub String to be search in String2
Compare = Optional, Specifies the string comparison to use. Default is 0

 Can have one of the following values:

 0 = vbBinaryCompare - Perform a binary comparison
     1 = vbTextCompare - Perform a textual comparison



Return Values :

0      -> If String1 is ""
0       ->  If String2 is not found
0           -> if start > len(String1)
Null       -> If String1 is Null
Null       -> If String2 is Null
Start val   -> If Strin2 is ""
position val-> If string2 is found within string1



Example :

Instr(1,"The QTP Tutorial","T")

o/p 1


2) InStrRev function in QTP

InstrRev returns first occurance of the String1 with in another string. The search begin starts from end of the string. But position returned counts from the beginning of the string.


Syntex:

InStrRev(String1,String2[,start],[compare])

Here,

String1 = Required, This is main String.
String2 = Required, This is sub String to be search in String2
Start   = Optional. Specifies the starting position for each search. The search begins at the last character position by default (-1)
Compare = Optional. Specifies the string comparison to use. Default is 0

 Can have one of the following values:

 0 = vbBinaryCompare - Perform a binary comparison
     1 = vbTextCompare - Perform a textual comparison



Return Values :

0      -> If String1 is ""
0       ->  If String2 is not found
0           -> if start > len(String1)
Null       -> If String1 is Null
Null       -> If String2 is Null
Start val   -> If Strin2 is ""
position val-> If string2 is found within string1


Example :

Instr(1,"The QTP Tutorial","a")

o/p 11



3) Lcase function in QTP

Converts specified string to lower case.

Syntex:

Lcase(String)

Here,

String = Required, string to be change lower case.



4) Ucase function in QTP

Converts specified string to upper case.

Syntex:

Ucase(String)

Here,

String = Required, string to be change upper case.







5) Left function in qtp

Left function used to returns number of characters from left side of the string.

Syntex:

Left(string1,length)

Here,

String1 = Required, Main string used to returns character from.
lenght  = Required, Specifies how many characters to return from left side of the string.


Return values

if length = 0      -> Returns Empty String ""
if length >= len(String) -> Returns full String
if lenght < len(string)    -> Returns number of character from left side


Example :

left("This is QTP tutorial",11)

o/p "This is QTP"





6) Right function in qtp

Right function used to returns number of characters from right side of the string.

Syntex:

Right(string1,length)

Here,

String1 = Required, Main string used to returns character from.
length  = Required, Specifies how many characters to return from right side of the string.


Return values

if length = 0      -> Returns Empty String ""
if length >= len(String) -> Returns full String
if lenght < len(string)    -> Returns number of character from right side


Example :

left("This is QTP tutorial",11)

o/p "TP tutorial"




7) Len Function in QTP

Len function used to returns the number of characters from given string.

Syntex:

Len(String)

Here,

String = Required

Example:

len("qtp")

o/p 3



8) Ltrim function in QTP

Ltrim Function used to remove spaces from left side.

Syntex:

Ltrim(String)

Here,

String = Required

Example:

len("qtp  ")

o/p qtp


9) Ltrim function in QTP

Rtrim Function used to remove spaces from right side.

Syntex:

Rtrim(String)

Here,

String = Required

Example:

len("  qtp")

o/p qtp



10) Trim function in QTP

Trim Function used to remove spaces from both side.

Syntex:

Ltrim(String)

Here,

String = Required

Example:

len("  qtp  ")

o/p qtp   



11) Mid function in QTP

Mid function returns number of characters from given string

Syntax

Mid(string,start[,length])

Here,

String = Required, The string which char can be returned
Start  = Required, Specifies the starting position.
lenght = optional, the number of characters to be returned.

Return values,

If start > len(String) = Return empty string ("")

Ex:

mid("This is QTP Tutorial",1,4)

o/p  This




12) Replace function in QTP

Replace the specified number of string with in one another.

Syntex:

Replace(String,Find,ReplaceWith[,Start[,Count[,compare)

Here,

String      = Required. Main String used to replace
Find    = Required, THis is String which is find in the main String for replacement
ReplaceWith = Required, Substring which is going to replace in main string.
Start       = Optional, From which postion from main string going to search and replace. Default is 1. All characters before the start position will be removed.
count       = Optional, number of replacement in Main String. Default value is -1, which means make all possible substitutions
compare       = Optional, Specifies the string comparison to use. Default is 0

 Can have one of the following values:
 0 = vbBinaryCompare - Perform a binary comparison
        1 = vbTextCompare - Perform a textual comparison   



Example :

Replace("This is a beautiful day!","i","##",2,2)

o/p  "h##s ##s a beautiful day!"




13) Space function in QTP

The Space function returns a string that consists of a specified number of spaces.


Syntax

Space(number)


Here,

number    = Required. The number of spaces you want in the string


Example

space(3)

o/p "   "



14) Strcomp function in QTP

The Strcomp function used to comapare the two string and return the values as per the result of comparison.

Syntax:

StrComp(string1,string2[,compare])

String1 = Required.
String2 = Required.
compare = Optional, Specifies the string comparison to use. Default is 0

 Can have one of the following values:
 0 = vbBinaryCompare - Perform a binary comparison
        1 = vbTextCompare - Perform a textual comparison


Return values,

-1    = if string1 < string2
0    = if string1 = string2
1    = if string1 > string2
Null    = if string1 or string2 is Null





15) String function in QTP

The String function returns the string with contains given number of continuous character.

Syntex:

String(Number,character)


Here,

number     = Required. The length of the returned string
character = Required. The character that will be repeated


Return values,

if character = "more than one letter"  -> It consists first letter of that string.

Example:

String(4,H)   ->  O/P  HHHH
String(4,"

How to use FOR EACH loop in QTP



-> FOR EACH loop used to execute every single element or item in a group.

-> Normally its used to like

1) Every single element in an Array
2) Every single files in a folder
3) Every character in a String

in these type of situation we can use FOR EACH loop.

Syntex

For Each [Item] In [Group]
   [loopBody]
Next [Item]


Example :

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")

For each str In a
print str
Next

output :

Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday



From above example, we print the every element in array.


Tuesday, 8 July 2014

How to Exit from loop in QTP



Exits a block of Do...Loop, For...Next, Function, or Sub code.

Syntax for VBScript Exit Statement

Exit Do
Exit For
Exit Function
Exit Sub


The above  Exit statements used for exit from respective block of the statement.

Sub RandomLoop
   Dim I, MyNum
   Do   ' Set up infinite loop.
      For I = 1 To 1000   ' Loop 1000 times.
         MyNum = Int(Rnd * 100)   ' Generate random numbers.
         Select Case MyNum   ' Evaluate random number.
            Case 17: MsgBox "Case 17"
               Exit For   ' If 17, exit For...Next.
            Case 29: MsgBox "Case 29"
               Exit Do   ' If 29, exit Do...Loop.
            Case 54: MsgBox "Case 54"
               Exit Sub   ' If 54, exit Sub procedure.
            End Select
      Next
   Loop
End Sub

Tuesday, 20 May 2014

How to connect SQL server using QTP script


1) We should know the below details before establish database connection with SQL server.


Provider = SQLOLEDB.1  (Default for all SQL server connection)
Server   = Server_Name
uid = User_ID
Password = Password for login into SQL server.
Database = Name of the database


2) QTP dont have the built-in function for access SQl server. So we can use access the data in SQL server by using ADODB connection. SO we should create object for ADODB connection and Recordset,

Set objcon=CreateObject("ADODB.Connection")
Set objrs=CreateObject("ADODB.RecordSet")

3) Establish database connection by using connection string

Syntex : 

objcon.open "Provider= Provider name (SQLOLEDB.1);Server=server_Name;uid=User_ID;Password=User_Password;Database=Database_Name;"

Example:

objcon.open "Provider=SQLOLEDB.1;Server=SQLServerName;uid=arunrajvdm;Password=arunrajvdm;Database=arunrajvdmdatabase;"

Here,

Provider = SQLOLEDB.1  (Default for all SQL server connection)
Server   = SQLServerName
uid = arunrajvdm
Password = arunrajvdm
Database = arunrajvdmdatabase


4) Execute Query

Syntex:

objrs.open "SQL_Statements",object of ADODB connection(objcon)

Example:

objrs.open "Select * from Emp",objcon


5) Access the data from database by using column_Name

we can use Fields property of Recordset object.

Syntex :

objrs.Fields("Column_Name")

Example

objrs.Fields("First_Name")



Sample Script:

Extracting the data from SQL Server database and update into the Excel


Set xl=CreateObject("Excel.Application")
Set xlwb=xl.Workbooks.Open("E:\SQLConnection.xls")
Set xlws=xlwb.Worksheets("TestData")

Set objcon=CreateObject("ADODB.Connection")
Set objrs=CreateObject("ADODB.RecordSet")

objcon.open "Provider=SQLOLEDB.1;Server=SQLServerName;uid=arunrajvdm;Password=arunrajvdm;Database=arunrajvdmdatabase;"
objrs.open "Select * from Emp",objcon

i=1
While not objrs.EOF
 xlws.Cells(i,1)= objrs.Fields("Emp_Name")
 objrs.MoveNext
 i=i+1
Wend


objrs.Close
Set objrs=nothing
objcon.Close
Set objcon =nothing

xlwb.Save
xl.Quit

Set xlws=nothing
Set xlwb=nothing
Set xl=nothing

Tuesday, 13 May 2014

Capture Bitmap Method in QTP



Saves the Screen capture of the object and saved with file ectension .png or .bmp depending upon the specified file extension.

Its used for store the screen capture of the test objects in QTP.


Syntax:

object.CaptureBitmap filename [override existing]

Object -> test object
Capturebitmap -> methode name
file name -> specified the full path file name with in quotes for wher we can stored the image file.
Override Existing -> True or False
        True -> the file override, if the file name already exists
        false -> defaulty QTP set as false, its not override.
Return Value : NONE

Ex:

Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebButton("Sign in").CaptureBitmap "E:\signin.bmp",True




Store screen shot hyperlink in excel using CaptureBitmap Method


Example Script:

Browser("Browser").Page("Order Summary").CaptureBitmap TestPath&"\Screenshots\"&"Number Of Access = "&NoOfAccess&".bmp",true
Linklocation =  TestPath&"\Screenshots\"&"Number Of Access = "&NoOfAccess&".bmp"
WS.Cells(i,12).value="=HYPERLINK("&""""&Linklocation&""""&","&""""&"Number Of Access = "&NoOfAccess&""""&")"


Here,

Testpath = Computer location used for save the screen shot


The above script used to capture the screen shot and saved into the perticular location. And stored as hyperlink in Excel.



Browser("Browser").Page("Order Summary").CaptureBitmap TestPath&"\Screenshots\"&Testcase&".bmp",true
Linklocation =  TestPath&"\Screenshots\"&Testcase&".bmp"
WS.Cells(i,12).value="=HYPERLINK("&""""&Linklocation&""""&","&""""&Testcase&""""&")"

Thursday, 8 May 2014

QTP Menu list is Empty after click Menu bar

Solution :

Right Click from near menu bar -> Customize -> Toolbars -> Restore all -> Restart QTP

From above step we can solve this problem.


QTP unable to find object in IE due to BHOManager CLASS add-on missing


This "BHOManager CLASS" add-on is a supporting add-on to run QTP script on the IE browser.

The publisher of this add-on is Mercury Interactive Corp.

I have uninstalled the existing IE browser because of some issues in my machine and reinstalled it. And after this i cannot run the QTP script as the "BHOmanager Class" add-on is missing.



http://stackoverflow.com/questions/13586606/how-to-install-the-bhomanager-class-add-on-in-ie


http://h30499.www3.hp.com/t5/Unified-Functional-Testing/HP-QTP-11-cant-recognise-IE8-browser-events-refresh-and-navigate/td-p/5317811#.U1YUTfmSyQ5




regsvr32 -u "C:\Windows\SysWOW64\BHOManager.dll
regsvr32 "C:\Windows\SysWOW64\BHOManager.dll




QTP is not recognise the object in Windows7 and IE8(64 bit)

1) Check the  BHOManager Add on in IE 8

Go to IE > Tools > Manage Add-ons, make sure BHOManager class
(Browser Helper Object) from Mercury Interative Corporation is
enabled.

Enabled BHOManager add on alone. And diabled rest of the Add on.

2) Please check if the iexplorer.exe of the AUT (Application Under Test) is 32 or 64 bit based, for it you can open the task manager, select the application nameà right click à go to process à and if the is an *32 next to the iexplorer.exe then the application is 32 bit based, otherwise is 64 bit.

Depending of it please use the following command thru the CMD to re-register the BHOmanager.dll, please close all browsers:

For the 32 bit:
                              regsvr32 -u "C:\Windows\System32\BHOManager.dll"
                              regsvr32 "C:\Windows\System32\BHOManager.dll"
For the 64 bit:


                              regsvr32 -u "C:\Windows\SysWOW64\BHOManager.dll"
                              regsvr32 "C:\Windows\SysWOW64\BHOManager.dll"



3) Check IE8 version is 32 bit or 64 bit, by using below method,

Method 1:

From Help-> About INternet Explorer ->  first line gives the version number. If it is 64 bit, it will say so. If 32 bit, it shows the version number only.Its doesnot show like 32 bit.


If your win7 is not have 64 bit IE8 means, you are using IE 32 bit versions alone.


If you are using a 64 bit Win7, both are listed in
Start -> All Programs.
Internet Explorer (64-bit)
Internet Explorer


Method 2:

We can check the IE location from Right click of the Properties from IE icon.


The 32 bit IE is located here:

C:\Program Files (x86)\Internet Explorer\iexplore.exe

The 64 bit IE is located here:

C:\Program Files\Internet Explorer\iexplore.exe


From above step, we get confirm IE is 32 bit or 64 bit edition.Then find the location for HP instalation path to know about which IE have the BHOmanager Add on

-> If QTP innstalled in below path

C:\Program Files (x86)\HP\QuickTest Professional

we come to conclusion IE with 32 bit have the BHOmanager Add on.


-> If QTP innstalled in below path

C:\Program Files\HP\QuickTest Professional

we come to conclusion IE with 64 bit have the BHOmanager Add on.

Tuesday, 8 April 2014

Generate Random Number in QTP

RandomNumber.Value(upperlimit,lowerlimit)

It would generate random numbers for that instance of QTP. But once QTP is restarted it will generate same numbers in same sequence. Example is shown in the images below.

Ex:

N=RandomNumber.value(1,15)

Its randomly pick the value from 1 to 15 and assign to N. Its randomly pick the any value for everytime QTP starts.

Wednesday, 19 March 2014

How to check and uncheck the perticular check box using QTP script



1) script for check the perticular check box

Browser("OLM Training").Page("Cart").WebCheckBox("WebCheckbox12").Set "ON"


2) script for un check the perticular check box

Browser("OLM Training").Page("Cart").WebCheckBox("WebCheckbox12").Set "OFF"


3) select the perticulat item from check box.


For i=1 to rc
  Table_linkText=Browser("projectCentre QTP:TEST-AT:").Page("projectCentre QTP:TEST-AT:").Frame("RegRegRegFrame").WebTable("...").GetCellData(i,3)
If (Expected_Link=Table_linkText) then
  Browser("projectCentre QTP:TEST-AT:").Page("projectCentre QTP:TEST-AT:").Frame("RegRegRegFrame").WebTable("...").ChildItem(i,1,"WebCheckBox",0).Set "ON"

How to select perticular item from Web list using QTP script


Ex: Web list contains below items.

Facebook
Yahoo
Twitter
Email



1) select item from web list using item index. Item index starts from 0.

Browser("OLM Training").Page("Cart_2").WebList("WebListBox").Select "#2"

o/p  Twitter


2) Select item from web list by using item name directly.


Browser("OLM Training").Page("Cart_2").WebList("WebListBox").Select "Email"

o/p  Email

How to select the second Radio button from Group of Web Radio button using QTP script


Method 1:

Find the "Value" property of the second radio option from web Radio Button Group using Object Spy. Then using below script we can select the perticular radio option from web radio button

Ex: "Value" property of second radio button = "Two"

Browser("All types of radio buttons").Page("All types of radio buttons").WebRadioGroup("MYRADIO").Select "Two"

Method 2:

 we can find the value property and select the second radio button option using below QTP script


CurrentValue = Browser("All types of radio buttons").Page("All types of radio buttons").WebRadioGroup("MYRADIO").GetTOProperty("value")

If CurrentValue <> "Two" Then
Browser("All types of radio buttons").Page("All types of radio buttons").WebRadioGroup("MYRADIO").Select "Two"
End If

QTP Virtual Object



We create the objects virtually in the QTP. Its enable the objects and run the test which is not regonized by QTP.

Its mark the boundary value of the object and saved it as a collection object. That means Objects are stored in object repository, so the virtual objects are stored in collection.

we cannot create virtual object using OR. we can use virtual object manager.


How to create the Virtual object

1) Tools-> Virtual Objects -> New Virtual object.
2) Click "Next"
3) select standared class for mapping the virtual object into the any standared class.
4) Mark the X and Y co-ordinates for virtual object by using "Mark object" button. Then click Next.
5) Select Entire parent hierarchy for save full hierarchy information.
6) Rename the Virtual object name as we want   
7) Rename the collection name as we want
8) click "Finish".


The above virtual object Saved below location in System :

C:\Program Files (x86)\HP\QuickTest Professional\dat\VoTemplate\VoCollection0.vot


how to add virtual object into the object repository

1) copy the VoCollection0.vot file from the location (C:\Program Files (x86)\HP\QuickTest Professional\dat\VoTemplate\VoCollection0.vot).
2) and save with the extention as .tsr file for adding the virtual object in OR. (Ex: VoCollection0.tsr)
3) Then save it. now the  VoCollection0.tsr have the virtual object which was created.



Limitations:


1) QTP doesnot support the virtual object in analog and low-level recording.
2) During the run session, make sure that the application window is same size in the same location as it was in recording. otherwise the co-ordinating of the virtual object relative to the parent may be different and script may get failed.
3) we can use the virtual objects only when recording and running the  test.
4) we cannot use the object spy to view the property of the virtual object.

ADO - Activex Data Object


ADO is a Microsoft technology, and stands for ActiveX Data Objects

ADO can be used to access databases from your ASP web pages.



What is ADO?

    ADO is a Microsoft technology
    ADO stands for ActiveX Data Objects
    ADO is a Microsoft Active-X component
    ADO is automatically installed with Microsoft IIS
    ADO is a programming interface to access data in a database


*********************************************

The common way to access a database from inside an ASP page is to:

    Create an ADO connection to a database
    Open the database connection
    Create an ADO recordset
    Open the recordset
    Extract the data you need from the recordset
    Close the recordset
    Close the connection


********************************************


ADO Database Connection

1) Create a DSN-less Database Connection

The easiest way to connect to a database is to use a DSN-less connection. A DSN-less connection can be used against any Microsoft Access database on your web site.

2) If you have a database called "northwind.mdb" located in a web directory like "c:/webdata/", you can connect to the database with the following ASP code:

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
%>

Note, from the example above, that you have to specify the Microsoft Access database driver (Provider) and the physical path to the database on your computer.


********************************************************


ADO Recordset

To be able to read database data, the data must first be loaded into a recordset.
Create an ADO Table Recordset

After an ADO Database Connection has been created, as demonstrated in the previous chapter, it is possible to create an ADO Recordset. 

Suppose we have a database named "Northwind", we can get access to the "Customers" table inside the database with the following lines:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"

set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Customers", conn
%>



*******************************************************************


objCS.Open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source ="&varPath&"\Reports.xls;Extended Properties =""Excel 8.0;HDR = YES;"";"



Provider = Microsoft.Jet.OLEDB.4.0; - Connect the database using DSN-less connection. It can be used any microsoft Access database.

Data Source ="&varPath&"\Reports.xls; = This is the path of Excel(Database)

Extended Properties =""Excel 8.0;HDR = YES;"";

1) HDR - yes mean The first column in excel treated as Column name. Not data . if HDR - No mean The first column in excel treated as data.

2) specify Excel 8.0 for XLS and Excel 12.0 for XLSX files, which means you would need to build connection string dynamically. You also need to specify correct extension for you files - if it is xlsx than you should put it instead of xlsx.

The connection string for XLSX files would be something like

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=myFile.xlsx;Extended Properties=""Excel 12.0 Xml;IMEX=1;HDR=YES;""

and for XLS files

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=myFile.xls;Extended Properties=""Excel 8.0;IMEX=1;HDR=YES;""


    
**********************************************************************

Recordset.Open Source, ActiveConnection, CursorType, LockType, Options


 CursorType

    Optional. A CursorTypeEnum value that determines the type of cursor that the provider should use when opening the Recordset. The default value is adOpenForwardOnly.
LockType

    Optional. A LockTypeEnum value that determines what type of locking (concurrency) the provider should use when opening the Recordset. The default value is adLockReadOnly.
Options

    Optional. A Long value that indicates how the provider should evaluate the Source argument if it represents something other than a Command object, or that the Recordset should be restored from a file where it was previously saved. Can be one or more CommandTypeEnum or ExecuteOptionEnum values, which can be combined with a bitwise OR operator.

Sunday, 23 February 2014

QTP Runtime Error

1) subscript out of range   - max array val specified, not specified value in drop down for object

2) Object required


3) Variable is undefined  - if we not defined the variable


4) Object doesnot support this property or method

 worksheetobj.cells(2,2).font.interiorcolor=vbred

Here The object does not support the interiorcolor property.

The Correct format is : worksheetobj.cells(3,3).interior.color=vbred


5) unknown run time error


6) That commant cannot be used on multiple selections

worksheetobj.range("F2,H3").select  -  we shouldnot give more than cells address here.

The correct format is - worksheetobj.range("F2").select
we should give only one address as above



7) select method of range class failed

worksheetobj.range("F2").select


8)wrong number of arguments or invalid property assignment

-> a= Browser("Traceability matrix -").Page("Traceability matrix -").WebTable("Requirement Identifiers").getcelldata

missed the row and column number in above details.correct format is

a= Browser("Traceability matrix -").Page("Traceability matrix -").WebTable("Requirement Identifiers").RowCount(row,col)

Saturday, 22 February 2014

Difference between RO-Properties and TO-Properties And Optional Step in QTP


What is optional step in QTP and how to use it?


    *  An optional step is a step that is not necessarily required to successfully complete a run session.
    * During a run session, if the object of an optional step does not exist in the application QTP  bypasses this step and continues to run the test
    * To set a step as optional in keyword view right click on the step and select Optional Step
    * Alternatively, you can directly write the keyword "OptionalStep" preceding a statement to make it optional


Ex: OptionalStep.Browser( ).Page( ).Dialog("Warning").WinButton("OK").Click



What is the difference between RO-Properties and TO-Properties in QTP?


The difference between RO-Properties and TO-Properties are that TO properties refer to the properties as they exist in the Test Object saved in the test (i.e. in the object repository or as described in descriptive programming) and the RO-Properties refer to the RunTime object (i.e. the object as it appears in the Application Under Test (AUT)).

From this distinction a few things arise

   1. Accessing a TO property doesn't require the AUT to be open
   2. Accessing an RO property requires the AUT to be open and the object to be uniquely described
   3. You can set the value of a TO property but not that of an RO property

Change the QTP settings by using AOM script

Browser Navigation Timeout:

1) This setting makes QTP wait for the web page to load completely for the specified amount of time.

2)By default the maximum wait time specified by QTP is 60 seconds.

3) This setting can further be modified bythe user based on his requirement. This setting is found in File>settings>Web>Browser navigation timeout.

4) This setting is applicable only for web applications.

Ex: App.test.settings.web.BrowserNavigationTimeout



Object synchronization timeout:

1) This setting makes QTP wait for the specified amount of time for the objects to appear.

2) By default the time setting is 20 seconds which can be modified by the user.

3) these settings can be found in File>Setting>Run>Object synchronization timeout.

Ex: App.test.settings.run.objectssynctimeout



TimeToActivateWinAfterPoint Property

The number of milliseconds after which to activate a window when pointing to it.

Ex : App.Options.TimeToActivateWinAfterPoint = 600


AddToPageLoadTime Property

App.Options.Web.AddToPageLoadTime = 30

The number of seconds to add to the page load time that is specified in each page checkpoint.

Friday, 14 February 2014

Working with MS Outlook application using QTP script

Let us now create a sample script in QTP that would access the Outlook Object Model and use it to open Outlook and display the Inbox folder.

In the Outlook Object Model, ‘Application’ Object is the topmost or parent Object that represents the entire Outlook Application. So we’ll first create an instance of Outlook.Application object like below.

Set objOutlook = CreateObject("Outlook.Application")

*******************************************************************************

GetNameSpace() Method :

-> Returns a NameSpace object of the specified type.
-> The Namespace object is multiple objects. The object itself provides methods for logging in and out, accessing storage objects directly by ID, accessing certain special default folders directly, and accessing data sources owned by other users.


Syntax : ApplicationObject.GetNameSpace(Type)


Type  is  Required String. The type of name space to return.


Example :

ApplicationObject.GetNameSpace ("MAPI") -  To return the Outlook NameSpace object from the Application object.


The only data source supported is MAPI, which allows access to all Outlook data stored in the user's mail stores.GetNamespace method used to bind to the MAPI namespace.


*******************************************************************************


MAPIFolder object


The MAPIFolder object represents a folder that contains email messages, tasks, contacts and various other items. MS Outlook provides a total of 16 default MAPIFolder objects.

 Example : olFolderInbox represents the Inbox folder. Similarly olFolderOutbox, olFolderSentMail, olFolderDeletedItems represent Outbox, Sent Mail & Deleted Items folders respectively.

MAPIFolder provides 16 default objects using which you can access different Outlook folders such as e-mail messages, tasks, contact items etc.

***********************************************************************************

16 Defult outlook folder type

Name
Value
Description
olFolderCalendar 9 The Calendar folder.
olFolderConflicts 19 The Conflicts folder (subfolder of Sync Issues folder). Only available for an Exchange account.
olFolderContacts 10 The Contacts folder.
olFolderDeletedItems 3 The Deleted Items folder.
olFolderDrafts 16 The Drafts folder.
olFolderInbox 6 The Inbox folder.
olFolderJournal 11 The Journal folder.
olFolderJunk 23 The Junk E-Mail folder.
olFolderLocalFailures 21 The Local Failures folder (subfolder of Sync Issues folder). Only available for an Exchange account.
olFolderManagedEmail 29 The top-level folder in the Managed Folders group. For more information on Managed Folders, see Help in Microsoft Outlook. Only available for an Exchange account.
olFolderNotes 12 The Notes folder.
olFolderOutbox 4 The Outbox folder.
olFolderSentMail 5 The Sent Mail folder.
olFolderServerFailures 22 The Server Failures folder (subfolder of Sync Issues folder). Only available for an Exchange account.
olFolderSyncIssues 20 The Sync Issues folder. Only available for an Exchange account.
olFolderTasks 13 The Tasks folder.
olFolderToDo 28 The To Do folder.
olPublicFoldersAllPublicFolders 18 The All Public Folders folder in the Exchange Public Folders store. Only available for an Exchange account.
olFolderRssFeeds 25 The RSS Feeds folder.



***********************************************************************************

GetDefaultFolder Method

Returns a MAPIFolder object that represents the default folder of the requested type for the current profile.

Syntax :

object.GetDefaultFolder(Request folder number)



***********************************************************************************



How to read first top most Mail item from outlook using QTP script


Dim InboxFolder=6    // Default index for inbox folder is 6.

Set ObjOUtlook = CreateObject("Outlook.Application")      // Create object for outlook application
Set objNamespace = objOutlook.GetNamespace("MAPI")       // Name Space Returns the Application object. "MAPI" is the only supported name space type.


Set oInbox = objNamespace.GetDefaultFolder(InboxFolder)        // Create default index object for inbox folder.

Set oAllMails = oInbox.Items                 //Find all Mail items in the Inbox Folder

'Find out properties of the mail item
sSubject = sSubject & "To -> " & oAllMails(1).To & vbCrLf
sSubject = sSubject & "CC -> " & oAllMails(1).CC & vbCrLf
sSubject = sSubject & "BCC -> " & oAllMails(1).BCC & vbCrLf
sSubject = sSubject & "Subject -> " & oAllMails(1).Subject & vbCrLf
sSubject = sSubject & "Body -> " & oAllMails(1).Body & vbCrLf
sSubject = sSubject & "Creation Time -> " & oAllMails(1).CreationTime & vbCrLf
sSubject = sSubject & "Is Marked Important -> " & oAllMails(1).Importance & vbCrLf
sSubject = sSubject & "Received at -> " & oAllMails(1).ReceivedTime & vbCrLf

'Display the result
msgbox sSubject


***********************************************************************************

Display total number of folders and name of each folder inside Inbox Folder from OUtlook using QTP script


Dim InboxFolder=6
Set ObjOUtlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI") 
Set oInbox = objNamespace.GetDefaultFolder(InboxFolder)

Set oAllFolders = oInbox.Count                    // Find how many folders inside inbox.

sFolderNames = "Total Folders = " & iCount & vbcrlf & vbcrlf    // Get the name of folders


For i = 1 to iCount
    sFolderNames = sFolderNames & "Folder " & i & " -> " & oAllFolders(i).Name & vbcrlf
Next

msgbox sFolderNames                          //Display folder count and folder names in msgbox


**********************************************************************************

Find out the list of all unread emails in Outlook Inbox


Dim InboxFolder=6
Set ObjOUtlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI") 
Set oInbox = objNamespace.GetDefaultFolder(InboxFolder)
Set oAllMails = oInbox.Items 


iTotalMails = oAllMails.Count        // Count the total NUmber of Read and Unread Mail in inbox folder.           

For i=1 to iTotalMails
  'Check if the mail is UnRead or not
  If oAllMails(i).UnRead = True Then
     sSubject = sSubject & oAllMails(i).Subject & vbCrLf
  End If
Next

msgbox sSubject

*******************************************************************************

Refer this link for more property of Mail Item -> http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.mailitem_properties.aspx
 

Sunday, 5 January 2014

what is the usage of integrate qtp with quality center?


HP ALM 11 or Quality Center is used as a test management tool in which we can store tests, function Libraries, test data, object repository, recovery scenario and much more.


HP ALM (HP Application Lifecycle Management) formerly known as Quality Center is a Test Management tool to manage entire Quality Assurance and testing process for an organization. Before being called HP Quality center it used to be Mercury Test Director.



How can we create a QTP Test in Quality Center?

In Quality Center, we create QTP tests in the Test Plan module. When you create a QTP
test, we apply a template test to it. We can choose either the default template test stored
on our QTP client, or a template test that is saved in our Quality Center project.

If we do not have any template tests saved in our Quality Center project, or if we choose in
the Template box, Quality Center uses the settings defined in the template test that was
installed with the QTP Add-in for Quality Center on our Quality Center client.

How to start ALM  -> http://www.softwaretestinghelp.com/learn-hp-quality-center-qc-in-4-days/

How to integrate QTP 11 with Quality Center/ALM -> http://qaautomationqtp.blogspot.in/2013/07/how-to-integrate-qtp-11-with-quality.html


What happens in case Smart Identification fails to identify the object in QTP?

What happens in case Smart Identification fails to identify the object in
QTP?

If the Smart Identification mechanism cannot successfully identify the object, QTP uses the
learned description plus the ordinal identifier to identify the object.

If the object is still not identified, the test fails and a normal failed step is displayed in the
results.



QTP object repository

QTP object repository used to store objects which QTP learns. Object repository stores logical name, property of the object and property value of the object.