5.5. How to Use the Windows nativeObject API

One of Squish's most useful features is the ability to access the toolkit's API from test scripts. This gives test engineers sufficient flexibility to allow them to test just about any aspect of the AUT.

With Squish's Windows Object API it is possible to find and query objects, call methods, and access properties. In addition, Squish provides a convenience API (Windows Convenience API (Section 6.12)) to execute common GUI actions such as clicking a button or typing text into a control. Windows objects are made available in a wrapper and the underlying objects' properties and methods are accessible through the Squish-added nativeObject property.

For example, to access the items in a windowsforms list view, we would first obtain a reference to the list view, and then access the items:

Python
listview = waitForObject(":_ListView")
items = listview.nativeObject.Items
item1 = items.at(0)
JavaScript
var listview = waitForObject(":_ListView");
var items = listview.nativeObject.Items;
var item1 = items.at(0);
Perl
my $listview = waitForObject(":_ListView");
my $items = $listview->nativeObject->Items;
my $item1 = $items->at(0);
Ruby
listview = waitForObject(":_ListView")
items = listview.nativeObject.Items
item1 = items.at(0)
Tcl
set listview [waitForObject ":_ListView"]
set items [property get [property get $listview nativeObject] Items]
set item1 [invoke $items at 0]

Here is another example that writes the names of a windows object's methods (in this case a list view) to the Squish log.

Python
listViewType = listview.nativeObject.GetType()
methods = listViewType.GetMethods()
for method in methods:
    test.log("ListView method: " + method.Name)
JavaScript
var listViewType = listview.nativeObject.GetType();
var methods = listViewType.GetMethods();
for (i = 0; i < methods.length; ++i)
    test.log("ListView method: " + methods.at(i).Name);
Perl
my $listViewType = $listview->nativeObject->GetType();
my @methods = $listViewType->GetMethods();
foreach $method (@methods) {
    test.log("ListView method: " . $method->Name);
}
Ruby
listViewType = listview.nativeObject.GetType()
methods = listViewType.GetMethods()
for method in methods
    Test.log("ListView method: " + method.Name)
end
Tcl
set listViewType [invoke [property get $listview nativeObject] GetType]
set methods [invoke $listViewType GetMethods]
foreach method $methods {
    set name [property get $method Name]
    test.log("ListView method: $name")
}

[Under Construction  .]