Thursday 2 August 2007

QTP: Good Practices to manage Object Repositories in QTP (For web based projects)



Objects are the most difficult things to manage in any automation tool/framework.

Though QTP gives a good way of managing objects via Object Repository manager, Still a few tidy things could make your scripts more robust and effective, from OR's perspective.

1) Browser Objects :

If Title is same for all the pages in the browser, through out the application, only one browser objects should be used to have less overheads. By saying 'One Browser' object, I mean that all the browser objects in all the repositories should have the same name. This would help us more in writing and maintaining scripts, as you need not worry about n different names for the browsers at different places.

User 'Title' property as single identifier, this would help in managing conflicts well.

Get rid of the prperties (Remove from the description properties ) like

1) 'openurl', as this makes the object dependent on the URL and even a slightest of the change in URL would make the script break.

2) 'version' , 'application version': This will make the scripts independent of Browser type and Versions.






2) Page Objects




- Don't use URL property in the object description properties, wherever possible

- If all the pages in the application have same title use the 'title' property to identify the page in all the object repository. Make sure you keep the name same for the all the pages.

This would reduce the overhead of using different object name in the scripts and maintenance would be very easy.


People may disagree here, as keeping the name same for all the pages, does not help in terms of documentation or rather helping in identify which page are we referring to from different places?


My Answer is : In a good framework, people work on multiple well defined functions, so function reference is good enough to tell me who is doing what?


Also, it is a good practice to have small manageable repository (.tsr, .bdb) file in QTP for good performance and easy maintenance.




So, one can have a repository for each script (Functionality), which makes it obvious that even if I am using a single name for all the pages, it becomes quiet evident by looking at repository that which Repositor is pointing to which particular page/pages.


Another reason is, keeping a single name for browser and page would mean a single heirarchy, irrespective of number of Object Repositories.

So, even if ten repositories are shared in a script/Test, you don't have to worry about thousand different heirarchies.


However, the next question is, when you see all your objects from different OR's under one heirrachy, isn't it confusing, in terms of identifying the object?



Answer is YES it can be confusing, if objects are not named properly.



E.g? Button1 should be rather named as Button1_loginpage, this would help me compensating for not using different pages at the same time taking benefits of using single heirarchy.







How Does a Single Heirarchy helps in scripting?




Wednesday 1 August 2007

QTP Bob's Bit

1) How to report the complete test run Status?

- Reporter.RunStatus

Returns: 1 = Pass; 0 = Fail

2) How to call external files

ExecuteFile "Path"