Execution flow of Function Libraries

Function Libraries - An area where most interviewers focus on. The reason for this is that if you have worked on QTP, you just cannot miss using function libraries. If you didnt, then there definitely is something wrong in your framework. Functions and reusable actions help you achieve code modularization which is a very important aspect in test automation development.

I was not thinking of explaining the function libraries and how to associate them but rather on something very interesting related to the execution flow. You can already get a lot of information on what a function library is and how to work with them. So whats the fun if I was going to repeat the same thing, right !!!!! Thats the reason why I did not want to concentrate on that topic, however if you do want me to post a thread on the details, please do let me know.

OK..so what was I meaning by execution flow. Ideally and practically, a function library would contain function definitions, external function declarations and/or global constant declarations. However you must understand that theoretically and technically, it could actually contain any valid VB script syntax. So, to show the execution flow, I am going to do something here which we would not normally have in a function library but this is just to explain one particular concept here.

First I am going to create a function library called as Lib1 and this contains just the statement
MsgBox "Within Function Library 1"

This is what I said above that we wont put a MsgBox in a function library and this is purely for illustration purpose. Next I am going to create a test and associate this function library within that test.



















My test contains nothing but another MsgBox statement






So we are ready... Lets run the script now and see what happens...
We first got








And then...








So what does this mean. When an action is run, the first thing that happens is that function library is executed first and only then the code within the action is being executed. So far so good but lets try to make it more interesting. Lets create another function library called Lib2 and associate that too with this test. Lib2 contains another MsgBox statement
MsgBox "Within Function Library 2"


 
















Now lets run our action and see what we get but before that I want you to anticipate what the outcome would be and then check the result. Which MsgBox came first ???








And then








And then








I am sure most of you would have expected the Function Library 1 MsgBox to appear first, right ? But no, the order of execution of the Function libraries are Bottom-Up and NOT Top-Down. Well, you can change the order of the function libraries and see what happens. But dont you think this is sort of wierd !!! From a user point of view, it looks like the library on the top would be executed first. So I am not sure if this is a bug in QTP or is this as per design.

Well, it doesnt really matter so long as we know what the order of execution is. I hope you all enjoyed this interesting fact and understood the execution flow of function libraries. See you soon !!!



I dont want to have any sort of copyright or copyleft in this site but if you are reusing this code in any other site, I would appreciate you to provide this page as a link so that others get a more descriptive explanation of this concept. Your suggestion and comments are always welcome. Cheers !!!
As always,
Your friend in need,

George, Reju

Read Users' Comments (1)comments

1 Response to "Execution flow of Function Libraries"

  1. Anonymous Says:
    August 28, 2013 at 11:13 AM

    Thanks for sharing the good thing with us.
    it's really useful for novice user.

Post a Comment

Visitors

Website Counter