Saturday, 22 June 2013

QTP :-Useful Datatable Methods

Data table methods are used for performing the operations on the runtime data table

1. Add- sheet: It is used for adding the new sheet for the runtime data table

Syntax: Datatable.Addsheet("SheetName")

Ex. Datatable.Addsheet("Sumit")




2. Delete- sheet: It is used for deleting a specified sheet from the run time data table

Syntax:
Datatable.Deletesheet("SheetName")
Datatable.Deletesheet(SheetID)


Ex. Datatable.DeleteSheet("Sumit")
Ex. Datatable.DeleteSheet(3)


3. Import: It is used for importing the data present in all the sheets in an excel file to the runtime data table
Syntax:
DataTable.Import("pathoffile")


ex datatable.Import("c:\esbbxl.xls") 



'4. Import Sheet: It is used for importing specified sheet of data from the excel file to the specified sheet in the runtime data table
'Syntax:
'Datatable.Importsheet “path of the excel file, source sheet id, destination sheet id”


datatable.ImportSheet "c:\esbbxl.xls",2,3 


//Imports 2nd sheet from esbbxl file  into 3rd sheet of datatable, i.e action 2 in our case.
1. Global
2.Action 1
3. Action 2 







 



 




QTP: Some useful Typecasting functions QA Enginners use in real time

QTP: Some useful Typecasting functions  QA Enginners use in real time

1. CINT
 This functions coverts string into integer.
Ex.

dim avalue="7"
dim bvalue="10"

if avalue >bvalue then

print avalue is greater

end if

Output:





Corret Code:





















dim avalue,bvalue


avalue="7"
bvalue="10"

if (cint(avalue) >cint(bvalue)) then

msgbox  "avalue is greater"

end if

Output: does not print anything as 7 is not greate than 10



CBool
To return a Boolean value of an expression for true/false condition

QTP- Registeruserfunc method : How to regsiter public function to test object

Register User Function is used to append a new method (Function/ Procedure) or to take priority over of a presented method for a certain QTP Class during run session. Register User Function is relevant for Test Objects similar to VbEdit, VbList, WebEdit, WebList, Dialog, Window and Browser etc…

To Register a Function, foremost define a Function and mark Register User Function declaration at the end of Function Library or in test script. You can Register a New Method for a Test Object Class or Use an Existing Method Name to take priority over the existing Functionality of the specified Method.

If the Function is defined and it is not registered, it operate as a Global Function, you can monitor all your defined functions in Step Generator (F7) if they are globalized. Once the Function is registered, you can’t see the registered function in Step Generator.

The Register Method applicable only in test Script or in Function Library. QTP clears all Registrations at the beginning of Every Run Session.

Syntax: RegisterUserFunc TOClass, MethodName, FunctionName, SetAsDefault

Arguments:
ToClass: To which Class you want to register the method.
Method Name: String which you like to see in methods List for that class.
Function Name: The name of the user defined function which you have defined.

Note: The Function should be located in your Action or in a Library file which you have associated to your Test Script.
SetAsDefault: Indicating that the registered function should be used as a default method for test object/not

Examples:
1. The following Example describes how to append a new method to QTP Class

Sub AddNewMethod (Object, ParameterValue)
If Object.Exist Then
Reporter.ReportEvent micPass, "Object Exist", "XXXXXXXXX Object is existed on this Page"
Else
Reporter.ReportEvent micFail, "Object Exist", "XXXXXXXXX Object is existed on this Page"
End If
End Sub

Declaration: RegisterUserFunc "WebEdit", "AddNewMethod","AddNewMethod",True

After finishing the delcaration of Function and its Registration save file as “FileName.vbs” and associate to the test script. You will find the registered new method in list of methods which supports WebEdit Class and displays as

Browser("QTP Descriptive Programs").Page("QTP Descriptive Programs").WebEdit("email").AddNewMethod

2. The Following Example describes how to add new function to an existing QTP Class/ method.

Function MySet (Object, x) [Ex: obj = Browser("MercuryTours").Page("FindFlights").WebEdit("Country")]
Dim y
Y = Object.GetROProperty("value")
Reporter.ReportEvent micDone, "previous value", y
MySet=Object.Set(x)
End Function

RegisterUserFunc "WebEdit", "Set", "MySet"

The behavior of the above function is to capture and report the value of an edit box before the new value is entered. We are registering the above function with existing set method of Test Object WebEdit i.e., modifying the Set Method behavior with newly distinct function.

Note: Once a new method is registered, the method becomes a recognized method to that specific Test Object until you unregister that method. If your method overrides an existing QTP method unregistering that method resets the method to its normal behavior. Unregistering new methods deletes that method from list of methods which supports by the Test Object. To Un-Register a Function make use of the following Syntax.

Syntax: UnRegisterUserFunc TOClass, MethodName
Arguments:
ToClass: To which Class you want to register the method.
Method Name: String which you like to see in methods List for that class.

Example: UnRegisterUserFunc "WebEdit", "Set"

Thursday, 13 June 2013

SystemUtil Object Usage in QTP

SystemUtil Object Usage in QTP


SystemUtil Object:
SystemUtil Object used to control applications and processes during a run session

Methods:

Run: Used to Runs a file or application.
e.g: Systemutil.Run "www.google.co.in","","",""

CloseProcessByName: Closes a process according to its name.
e.g: Systemutil.CloseProcessByName("Excel.exe")

BlockInput: Used to Prevents keyboard and mouse input events from reaching applications.
e.g: Systemutil.BlockInput

UnblockInput: Used to Re-enables keyboard and mouse input events after a BlockInput statement was used to block them.
e.g: Systemutil.UnblockInput

CloseDescendentProcesses: Used to Closes all processes opened by QuickTest.

CloseProcessByHwnd: Used to Closes a process that is the owner of a window with the specified handle.

CloseProcessById: Used to Closes a process according to its Process ID.

CloseProcessByWndTitle: Used to Closes all processes that are owners of windows with the specified title. 

Spring Boot : Exception Handler 14