Wednesday 2 May 2012

Regular Expressions in QTP

Regular expressions enable QTP to identify objects and text strings with varying values. You can use regular expressions only for values of type string.

It can be used when:

  • Defining the property values of an object in dialog boxes or in programmatic descriptions.
  • Parameterizing a step.
  • Creating checkpoints with varying values.
We can define a regular expression for a constant value, a Data Table parameter value, an Environment parameter value, or a property value in Descriptive programming. 

We can define a regular expression in standard checkpoint to verify the property values of an object; we can set the expected value of an object's property as a regular expression so that an object with a varying value can be verified.

We can define the text string as a regular expression, when creating a text checkpoint to check that a varying text string is displayed on our application, For XML checkpoints we can set attribute or element values as regular expressions. 

In QTP, when working with Regular Expressions and varying object descriptions can be handled by using Descriptive Programming.

E.G:  Let assume in my Gmail Account I have one unread mail into my Inbox(2) and once I read one mail now it is Inbox(1). In this scenario we will use Regular Expression as shown in script.

'DP for Inbox(2)

cm_d("text").value = "Inbox.*"     ‘.* is used as Regular Expression

If Link(cm_d).Exist(2) Then
    Link(cm_d).Click
            else
            msgbox "Link not present"
End If

By Mann Bhammar
     Test Analyst

3 comments: