Subscribe by Email

Tuesday, September 25, 2012

What is the difference between functions and actions in QTP?

Functions and actions are two different aspects of quick test professional. In this article we will talk regarding the two and see what the differences between them are. 

What are functions in QTP?

- In most of the cases you may need to use some segments of code again and again in your tests. 
- In such a case a user defined function can be created which will not only reduce the length of your tests but will also make it easier to be designed, read and maintained. 
- The created functions can consist of the following:
  1. Sub routines,
  2. Modules
  3. VBScript functions and so on.
- Three simple tests need to be followed if a function is to be used in the test from a library:
  1. For creating a new function you can select new function library from the file menu. This cause a new tab to open up in the quick test professional window. You can even opt for multiple tests in the same file.
  2. Next you need to save the function with extension “.qfl” and associate the appropriate library with that particular function. “Associate function library” option can be accessed from file menu.
  3. Now the third step is to invoke the function using the usual simple function call. Quite advanced or sophisticated functions can be generated using DCOM and COM.

What are actions in QTP?

- Whenever you have a piece of code at your disposal you get two options in quick test professional i.e., to either turn it in to a function or a reusable action.
- When the quick test 9 was introduced by the mercury, an argument was made in the favor of the functions for making them more compelling by the means of multi document interface. 
- Many function libraries can be used at once but still mostly one test is used. 
- If you want a reusable action to be edited, the current test has to be shut down. 
- Then you need to open the test in which you want to make the changes, make the changes and then save and close. 
- Later, the original test can be re-opened.

Differences between Functions and Actions in QTP

Now we are stating below some very basic differences between the functions and actions in quick test professional:

1. Passing of Data: 
Functions can access a variety of objects advance as well as primitive like arrays, test objects (such as frames, pages and so on.) and dictionary objects. But this is not the case with the actions rather they can accept only primitive kind of data types such as parameters like integers, strings and so on.

2. Use of Resources: 
Each action is provided with the following basic things:
a)   A folder
b)   3 separate VBS files
c)   A subfolder for keeping snapshots
d)   A certain amount of load time
e)   An excel spreadsheet and
f)    A local object repository.
On the other hand a function consists of only the code and nothing else.

3. API: 
For functions, the function libraries can be attached to the test scripts through the API of the quick test professional. As for the actions the insertion of the calls in the existing actions is not possible through the API of the quick test professional rather it can be done only through the interface.

4. Return Values: 
Actions return the values which are quite difficult to be read in syntax as well as understand. On the other hand the return values of the functions work well and similarly in all the languages.
With actions your test can be divided in to business processes or logical units along with the scripts that are more efficient as well as modular.

No comments:

Facebook activity