Monday, August 30, 2010

QTP -Performance increase in table lookup functions

Using object properties instead of QTP standard functions will improve the performance of QTP tests significantly. In our case, we often want to lookup the location of a certain value in a WebTable. QTP provides several functions to read out data from a table, but is slow when used iterating the table (like two for loops, one iterating the rows, the embedded second one iterating the columns per row).

Example of a conservative way to do this:

Public Function LocateTextInTable(byRef tbl, textToFind, byRef row, byRef col)

For row = 1 to tbl.RowCount
For col = 1 to tbl.ColCount
If tbl.GetCellData(row, col) = textToFind then
LocateTextInTable = True
Exit function
End if
Next
Next

row = -1 : col = -1
LocateTextInTable = False
End Function

The crux is this: .GetCellData is not a very fast method and with a table, consisting of 30 rows and 10 columns, this method is iterated up to 300 times in the most worse case scenario (= text not found).

A faster way to retrieve the data is through the Document Object Model (DOM). This allows you to use the more native properties of an object with the sacrifice of some ease of use.

A table consists of row elements and each row element contains one or more cells. We can iterate them just the same way as we did with the function above:

Public Function LocateTextInTableDOM(byRef tbl, textToFind, byRef row, byRef col)

Dim objRow, objCell

row = 1 : col = 1

For each objRow in tbl.object.Rows
For each objCol in objRow.Cells
If objCol.Value = textToFind then
LocateTextInTableDOM = True
Exit function
End if
col = col + 1
Next
row = row + 1
Next

row = -1 : col = -1
LocateTextInTableDOM = False
End Function

From our experience, this will increase the performance of the function with a factor 10.
But be aware, there is one big assumption: This function assumes that the row objects (and cell objects) are perfectly iterated from the first row to the last row and in this exact order. Although a For…Each construct cannot guarantee this behaviour, we never encountered an incorrect location.

Seven Personal Qualities Found In A Good Leader:

1. A good leader has an exemplary character. It is of utmost importance that a leader is trustworthy to lead others. A leader needs to be trusted and be known to live their life with honestly and integrity. A good leader “walks the talk” and in doing so earns the right to have responsibility for others. True authority is born from respect for the good character and trustworthiness of the person who leads.

2. A good leader is enthusiastic about their work or cause and also about their role as leader. People will respond more openly to a person of passion and dedication. Leaders need to be able to be a source of inspiration, and be a motivator towards the required action or cause. Although the responsibilities and roles of a leader may be different, the leader needs to be seen to be part of the team working towards the goal. This kind of leader will not be afraid to roll up their sleeves and get dirty.

3. A good leader is confident. In order to lead and set direction a leader needs to appear confident as a person and in the leadership role. Such a person inspires confidence in others and draws out the trust and best efforts of the team to complete the task well. A leader who conveys confidence towards the proposed objective inspires the best effort from team members.

4. A leader also needs to function in an orderly and purposeful manner in situations of uncertainty. People look to the leader during times of uncertainty and unfamiliarity and find reassurance and security when the leader portrays confidence and a positive demeanor.

5. Good leaders are tolerant of ambiguity and remain calm, composed and steadfast to the main purpose. Storms, emotions, and crises come and go and a good leader takes these as part of the journey and keeps a cool head.

6. A good leader as well as keeping the main goal in focus is able to think analytically. Not only does a good leader view a situation as a wh***, but is able to break it down into sub parts for closer inspection. Not only is the goal in view but a good leader can break it down into manageable steps and make progress towards it.

7. A good leader is committed to excellence. Second best does not lead to success. The good leader not only maintains high standards, but also is proactive in raising the bar in order to achieve excellence in all areas.

Seven Personal Qualities Found In A Good Leader:

1. A good leader has an exemplary character. It is of utmost importance that a leader is trustworthy to lead others. A leader needs to be trusted and be known to live their life with honestly and integrity. A good leader “walks the talk” and in doing so earns the right to have responsibility for others. True authority is born from respect for the good character and trustworthiness of the person who leads.

2. A good leader is enthusiastic about their work or cause and also about their role as leader. People will respond more openly to a person of passion and dedication. Leaders need to be able to be a source of inspiration, and be a motivator towards the required action or cause. Although the responsibilities and roles of a leader may be different, the leader needs to be seen to be part of the team working towards the goal. This kind of leader will not be afraid to roll up their sleeves and get dirty.

3. A good leader is confident. In order to lead and set direction a leader needs to appear confident as a person and in the leadership role. Such a person inspires confidence in others and draws out the trust and best efforts of the team to complete the task well. A leader who conveys confidence towards the proposed objective inspires the best effort from team members.

4. A leader also needs to function in an orderly and purposeful manner in situations of uncertainty. People look to the leader during times of uncertainty and unfamiliarity and find reassurance and security when the leader portrays confidence and a positive demeanor.

5. Good leaders are tolerant of ambiguity and remain calm, composed and steadfast to the main purpose. Storms, emotions, and crises come and go and a good leader takes these as part of the journey and keeps a cool head.

6. A good leader as well as keeping the main goal in focus is able to think analytically. Not only does a good leader view a situation as a wh***, but is able to break it down into sub parts for closer inspection. Not only is the goal in view but a good leader can break it down into manageable steps and make progress towards it.

7. A good leader is committed to excellence. Second best does not lead to success. The good leader not only maintains high standards, but also is proactive in raising the bar in order to achieve excellence in all areas.