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