Highlighted
liorde Honored Contributor.
Honored Contributor.
3051 views

Regular expression in descriptive programming

Jump to solution

Hello colleagues.

Is there an option to use regular expressions while defining an object through code, in DP?

Example:

Set ObjDevice = Description.Create
ObjDevice("micclass").value     = "WebElement"
ObjDevice("class").value         = "upnp-progressbar" 
ObjDevice("html tag").value     = "SPAN"

The class value can be "nat-progressbar" or "dmz-progressbar" or some other progressbar objects...

How can I define 1 general descriptive-object, to refer to these elements that will appear in my web page?

 

Thank-you.

 

Tags (1)
0 Likes
1 Solution

Accepted Solutions
Tal Halperin Super Contributor.
Super Contributor.

Re: regular expressions may not be available descriptive programming

Jump to solution

Hi Lior.

Regular expression is supported via descriptive programming. See here for indication of it:

https://admhelp.microfocus.com/uft/en/14.02/UFT_Help/Content/User_Guide/Using_Reg_Exps.htm?Highlight=regular%20expression

And even the below post by Paul Grossman gives a very nice overview of it:

https://www.itcentralstation.com/product_reviews/micro-focus-uft-qtp-review-33678-by-paul-grossman

Quoting Paul:

"However advanced users can also build objects on the fly in code, either with Descriptive Programming or a Descriptive Object. All three approaches support CSS, xPath and Regular Expressions, so that you can reduce maintenance if portions of the object property value changes regularly. "

As for using CSS and xPath:

https://admhelp.microfocus.com/uft/en/14.02/UFT_Help/Content/Addins_Guide/Web_Obj_ID_types.htm?Highlight=css

https://admhelp.microfocus.com/uft/en/14.02/UFT_Help/Content/Addins_Guide/Web_Obj_ID_exercise.htm?Highlight=css

I hope this can help.

Good luck!

0 Likes
5 Replies
GoScriptless1 Honored Contributor.
Honored Contributor.

Re: Regular expression in descriptive programming

Jump to solution

Hi, 

I tried the below for peoplesoft and it worked fine. 

Set odesc = description.Create
odesc("class").value = "PS.*"

In your case your 

Set ObjDevice = Description.Create
ObjDevice("micclass").value     = "WebElement"
ObjDevice("class").value         = ".*progressbar" 
ObjDevice("html tag").value     = "SPAN"

Please try it with or without the tag and let us know. 

GoScriptLESS Create tests in seconds. www.scriptlessautomation.com

0 Likes
Dan-k Super Contributor.
Super Contributor.

regular expressions may not be available descriptive programming

Jump to solution

I have seen other posts that say regular expressions arent avaliable in code, possible alternatives:

Xpath alternative:

  • ObjDevice("xpath").value         = "//SPAN[contains(@class,'progressbar')" 

Object repository alternative: 

  • Create a WebElement object that has a Description property 
  • class (Regular expression)  = ".*-progressbar"
  • change the object descriptions at run time to suit your needs: {}.SetTOProperty("class", "upnp-progressbar")

 

0 Likes
liorde Honored Contributor.
Honored Contributor.

Re: regular expressions may not be available descriptive programming

Jump to solution

Thank-you for the replies friends.

Does UFT support the CSS Selector identification method, like in Selenium?

I know that xPath is supported , but I dont know until what extent.

I am not sure that regex is supported while coding an object in run time, will have to run some tests of this.

This is all new to me, so please if you have more examples of uasge with xPath and CSS Selector are very much welcome..!!

 

Thank-you.

0 Likes
Tal Halperin Super Contributor.
Super Contributor.

Re: regular expressions may not be available descriptive programming

Jump to solution

Hi Lior.

Regular expression is supported via descriptive programming. See here for indication of it:

https://admhelp.microfocus.com/uft/en/14.02/UFT_Help/Content/User_Guide/Using_Reg_Exps.htm?Highlight=regular%20expression

And even the below post by Paul Grossman gives a very nice overview of it:

https://www.itcentralstation.com/product_reviews/micro-focus-uft-qtp-review-33678-by-paul-grossman

Quoting Paul:

"However advanced users can also build objects on the fly in code, either with Descriptive Programming or a Descriptive Object. All three approaches support CSS, xPath and Regular Expressions, so that you can reduce maintenance if portions of the object property value changes regularly. "

As for using CSS and xPath:

https://admhelp.microfocus.com/uft/en/14.02/UFT_Help/Content/Addins_Guide/Web_Obj_ID_types.htm?Highlight=css

https://admhelp.microfocus.com/uft/en/14.02/UFT_Help/Content/Addins_Guide/Web_Obj_ID_exercise.htm?Highlight=css

I hope this can help.

Good luck!

0 Likes
liorde Honored Contributor.
Honored Contributor.

Re: regular expressions may not be available descriptive programming

Jump to solution

Thank-you TalHal for the informative reply.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.