Monday, November 7, 2011

ExecuteFile



Have you used ExecuteFile in your Action/Script to call Lib files?
There is another option in QTP to call functions and Sub Routines via Associate Resources Files tab. What is the difference between both of them. Here is my view.

Say there is a main script which calls sub scripts they cover 10 scenarios. For 6 scenarios the variables, constants, functions and sub routines are required from 'text1.vbs,text2.vbs,text3.vbs,text4.vbs and text5.vbs'  and for other 4 the variables, constants, functions and sub routines written in 'GeneralLib1.vbs,GeneralLib2.vbs,GeneralLib3.vbs,GeneralLib4.vbs and GeneralLib5.vbs' are required. If we use File--> Settings--> Resources to associate all 10 vbs files to main script, it will take time to read all 10 vbs and will have impact on performance of the main script. ExecuteFile statement is very useful in this case. By using conditions like if else statements we can call the required lib files at the required steps.
Here is the example:
If scnNumber=1 Then
   ExecuteFile "C:\Library\text1.vbs"
End if

If your location of lib files getting change offenly then use relative path as
If scnNumber=1 Then
   ExecuteFile "text1.vbs"
End if
But make sure that folder path is associated at Tools--> Options--> General --> Folders as C:\Library.
Disadvantages of ExecuteFile statement over Accosiate Lib file are break point is not going to work and execution marker will not move to the file and function which is getting executed. It will be difficult for debugging.
Here are the advantages and disadvantages of ExecuteFile statement and Associate Lib files

Advantages:
1. It can be called one or more Lib file/s in another lib files.
2. Lib files can be called at the point where it is exactly needed.
Disadvantages of ExecuteFile command
1. Will not display execution marker even after selecting Normal Mode in Tools->Options->Run
2. Will not support break Points.
3. Will not support F11 at middle of execution
4. To use F11 at middle of execution, need to click on Pause then it will support F11. But even this cursor will not display on the line number where it is getting executed for every clicks of F11.
5. It will not list associated function libraries in Resources-> Associated Function Libraries.
6. If there is a break point in a script and the statement where break point is applied is calling a function which is present in other lib files, then if user click on F11, it will move next statement but will not invoke the lib file and will not show the cursor.
7. When you run an ExecuteFile statement within an action, you can call the functions in the file only from the current action.
8. Function Generator will not list the Library Functions in Operation Drop down.

Advantages of Associate Lib files
1. Supports break points and F11 from there.
2. Easy to debug.
3. Execution Marker moves over each statement for every press of F11, we can see what the statement does.

No comments:

Post a Comment