Friday, October 15, 2010

VBScript- Property Let, Property Get, Property Set

Class properties in VBScript are used to assign values to private variable and handle the process of data validation.

Property Let: Which is used by the outside code to store a value in the private property variable. It is similar to a procedure in the sense that it does not return a value. A Property Let procedure must accept at least one argument. If the private variable you are using is an object then the process of assignment and data validation is handled by Property Set. Property Set: Similar to Property Let but used for object based properties. By default, the Property Set procedure is Public.

To retrieve the value of a private variable we will retrieve the value of a property. Property Get: This is used by code outside of your class to read the value of a private property variable. It is similar to a function in the sense that it returns a value to the calling code -- this value is the private variable value.

The Property Get procedure does not accept any arguments. You can add an argument to it, but then you have to add an additional argument to the property's corresponding Property Let or Property Set procedure, because Property Let/Set procedure must always have exactly one more argument than its corresponding Property Get procedure.

If the property get procedure returns an object then we can use the set statement (but it works well without set also) to return the value.

Class ABC
'Private Object
Private var_obj

Public Property Get username()
Set username = var_obj
End Property
End CLass

Read only Properties have only Property Get procedure

Write-only properties have only a Property Let or a Property Set procedure

Read-Write properties have a Property Get procedure and either a Property Let or a Property Set procedure

Example 1 of Property Let, Property Get, Property Set

Below Example, which shows a simple class that defines a private variable, m_var, and a two read-write properties, one_type and two_type, the latter of which is an object
property.

Class Computer
Private m_var
Private o_var

Public Property Let one_type(stringtype)
m_var = stringtype
End Property

Public Property Get one_type( )
one_type = m_var
End Property

Public Property Set two_type(oObj)
Set o_var = oObj
End Property

Public Property Get two_type( )
Set two_type = o_var
End Property

End CLass

Example 2 of Property Set

Here is the syntax for a Property Set procedure.

Class Main_class
'Private FS_Object object
Private var_Obj

Public Property Set FSPro(objFSPro)
Set var_Obj = objFSPro
End Property

End CLass

For example, here is what code that is using an object based on the above class might look like.

Dim objMain_class
Dim objFSPro
Set objFSPro=WScript.CreateObject("Scripting.FS_Object")
Set objMain_class = New Main_class
Set objMain_class.FSPro = objFSPro

Last line uses the Set Statement when it writes to the FSPro property. This is required because the Main_class class used a Property Set procedure for the FSPro property. Without the Set statement at the beginning of the last line, VBScript would produce an error. When a property on a class is object based, it is typical to use a Property Set procedure. Most programmers using this class would expect this.

Example 3 of Property Set

For example imagine we had a class that contained a private property named ob_var_conn that was expected to be an ADO Connection object. This class definition, with the
property Set and Property Get Statements might look like:

Class Connect_Class

'Create a Private property to hold our connection object
Private ob_var_conn

Public Property Get Connection()
Set Connection = ob_var_conn
End Property

Public Property Set Connection(ob_var_Connection)
'Assign the private property ob_var_conn to ob_var_Connection
Set ob_var_conn = ob_var_Connection
End Property
End Class

The end developer would use the Property Set statement in the following manner:

'Create an instance of Connect_Class
Dim ob_var_Class, ob_var_record
Set ob_var_class = New Connect_Class
Set ob_var_Connection = Server.CreateObject('ADODB.Connection')
'Assign ob_var_Connection to the connection property
Set ob_var_class.Connection = ob_var_Connection

As with the Property Let statement, the Property Set statement has an optional argument list. This argument list must be identical to the corresponding Property Get's argument list.

Sunday, October 10, 2010

QTP Recovery Scenario

QuickTest Professional Recovery Scenarios are summarized in the below mentioned points with three "easy to understand" examples.

1) With "Recovery Scenario Manager" you can

a) create and edit recovery files,
b) create and manage the recovery scenarios stored in those files.

2) A unique icon corresponds to a recovery scenario that indicates its type.

3) Each recovery scenario is represented by an icon that indicates its type.

4) You are guided step-by-step, through the process of creating a recovery scenario by Recovery Scenario Wizard.

5) You start by defining the trigger event. [4 trigger types are there Pop-up window, Object state, Test run error, Application crash]

6) After that you specify the recovery operation(s) [Recovery Operation can be Keyboard or mouse operation, Close application process, Function call, Restart Microsoft Windows]

When using Function call, Functions have to be defined using a prototype syntax, which is different for each trigger type.(See QTP User Guide.)

7) Then you select a post-recovery test run operation. [Which can be Repeat current step and continue, Proceed to next step, Proceed to next action or component iteration, Proceed to next test iteration, Restart current test run, Stop the test run]

8) The recovery file is saved in the specific location with the file extension .qrs.

9) Properties for any defined recovery scenario can be viewed from Recovery Scenario Properties dialog box

10) During the run session, QuickTest ignores deleted recovery scenario that is associated with a test or component.

11) You can copy recovery scenarios from one recovery scenario file to another.

12) The scenarios can be prioritized so that QuickTest applies the scenarios during the run session in a order of priority.

13) Some or all of the scenarios can be disabled.

14) Recovery Scenario(s) can be set as default for all new tests.

15) Go to File > Settings, the Test Settings dialog box opens. Select the Recovery tab.

You can edit a recovery scenario file path by clicking the path once to highlight it, and then clicking it again to enter edit mode.

16) In the Recovery tab itself you can define when the recovery mechanism is activated:

On every step.
On error
Never.

17) You can use the Recovery object to control the recovery mechanism programmatically during the run session.