Question: How can we increase performance of our scripts for a web application with deep paths (objects within the objects for an example webtable within several webtables)?
Description:We are using Descriptive programing in our project. From the performance point of view our scripts are very slow even if a single text box has to be populated with a specific text, it takes several minutes to perform the Action. It seems too many similar objects are the reason.
Question by: Sachin Ratra
Answer: Sachin, the issue was obviously because of several object of similar kind but it wasn’t the only issue, there was something very basic which was triggering the issue.
Step 1 Defining the Objects:
Most of us describe the objects like this only, either we don’t know what’s wrong with this or we never consider performance aspects of the code we write:
Every object created (using Description.Create method) in QTP has a RegularExpression Property, which specifies whether the value of a Property object in the Properties collection is a regular expression or not. And By default, value of all Property objects added to a Properties collection are treated as regular expressions.
So, it’s always advisable to set the RegularExpression property to false. Now the question is how would you do it in practical scenario, because it doesn’t seem practical to set RegularExpression property to false for every single definition.
If you will do it for every value you will land up with increasing several
Hence, to avoid this you have to do two things:
1. Identify what all objects are eating up most of the time while identification
2. Set RegularExpression property to false for these objects, using a custom Function/Procedure, you may write a function like the following one to set all defined TO properties
Above procedure can be called after define the object (only for those objects wherein identification take too long)
Step 2 Optimizing the staements:
There are two things which can be Optimize:
1. For access the object on the same path all the parent objects are Identified again example Browser class had been called twice and also been identified twice by QTP. Same has happened with Page class, to overcome this we can use With statement.
Now Browser and page class will be hit only once (at the beginning of With statement)
2. Also, in case of a Web Application it is advisable to keep the Root Class node (Browser) and the first child (Page) in QTP’s Object repository, as they are constant in most of the cases (even if not you may update the definition at run time but it’s for sure that you see a significant difference in terms of performance.
I hope this Article would have helped you up to your expectation.
Further, if you need more performance related tips you may refer to “Tweaks for better Performance” Article