QTP: TableHandler class

I cracked, I really did. I was even packing my stuff to just give up.

One too many dynamically generated tables to deal with in QTP did to me. What's worse, the columns in the table change, too. Basically I started on a page with a set of links. When you click any of the links, the same landing page pops up. However, the data shown in the the table changes, as does the table colums number, type, and description. There are 12 different versions, and each is dynamically generated every time.

I originally wrote some code to manage the query string for me (since the URL is identical with the exception of one NVP in the querystring), and this works very well (I have quasi-extended the Browser object in QTP so I can now always get a NVP value out of a querystring via a method). However, this would still require me to write some serious logic handling code in the action to deal with the table.

What to do and how to deal with the frustration? Sometimes, frustration breeds solution....thank the gods.

I have written the TableHandler class. You pass it a table object and a number indicating the row that contains the header info. It will manage the table, providing a FieldNames property for your action (so you can know how to interact with the table), and methods to iterate through the table similar to the way you would a Recordset. The user simply interates the table with a MoveNext, MovePrevious, or Move...using a BOT/EOT property to know when the beginning end is reached. You can pass a string (from the FieldNames property) into the FieldValues method to get the value out. Internally, the class manages a pointer to the correct row. When you move, it controls the pointer and loads the data for that row into an internal dictionary that is called via the FieldValue method.

Now, iterating any dynamically generated table in my app is simple and fast. It also standardizes how anyone else will do it, making the team (just me right now) more consistent.

I am going to refactor the code soon, though, to type check the parameter passed as the row for the header. That will enable me to send a table schema along rather than use a number. This will be useful when there is no header or the header isn't easy to use.

Pretty slick, if i do say so myself. :-)
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Print | posted on Wednesday, May 14, 2008 9:41 AM
Comments have been closed on this topic.