Regular Expression
Regular Expression:
♦ Regular Expressions enable Quick Test to identify objects and text strings with varying values.Regular expressions are
used when the objects value is dynamically changed.
♦ A regular expression is a string that specifies a complex search phrase. By using special characters such as a period (.),
asterisk (*), caret (^), and brackets ([ ]), etc. you define the conditions of the search.
Steps to Specify Regular Expressions for an object in Object Repository:
1. Go to Object Repository. Navigation: Resources>>Object Repository.
2. Select the Object which you want to specify regular expression.
3. In the right side you can observe properties of that object.
4. Select the property which you want to specify regular expression.
5. Click on the property value of that property and the property value is editable. There is a configure button appeared with the
symbol ”<#>”
6. Click on the configure button or use Ctrl+F11 to open configure window.
7. Select Regular Expression check box.
a. If the property value is having any special characters then QTP will display a dialog with asking
Do you want to add the backslash (\) before each special character in order to treat it literally?
b. If you click on yes QTP will automatically gives the backslash before every special character. So that the special
characters will be treated as literal.
8. Now specify the regular expression in constant edit box.
9. Click on OK.
10. Observe that a symbol “A.*” is added in property field. This means, that property is using regular expression.
11. Highlight the object in application to ensure that the provided regular expression is working fine.
In Dynamic descriptive programming we create a descriptive object using description.create.
While specifying properties we can give regular expressions. By default the properties will be treated as regular expression when you added to description object.
♦ Regular Expressions enable Quick Test to identify objects and text strings with varying values.Regular expressions are
used when the objects value is dynamically changed.
♦ A regular expression is a string that specifies a complex search phrase. By using special characters such as a period (.),
asterisk (*), caret (^), and brackets ([ ]), etc. you define the conditions of the search.
Steps to Specify Regular Expressions for an object in Object Repository:
1. Go to Object Repository. Navigation: Resources>>Object Repository.
2. Select the Object which you want to specify regular expression.
3. In the right side you can observe properties of that object.
4. Select the property which you want to specify regular expression.
5. Click on the property value of that property and the property value is editable. There is a configure button appeared with the
symbol ”<#>”
6. Click on the configure button or use Ctrl+F11 to open configure window.
7. Select Regular Expression check box.
a. If the property value is having any special characters then QTP will display a dialog with asking
Do you want to add the backslash (\) before each special character in order to treat it literally?
b. If you click on yes QTP will automatically gives the backslash before every special character. So that the special
characters will be treated as literal.
8. Now specify the regular expression in constant edit box.
9. Click on OK.
10. Observe that a symbol “A.*” is added in property field. This means, that property is using regular expression.
11. Highlight the object in application to ensure that the provided regular expression is working fine.
In Dynamic descriptive programming we create a descriptive object using description.create.
While specifying properties we can give regular expressions. By default the properties will be treated as regular expression when you added to description object.
Set oDescription=Description.Create oDescription("micclass").value= "Browser" oDescription("openurl").value= "http://www.google.co.in"
Here in this URL property there are three dots (.) which can be treated as regular expressions. These dots will work as regular expressions because by default the property values will be treated as regular expressions.
There is a property called regularexpression for description object which is used to set the property values to work as regular expressions or as a literal string values.
In the Above example, set the regularexpression property to false to treat "http://www.google.co.in" as a literal string.
Set oDescription=Description.Create oDescription("micclass").value= "Browser" oDescription("openurl").value= "http://www.google.co.in" oDescription("openurl").regularexpression = False
oDescription("openurl").regularexpression = False
Note:
You can always use forward slash symbol (\) before every special character to treat a property value as literal character.
Use of Regular Expression in QTP
We can use regular expressions in QTP when
1. Defining Properties of an Object
2. Verifying data using check points
3. Parameterize an object property or check point
Note:
♦ You can use regular expressions only for values of type string.
♦ By default all properties which you pass from object property are strings / Constants.
♦ When using action parameters to parameterize a check point or an object repository, those action parameters data type
must be string type. If you specify any other data type, that will not be treated as regular expression.
♦ We can assign property values to variables in QTP when using descriptive programming. When assigning regular
expression to any variable make sure that regular expression is in string format.
♦ When any special character in a regular expression is preceded by a backslash (\), QuickTest searches for the literal
character.
♦ If your searching for a character “*” in a string, then you need to give the pattern as “\*”
Defining Properties for an Object using Regular Expressions
If you expect any change in the object property value at run session, Regular Expressions are useful to handle that dynamic change of the property value.
Example:
If you login to gmail.com, the browser title will be “Gmail – Inbox – MailID”
Gmail – Inbox – qtpworld@gmail.com
You can always use forward slash symbol (\) before every special character to treat a property value as literal character.
Use of Regular Expression in QTP
We can use regular expressions in QTP when
1. Defining Properties of an Object
2. Verifying data using check points
3. Parameterize an object property or check point
Note:
♦ You can use regular expressions only for values of type string.
♦ By default all properties which you pass from object property are strings / Constants.
♦ When using action parameters to parameterize a check point or an object repository, those action parameters data type
must be string type. If you specify any other data type, that will not be treated as regular expression.
♦ We can assign property values to variables in QTP when using descriptive programming. When assigning regular
expression to any variable make sure that regular expression is in string format.
♦ When any special character in a regular expression is preceded by a backslash (\), QuickTest searches for the literal
character.
♦ If your searching for a character “*” in a string, then you need to give the pattern as “\*”
Defining Properties for an Object using Regular Expressions
If you expect any change in the object property value at run session, Regular Expressions are useful to handle that dynamic change of the property value.
Example:
If you login to gmail.com, the browser title will be “Gmail – Inbox – MailID”
Gmail – Inbox – qtpworld@gmail.com
Here Inbox is the selected folder name in Gmail and MailID is login user mail id.
These two are not constants. If you select “sent mail” folder immediately the browser title will be changed. In this case you may get object identification problems if you’re using the name property for the browser object. To overcome this dynamic change in the application we need to use regular expression in object properties. For this you have to use Gmail - .* -.*@gmail\.com as a Regular Expression.
Like this if you expect any object property is dynamic you can use regular expressions as required.
Comments
Post a Comment