How to Use Regular Expression in LeanFT | UFT Developer

In your day to day testing activity, you might have come across a few objects in the application under test whose properties are dynamic in nature and keep on changing every time. We can not use static object properties to identify such objects. The test script will fail in every iteration because it won’t be able to find the object with the required properties in the test application. Handling such objects are quite challenging. In such a situation regular expressions are quite instrumental. We can replace the hard-coded property using a regular expression to match the dynamic object properties. A regular expression is also known as regex or regexp represents a pattern that is used to match character combinations in strings. 

In this article, you will learn how to use regular expression in LeanFT now known as UFT Developer to identify objects with the dynamic property. Here I have shown an example of identifying a web element that displays the date in the find flight search result page of the Mercury Tour demo application. The text property of the date object is a dynamic property as it will change every day.

Regular Expression in LeanFT

Example of Using Regular Expression in LeanFT | UFT Developer

Code Explanation

In the above code innerText property of the Date, web element is being used to identify it, and rather than the hardcoded coded value of a date a regular expression pattern has been used that will match any valid date as per the date format being displayed in the web application.

Recommended Posts

Leave a Reply