Saturday 15 September 2012

Library Files

This is a continuation

In an automation framework architecture library files plays an important role. Normally people try to built most generalized function and place them at separate and common place.

I see that people always ask me questions which one is good to use Action or functions? I have personal view on these to use Functions instead of Actions. Of-course every aspects have its own pros and cons. Some people may feel comfortable to use Actions rather than Functions.

Whenever I create a functions I always have an intentions in my mind whether I can make this functions more generalized? I have developed an habit to have function's maximum usability. But be caution think to make generalized function should not change your motto of creating it ;)


A function doesn't meant to only have the VBscript codes, of-course you can always have QTP script codes . Functions are often treated as keywords in QTP, now a keyword can be placed separately in excel file, text file, or XML file. so that you can design keyword driven framework.

While automating (developing script) a particular workflow/E2E test case, first I create scripts in Linear manner in a particular action. Later on I break down these workflow in smaller script parts, of-course to divide these you need to know other test cases also so that you can easily identify commonality in functionality. Don't worry if you are not able to identify commonality, just go ahead and as you move ahead with framework designing you will be able to know it.

Now, the divided code is bundled under functions with a name which could make sense, for example NavigateTo(strURL), Login(strUserName, strPassword), NavigateToPageMenu(strMenuName), LogOut()

In an attempt to make execution faster and in terms of maintenance we load the functions runtime by leveraging power of "ExecuteFile" method. See, when you associate the ".qfl" file with script, so when you want to move complete framework folder, you will have to re-associate the library files. Of-course while script development you would require to associate library file for debugging purpose. Later on after your code is fully developed you can use "ExecuteFile" method to make all functions available in QTP run session during runtime.

I will update some more ideas in future, ofcourse many more ideas related to Library files.

Now Talking about our Framework development, presuming I have functional knowledge of AUT. I decide to place functions in appropriate library file. When I say appropriate library file . . . I meant only those library files containing specific functions which are relevant to a particular module or Test Case should be loaded. It doesn't make sense if you have numerous function written in a library file and in runtime load, these function are available which are of no use.

I have seen people writing function in an unorganized fashion and a single library files are flooded with many functions which are sometimes create problem during maintenance. Ofcourse no harm with that, but I believe this as to be the best practices.

See below image for a gist I am trying to convey . . .













 In above framework folder structure you can see some library files example placed. I guess no need to explain library files other than "GlobalFunctions.qfl"

GlobalFunctions.qfl :- This is one its kind, you know as the name suggest I place all those functions which 
  • are repetitively used
  • needs to have global scope
  • are very generalized
For example functions like
FrameworkInitializer, LoadModuleBasedTestData, LoadGlobalDataVariablesFromGlobalDataxls, CreateOutputDataFile, InitializeLogs, WriteCurrentLogInLogFile, ReportPassFail . . .

I have purposefully named these functions to be more meaningful to you ;)

GlobalFunctions.qfl file is associated with all QTP TestScript. The decision to put functions in which library files solely depends on you, you have to design the architecture, you have to design the workflow of you framework, you have to decide when to load which library files.

-Pankaj Dhapola 
Think on it