I worked with various users who appreciate Dynamic Find feature a lot but often have doubts about correct usage, best practices etc. This is an attempt to capture some of the best practices to follow when using dynamic find APIs. You need to remember the four important factors that can help you to get best out of dynamic find feature. These factors are :
1) Object Selection
- Object selection
- Search type
- Property selection
- Memory cleanup
: Here you need to find the right set of objects to search on. Let's call the selected objects as landmarks, which is what we use when we have to move from one place to another in real world.
Landmarks: These are the objects that helps in reaching the destination. The approach should be similar to how we follow in our real life. Let's say you have to drive from place A to place B, than what's the first thing you do. Do you look for directions in map? Yes, we note down the landmarks on the way to place B and follow these to ensure that we are moving in right direction. Can you describe how will you travel between two places if you have no way to find out landmarks or road details, but what you have is many roads leaving start destination ? Leaving it as an exercise ;-)
Remember : Do not select a landmark that is temporary in nature.2) Search Type
: Second important decision to make is how do you want to search on the selected object. There are various ways you can perform search on a landmark, like you can search in all possible routes, you can search in adjacent cities etc. Following the similar real time search approach RFT provides you with three types of search :
: Search in all descendants
: Search only the first level children
: Good to request complex search in a single command and offers better performance.
Use appropriate criteria to get correct results in quick time.
In RFT the object's hierarchy is like directions on how to move from Top level object to the object you are looking for. If you give proper landmarks definitely you'll reach quickly, else you need to explore all options before reaching the right location. Let's understand whatever we discussed above with an exampleGoal : find "ObjectA" in a UI which has the following hierarchy
Object1(may not remain in future)
Object2(dynamic property values)
In this case the fastest way to reach to ObjectA would be
step1 : find TopObject atChild of RootTestObject
step2 : find Object2 atdescendant of step1's result ( use Regularexpression for dynamic properties)
step3 : find Object3 atChild of step2's result
step4 : find ObjectA atchild of step3's result
3) Property selection : We have found the object on which we want to make a search, we have also figured out the scope of search within the object children hierarchy, now is the time to decide what parameters we like to pass to our search type. Let's go back to our travel scenario. Our problem statement was to go from place to place B.
In first step we found out that Building ABC, Restaurant XYZ and Stadium PQR are the right landmarks.
In second step we decided that since Building ABC is adjacent to place A so we'll use atChild search type, whereas Restaurant XYZ is not adjacent to Building ABC so we'll use atDescendant etc.
In third step: We decide the properties that can uniquely identify the landmarks selected in first step. For example: Building ABC can have name, type, size etc as properties that can help in identify the building.
Now coming back to RFT world of dealing with GUI objects, some of the important properties that you must use to get quick results are :
# .class - All domains
# id - html domain
# .dojoclass - Dojo GUI Objects
# .processname - win, .net etc.
4) Memory cleanup : Last but equally important thing to remember while using objects returned by find is to free the objects as soon as the work is done or whenever you feel that the object might have changed in the AUT as part of some intermediate transaction. Find API returns a bound testobject to you and understands that you know how to use it and till what time the object is valid and thus expects that you'll do the clean up of the resources used by this object. RFT provides unregister API that needs to be called on the Bound Testobject. For more details I recommend to refer RFT help documentation. This is a very important point and can significantly hit performance of long running testcases, in case testobjects are not released in time.
That's all from my side and I hope this will help you in understanding the most famous feature of Rational Functional Tester.