Google Search Results
You arrived here after searching for the following phrases:
Click a phrase to jump to the first occurrence, or return to the search results.
ChangeLog:
5/10 : I’ve uploaded a new file with the fixed parser. Added support for code blocks with sensitive names (Function PrivateFunciton, Sub SpecialGet etc.)
10/10 : I’ve uploaded a new file with constructor arguments support, and a new regular expression engine (preserves comments and should make things go faster).
Notice that the new file requires a new run command (use NewRegExParser.dll instead of ClassParser.Dll).
To use constructor arguments:
1. In your Class_Initialize sub, add parameters with a comment. For example: Sub Class_Initialize ‘(Param1, Param2)
2. When you create a new instance of your class, use comments to deliver values to these parameters. For example Set x = new MyClass’(5, “Something”)
You can pass parameters and variables. However, these will always be passed as ByVal.
The problem
One of QTP’s biggest downsides is its VBScript engine. While it may answer most of your everyday needs, it falls short when it comes to classes and object-oriented programming.
On the top of my personal VBScript missing features list is the ability to perform class inheritance, which could save tons of duplicate code, and significantly reduce maintenance overheads. Here’s a quick example for class inheritance. Imagine this is a basic “engine” template:
Class AbstractEngine
'This will include general methods, variable and properties
Private pEngine 'Each engine will hold its object here
Private pFileName 'The location for the output
Public Property Get File
File = pFileName 'This is the same for all engines
End Property
Public Sub StartEngine
'Each engine should implement this on its own
End Sub
Public Sub Report(sEventName)
'This is the same for all engines
pEngine.Report sEventName
End Sub
End Class
We would like to write specific engines that would implement this more general class template. In every other language, we could’ve inherited the AbstractEngine, and immediately reuse its code without having to rewrite it specifically in our own “derived” class. This would allow us to maintain the “base” code in only one place – the abstract class, and all the derived class would immediately inherit our repairs and changes.
However, as I’ve noticed, VBScript does not support class inheritance, thus forcing us to manually copy the base code to all our derived classes. This means we would have to duplicate changes in multiple files, projects and computers – severally hampering our automation ROI.
The solution
Registeration is FREE, quick and private.
You can either Register pr Login if you have already registered
Summery
VBScript’s lack of class inheritance can be quite problematic for those of us who are using Classes regularly throughout our scripts. The attached file provides a parser which enables you to effectively use class inheritance in VBScript by placeing ‘<Inherit> ParentClassName comments within your classes. The mechanism will:
1. Enable inheritance from multiple parents (just use multiple lines with Inherit comments)
2. Copies Properties, Variables, Functions and methods from the parent class to the derived class.
3. In case the derived class already has a code segment with the same name, the copied code-segment is changed to MyBase_<Name>. Inner segment placements are updated accordingly.
4. Enables inheritance through multiple hierarchies (e.g. GrandParent->Parent->Child inheritance). Circular inheritance protection. The order of appearance in the files is irrelevant, the parser will make sure the parent classes are parsed before their derived classes.
5. Enables passing arguments to Class_Initialize constructors by using structured comments.
6. The parser has a major downside – as the technique uses ExecuteGlobal to load the processed classes into QTP, you cannot debug the code in mid-run.
Reliability
I’ve tested the parser on a wide variety of code libraries, and it seems to be working fine. Having said that, there’re probably some undocumented bugs which might prove to be catastrophic – be warned.
I’ve not planing on actively maintaining the parser, but if you’ll report bugs that are easily fixed, I’’ll work on them and post repaired versions when I get the chance. The parser is distributed AS IS, with NO WARANTIES, and should be regarded as a Beta / Alpha release.
Future Releases
This is just a preliminary work on the way to an integrated QTP parser. The end goal is being completely transparent for the user. Pressing F5 will run the test as usual, and the parser will work in the background in a manner which will allow debugging though the run-session.
I already have archived some milestone toward this goal – If you’d like to participate in the product’s beta group, please contact me and say so. Not everyone will be able to participate – so don’t get your hopes up :) .
Posted in QTP Hacks, Using Classes, VBScript Techniques


Yaron Assa




October 4th, 2008 at 5:44 pm
I’m downloading this immediately. What a simple and elegant answer to a major shortcoming.
As for debugging; if there were a method to generate the library files that included the inherited code in place of the ‘ tags, you could then add those files as resources and debug as normal.
October 5th, 2008 at 9:09 am
This feature looks very promising…
Excellent work!
October 5th, 2008 at 9:35 am
Great solution Yaron. Excellent solution, indeed.
October 5th, 2008 at 11:32 am
Thanks,
One major bug I’ve found is the inability to parse code segmnets with names the contain Sub, Function, Class etc.
I’ll update my regular expression engine and repost the attached file soon.
Meanwhile, the I’ve made some major progress in hooking into QTP for the background parser.
October 5th, 2008 at 4:44 pm
Great Solution!
Could you please tell me how it will resolve when we try to do multiple inheritance and when the two class=”searchterm1″>base classes contains the function with same signature?
Did you implement something which is similar to Virtual functions in C++?
October 6th, 2008 at 7:38 am
Hey shiv_nsk
The algorithm for conflicting code segments is as follows:, and add it
1. If no conflict occurs, the derived class copies the segment as is.
2. If the derived class already has a code segment with the same name:
Check if there’s a segment named MyBase_
If not, change the segment’s name to MyBase_
If true, then this segment has already been overridden once. Simply don’t add it.
Sadly the whole mechanism is very naive and simple - it’s just a text parser with some basic override logic.
October 6th, 2008 at 9:42 am
I’ve great expectations and I’m keen to see the Future Release including debugging facilities.
Great work so far.
regards - Erich
October 10th, 2008 at 5:12 am
Without enough support of Class usage is the most disappointing pitfall you have to tackle.
October 14th, 2008 at 11:36 pm
I’m concerned about the debug angle. My experience has been that automation developers often do not give enough consideration to how they will determine the root cause when something goes wrong at run time. This debug time is typically much harder to estimate than initial development time and hence consideration should be given to making debug as easy as it can be.
I have sacrificed the benefits of classes so as to not sacrifice debug ability. My team have a varying amount of programming and debug ability so I have to carefully consider the pro’s and cons of any solution. Simplicity / elegance at development time may have a negative impact at execution / debug time.
If a class class=”searchterm1″>based solution is a real benefit would it not be better to jump in with both feet and create a .net assembly that can be used in QTP? Of course an intepreted solution avoids the compile stage.
Just a few thoughts…
October 15th, 2008 at 1:53 am
Hi all,
I’ve created a different solution to this problem which I posted over at 4guys:
http://www.aspmessageboard.com/showthread.php?p=892720#post892720
Just came across this post, wasn’t sure if my solution was of any use to anybody.
If you need any help with it or you have any suggestions please let me know.
Thanks,
Reiss
October 15th, 2008 at 6:12 am
Reiss - Interesting solution - I wasn’t aware you could do that with GetRef. It’s pretty cool!
glennh - I understand your thoughts about debugging. I’ve almost finished a product which does the same thing, but still allows debugging.
October 15th, 2008 at 5:01 pm
Hi all,
I’ve updated the technique in the above post to provide better performance and super easy syntax:
http://www.aspmessageboard.com/showthread.php?t=229924
Rather than creating a “native class object” and “dictionary object” per new class, there is now one native class object “ClassHelper” that provides some simple methods for creating classes. This is seriously simple yet very powerful, proper inheritance and polymorphism, constructor parameters etc, and from my quick tests there is no performance penalty between this technique and native classes.
If you need any help with it or you have any suggestions please let me know.
@Yaron - I had initially gone down the “execute code on the fly” route like yourself but it brought with it too many problems, especially debugging, and performance suffers. The native class in class=”searchterm2″>vbscript is useless to be honest, simulating your own “class structure” like the javascript guys is the way to go in my opinion, however, I do like your parser. As always there is more than one way to solve a problem. :o)
Thanks,
Reiss
October 17th, 2008 at 1:45 pm
Thanks a lot for sharing your code!