Wednesday 22 January 2014

Regular Expressions in QTP


Regular Expressions in QTP
Sometimes there might be situations where values of objects keep on varying and QTP may fail to recognize them or checkpoints might get failed as the expected and actual data are not matching. In such cases Regular expressions come into picture. It enables QTP to identify objects and text strings with varying values.Regular expressions can be used:

1. In identifying the property values of an object

2. In parametrization

3. For creation of checkpoints on objects with varying values

1. In identifying property values of an object:

In this concept, let’s see how to handle QTP when a value of an object is varied. Let’s walk through this section with a small example:

Assume that you have to record a scenario of verifying the mails in a mail account. Open the mail with valid username and password. Now click on Inbox. When you have opened your mail account assume that there are 5 mails. So the inbox would be showing Inbox (5). When you click on that, the mails get displayed. Following would be the statement that gets generated when clicked on Inbox:

Browser(“Gmail”).Page(“Gmail”).Link(“Inbox(5)”).click

Now when the same script is run again, QTP fails at the same step as the number of mails in the inbox is 4. Or even more if some new mails have come. The script execution doesn’t get passed unless the total number of new mails is again 5. We make use of regular expression here as the value for the number of mails keeps varying.

For creating a regular expression, go to object repository from ResourcesàObject repository. Select the link object Inbox (5) from object list displayed in the left side.

Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUyR4S8fIebPZVlPPkyNDoCLYTvIB_UzJvdZeaWiPyuIWGAtL8eI3OHLN0g-kljkbSgOW3zr0AnqORV6PP-s5o-JBz_38dE7grmbq-2S19pEr1ULnWZ-jTFly3YuXH9-tKTXNT8IhJLiF5/s400/RE_1.JPG

Go to the object properties screen displayed in the right side of the screen. Select the property that has the value Inbox (5). Click on the configure icon that gets displayed there.

Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdmJhB3V755FiU6mPaNYiTNlPDquuhyphenhyphenzu7sK3izIiGqzQj9MSAYyMY3CWUK76YsHNp7WpSSRqFODnkIbWhNU68-sAFAzb8b3OY4NUBF7Nes-zXgHrPfT3lfLMRBYjWpbLh2kOnM-QCXD9v/s400/RE_2.JPG


‘Value configuration Options’ dialog box gets displayed.


Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihThyphenhyphenGsyBELN2A9W3hcZxzF_bIyf95QbD9cc8-IVSuevG8QxyJvYZBTrY-MnqkBt9_zifPOLP7wq0Z-Qewujsy4n3LDyeBbyR_Q3OTwDhXuskLF5kdelFGtqGmo8eImxTZogvwVNpIg5MM/s400/RE_3.JPG

Check the Regular expressions check box. A dialog box gets raised asking the user whether to add a back slash before each special character in order to treat it literally. As we have special characters ‘(‘ and ‘)’ we need to click on Yes and QTP adds a slash character before both the Parenthesis characters.

If you want qtp script to be successful for 0-9 mails then give the following value in Constant edit box:

Inbox\([0-9]\)

For 0-99 mails

Inbox\([0-9][0-9]\)

For 0-999 mails

Inbox\([0-9][0-9][0-9]\)

Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL9LOQLThdWpbctbn3p0mz_8WBZg2d0CitGrm_Xv1AfyW6O4oAaKtOhmtIY5ZmJT1pkCI1DJLLqbgUaZiAgObi45D2T91xH2pgEYtce35tX8uTx4W_TER9i5LlozFdA-RTP8iDGU2A5rP7/s400/RE_4.JPG

Click on OK and close the object repository window. For first option QTP executes the scripts successfully if the Inbox has 0-9 mails. Second option executes successfully for 0-99 mails and third option for 0-999 mails.

2. In Parameterization:
In some cases, we need to parameterize the varying values in the script. In such cases we parameterize the values and use the regular expression in parameterized value i.e., in data table sheet where the value is present. Using the same example mentioned above lets discuss how can be regular expressions in parameterization process.

Select the link object Inbox (5) from object list displayed in the left side of Object repository.

Go to the object properties screen displayed in the right side of the screen. Select the property that has the value Inbox (5). Click on the configure icon that gets displayed there.

‘Value configuration Options’ dialog box gets displayed. Set the Parameter Radio button and select the location of data table (global/local). Enter a title for the column.Now check the Regular expressions checkbox in advanced configurations option. Click on Yes in the dialog box that gets displayed.


Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrFxLz6SeNwTaAo79VdYw1ZQW09k2P0snnrVdw9-xPonWDA2RoGSi_EEk_j003Y9kD1OKIA0k72v3mcpjEWeKroh1YicebkanEm92lxPDodrlbbbs-Z0rwUTCi1IY2yrG-8lg50DTj8vmo/s400/RE_5.JPG

Click on OK and close the object repository window. If you want QTP script to be successful for 0-9 mails then give the following value in Data table sheet of QTP:

Inbox\([0-9]\)

For 0-99 mails

Inbox\([0-9][0-9]\)

For 0-999 mails

Inbox\([0-9][0-9][0-9]\)

Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_5uEoesAKgWAF2A9ZN3wzzzfc51Rbjyr436yYT2QGMwChQfbpgrpKQ-doyH2xus8B-qMM5eh8MBRiGFZBX41dldN8D_T1rlX7VBpKG-4QBGdh0rgJ6o2pbIa1_NeeWY3MU4VJn9M31jDO/s400/RE_6.JPG
For first option QTP executes the scripts successfully if the Inbox has 0-9 mails. Second option executes successfully for 0-99 mails and third option for 0-999 mails. Using this example, the values can be changed directly in the data table sheet.

3. For creation of checkpoints on objects with varying values

Assume that you have to create a text check point on some text which gets varied continuously. In the same example mentioned above, you need to insert a text checkpoint on Inbox (5) which gets varied basing on the number of mails available in the inbox. When the checkpoint is created, it takes Inbox (5) as the expected value and when the same script is run again when there are 4 mails in the inbox, and then the checkpoint fails. To overcome such situations, regular expressions is used again.

Insert a checkpoint by selecting Insert-->Checkpoint-->Text Checkpoint. (Make sure that QTP is in recording mode)

Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXXCiXdIC3CtOKR2_NBfH_h_mnU_ixJk4xmz5N1ZKj0L2o79rYyABYUF30BiZ2tciFA5R55cXJgZsoKpgeT3FNg7-ZZ58BFXLIrRK9MAE96vBn3zeji_TTLoMrzZnVCmHb4fpg-mmPskMM/s400/RE_7.JPG

Select the text on which you want to insert text checkpoint (i.e., Inbox (5)). Text checkpoint properties window gets opened.Make sure that the radio button is set to constant dialog box. Click on Constant Value options icon that gets displayed there.

Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1YdWoAMltTr9TUD46WV6BWv7GAGkcakO1urov5v5v_VIxKbLr0PsWVfN8gI19Ht14jqfVCDgFpvd8z9FIO6XO_tpBD6IBhutVXvVVXpHO_MvAP9ivBlvUjs7XWxsmXCPKcc90uFXCzh00/s400/RE_8.JPG
‘Constant Value options’ dialog box gets displayed. Now check the regular expressions check box and Click on yes in the dialog box that gets displayed to treat ‘(‘ and ‘)’ as literal characters. Now in the same way as mentioned in the above two examples enter the data as per your requirement.


Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmnlVvIpXQ-23uWlfmLJ_Rblc4fXreEfZMdc0AlMyBL1I_QMto6oJezJbCpqL1F6bvq4D1Z-Y9JmJGO_ng_IIGLGn8O_3XHWD4PUuoXlyQOlKukZacnGEfmBqW3DLqe1MACluUgDvkviR7/s400/RE_9.JPGFor 0-9 mails

Inbox\([0-9]\)

For 0-99 mails

Inbox\([0-9][0-9]\)

For 0-999 mails

Inbox\([0-9][0-9][0-9]\)

Click on OK and close the Text checkpoint properties window. For first option QTP checkpoint gets passed if the Inbox has 0-9 mails. Second option gets passed for 0-99 mails and third option for 0-999 mails.

11 comments:

  1. Great, thanks for the informative article.
    It was very helpful for interviews..
    Will definitely share it as a reference.

    Selenium training in Chennai | Best Selenium training institute in Chennai

    ReplyDelete
  2. Great Post. I was searching for such a information. Thanks for bailing me out.
    Devops Training in Chennai | Devops Training Institute in Chennai

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Nice post I have been searching for a useful post like this on salesforce course details, it is highly helpful for me and I have a great experience with this, Salesforce Training Australia  

    ReplyDelete
  5. I really appreciate this amazing post which you have provided for us. I assure that it will be beneficial for most people.Excellent information with unique content and it is very useful to know about the information based on blogs.

    Data Science Training In Chennai

    Data Science Online Training In Chennai

    Data Science Training In Bangalore

    Data Science Training In Hyderabad

    Data Science Training In Coimbatore

    Data Science Training

    Data Science Online Training

    ReplyDelete
  6. I just recently discovered your blog and have now scrolled through the entire thing several times. I am very impressed and inspired by your skill and creativity, and your "style" is very much in line with mine. I hope you keep blogging and sharing your design idea


    oracle training in chennai

    oracle training in velachery

    oracle dba training in chennai

    oracle dba training in velachery

    ccna training in chennai

    ccna training in velachery

    seo training in chennai

    seo training in velachery



    ReplyDelete
  7. Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up.
    data analytics training in hyderabad

    ReplyDelete