View the list of methods of a .NET Control
March 5, 2010 at 10:51 am | Posted in Test Automation | Leave a commentWhile Automating .NET based applications, we might some times require to access the methods exposed by the controls directly from UTP. For viewing the various methods which a control exposes, in UTP, we have a DotNet class Viewer which shows the list of all the methods of a control.
Here are the steps to view the .NET methods.
- Invoke the Interface Driver (SDTIDE).
- Open the GUI Mapper and capture any .NET application.
- Select a control from the list of captured controls and select the Property button.
- A new window opens with all the supported methods within it.
- We should copy and paste the methods in the DotNet Class View window to see the internal supported methods. Copying is possible by double clicking on the required method.
In the below figure, we can see the GUI Mapper window which is having a sample .NET captured application and saved as a new GUI Map File under a Project,
Getting methods for a control is a very easy process in UTP. All the supported .NET methods will be displayed as a separate window by selecting the control and pressing the ‘Property’ button in the GUI Mapper window.
The below image shows a list of ‘Methods’ displayed for a .NET control (Combo Box). We can also view the supported ‘Fields’ and ‘Properties’ by selecting the corresponding radio buttons in the below window.
If the return type of the method is an object of a particular class and if its list of methods is to be determined, you can copy its Return Type and paste it in the “Class Name:” edit box of the ‘DotNet Class View’ available in the GUI Mapper File menu.
Figure shows the ‘DotNet Class View’ menu option in the GUI Mapper.
Copying of a Return Type is also possible by clicking on a method displayed.
Ex: For example, copied method is “public System.Windows.Forms.AccessibleObject get_AccessibilityObject()”. You can view the methods of the ‘Return Type’ “System.Windows.Forms.AccessibleObject” after pasting it in the Class Name: edit box.
Invoking the specific methods of .NET Application controls using the Object Model
March 5, 2010 at 10:51 am | Posted in Test Automation | Leave a commentBackground:
In today’s environment applications are becoming more complex and domain specific code is being written to develop applications. In the process of automated testing, it is some times required to have direct access to the application API and be able to call the methods/functions of the controls in the application under test.
In case of applications developed in .NET environment, UTP provides a way to access and invoke the methods of the controls in the Application. The UTP .NET Functions enables the Automation Engineers to get the .NET Objects for the corresponding Logical name of the control and then invoke the methods on the .NET objects. This will be very useful in automating the applications developed using .NET environment.
Sample Application:
For the purpose of explaining the process of invoking the .NET methods, we are using a sample .NET application which has a combobox in it.
Solution:
Data types in UTP for .NET
The data types which are used in .NET for invoking the methods are
UTPDotNetObject
-
This data type should be used in various UTP .NET Functions, when a .NET object has to be retrieved or a .NET object has to be passed to the Constructors/methods of .NET Class.
-
This contains two more fields
-
Ref – This will have the Reference to a Java Object as String recognized by UTP.
-
Value – Value of the Object, if the java object is a basic data type like int, long, String, etc.
UTPDotNetParameters
- This data type should be used in various UTP .NET Functions when passing Parameters to a Constructor or Methods
- This is a Collection of Strings. The String can be UTPDotNetObject.Ref where a .NET object has to be passed. For all other basic data types, the value has to be passed as a string.
The method invocation is done from the SDTIDE.
The process of invoking the .NET controls methods involves the following basic steps .
- Getting the Object Reference (from application) of the Combo Box Control for its given Logical Name.
- Preparing the required parameters to pass to a .NET control method.
- Invoke the method/function on the Object Reference with the prepared parameters.
1. Getting the Object Reference (from application) of the Combo Box Control:
Here are the detailed steps to get an Object Reference of a ComboBox Control.
- Declare a UTPDotNetObject
- Dim CntrlObject As UTPDotNetObject
- Call UTP.DotNet.GetObject(“ComboBox1”, CntrlObject) to get the reference of the Object for the combobox control
- ComboBox1 is the captured logical name of Combo Box Control. This should have been already captured in a GUI File.
- CntrlObject is where the object reference of the control will be returned.
2. Preparing the parameters to pass to the method:
We have to prepare the parameters that have to be passed to method, for selecting the desired item from combo box control.
- Declare UTPDotNetParameters variable which is a collection object
- Dim comboboxParameter As New UTPDotNetParameters
- Then add appropriate parameter values to the UTPDotNetParameters object. In this case we add “Jon” as parameter. This item will get selected.
- comboboxParameter.Add “Jon”
3. Invoke the method/function on the Object Reference:
We got the Object reference in Step1 and prepared parameters in Step2. Now we have to call the appropriate method on the Object by passing the prepared parameters. The appropriate method is ‘set_SelectedItem’.
Please refer the blog article on how to view the list of methods of .NET control.
Here is the way to invoke this method.
- Dim RetObject as UTPDotNetObject
- UTP.DotNet.InvokeMethod(CntrlObject, ” set_SelectedItem”, RetObject, comboboxParameter)
Sample Code:
We have seen how to invoke a method of an application .NET application control. In this sample, we will put all the code together in a UTP Custom Object for selecting the desired item from the ComboBox in a .NET based application.
Dim funReturnValue As Boolean
Dim CntrlObject As UTPDotNetObject ‘Declaration of the DotNet Objects
Dim RetObject As UTPDotNetObject
Dim comboboxParameter As New UTPDotNETParameters ”Declaration of DotNet Parameters
Dim reqitem As String
‘ Combobox item which is to be selected
reqitem = “Jon”
‘ —Getting the Object Reference to the ComboBox Control
funReturnValue = UTP.DotNET.GetObject(“ComboBox1″, CntrlObject)
If (CntrlObject Is Nothing) Then
UTP.ReportComment “Not able to get ComboBox Object “
Exit Sub
End If
‘—Preparing Parameter value
comboboxParameter.RemoveAll
comboboxParameter.Add reqitem
‘ —Invoke ‘ set_SelectedItem ()’ method on ComboBox Object with parameter value as ‘Jon’
funReturnValue = UTP.DotNET.InvokeMethod(CntrlObject, “set_SelectedItem”, RetObject, comboboxParameter)
If funReturnValue = False Then
UTP.ReportError “Unable to select the item in combobox”, engineError
Else
UTP.ReportComment “Desired item selected Successfully”
End If
‘Code Ends here
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.


