Subscribe by Email


Tuesday, September 4, 2012

What are User Define Functions? What are all the different types of User defined functions? (In WinRunner)


The testing capabilities of the winrunner can be extended further by letting the user create his own TSL functions. The TSL functions thus created can be used in a compiled module as well as in a test. 

Apart from just providing the built in functions, the TSL allows you to do the following:
1. The user defined functions can be defined by the user. After defining the function once in the test script, it can be called from anywhere in the tests.
2. The user defined functions can be defined by the user for compiled modules. Once that particular gets loaded, the functions it holds can be called from anywhere.
3. These user defined functions can be called from anywhere in the Microsoft API and other external DLL functions as well.

- The user defined functions are used when it is required to perform the same operations several number of times. 
- Instead of repeating the same code again and again, a single function can be written that will perform the same operations a number of times. 
- This has the following benefits:
  1. It makes your test scripts more modular.
  2. It makes your test scripts more readable.
  3. It becomes easier to maintain the code and debug it.

What are User Defined Functions?

- A user defined function because of being incorporated in to the compiled module can be accessed from any where. 
- At the same time the time taken for the execution is reduced since the compilation of the function is done in the earlier stages only. 
- Below stated is the typical declaration for a user defined function:
[class] function name ( [mode]  parameter.... )
{
Declarations;
Statements;
}
- The class of the function can either be public or static. 
- Whenever a static function is declared with static class it is made available to the module or the test within which that function lies. 
- Once a function with a public class is executed, it is made available to almost all the tests for the time till the test holding that function remains open. 
- This seems to be the most convenient option when it is required that the function should be accessible from all the tests. 
- However if the case is as such that it is required that many tests should be able to access the function, then the function has to be placed in a compiled module. 
- Whenever a function is placed in the compiled module, it becomes accessible until the duration of the testing session ends. 
- Unlike the class, there is no need of declaring the parameters explicitly. 
Parameters can possess any one of the following modes:
  1. In: in this mode the value is assigned from outside the function.
  2. Out: in this mode the value is assigned from inside the function.
  3. Inout: in this mode the value can assigned either from inside or from outside the function.

Types of User Functions in WinRunner

Now let us state all are the types of user defined functions:
  1. Scalar functions
  2. Multi- statement table valued functions and
  3. Inline table valued functions
- A user defined function may consist of either zero parameter or more then that.
- The function may return either a table or a scalar value.
- However, the input parameters have a limit of 1024. 
- If the function is to be driven with the default values then the key word DEFAULT must be specified while you call the function. 
- This key word is added in order to get a default value for the user defined functions. 
- In some cases if you omit the parameters then the parameters are treated to be default values. 


No comments:

Facebook activity