The information in this topic applies to web tests that implement the default approach (rely on Name Mapping and run in local environments).
There are several ways to refer to objects in Flash and Flex applications. If you use Name Mapping in your test project, you can refer to the application objects using their names specified in Name Mapping. For objects not in Name Mapping, you can use the naming syntax that directly includes identification properties and values of these objects. This topic explains both approaches.
About Object Names in the Object Browser
Addressing Flash and Flex Objects Using Name Mapping and Aliases
Addressing Flash and Flex Objects Without Name Mapping
About Object Names in the Object Browser
You can explore the object structure of the tested application in the Object Browser. Here is a sample view of the Flex application hierarchy displayed in the Object Browser:
Here, the Browser("iexplore")
branch of the Sys
object corresponds to the browser under which the tested Flex application is running; the orders("orders")
object and further objects correspond to the application’s controls and objects.
To refer to an individual object in a tested Flash or Flex application, select the needed object in the Object Browser or Object Spy. These tools display the selected object’s name above the member list. From the right-click menu, you can copy this name to the clipboard and then insert it into your test.
You may notice that this name is different from what you see in the object tree on the left of the Object Browser. This is because the name displayed at the top of the panel uses object aliases if they are defined, whereas the object tree uses the naming syntax that includes identification properties. The differences between the two object naming syntaxes are explained in the Addressing Flash and Flex Objects Using Name Mapping and Aliases and Addressing Flash and Flex Objects Without Name Mapping sections below.
You can also learn object names in different syntaxes by looking at the following object properties:
-
MappedName
- the object’s fully-qualified alias (including aliases of all parent objects). This name is used for the object by default in your tests. Note that if the selected object is not in Name Mapping, this property is empty. -
Name
- the object name that includes its identification properties. This is the same name you see in the Object Browser’s object tree. For an explanation of this syntax, see below. -
FullName
- the object’s fully-qualified name in the syntax that includes identification properties. This name consists of the object’sName
property value and theName
s of all of its parent objects. See below.
Addressing Flash and Flex Objects Using Name Mapping and Aliases
By default, TestComplete uses object names from Name Mapping (the object repository) to refer to individual objects in Flash and Flex applications under test. These names are called aliases. When you record a test, TestComplete automatically adds recorded objects to Name Mapping and generates aliases for them.
You can see available object aliases and add new aliases in the Name Mapping editor.
Here, Mapped Objects and Aliases display the hierarchy of mapped objects and their aliases, respectively. The fully-qualified alias that can be used to refer to an object is displayed in the top right of the Name Mapping editor (see the image above). It starts with Aliases and includes aliases of all of the object’s parent objects separated by dots (in VBScript, JScript, Python and DelphiScript projects) or square brackets (in C++Script and C#Script projects). For example, in the image above you can see that you can refer to the buttonNewOrder object using the following name:
JavaScript, JScript
Aliases.browser.page.objectOrders.buttonNewOrder
Python
Aliases.browser.page.objectOrders.buttonNewOrder
VBScript
Aliases.browser.page.objectOrders.buttonNewOrder
DelphiScript
Aliases.browser.page.objectOrders.buttonNewOrder
C++Script, C#Script
Aliases["browser"]["page"]["objectOrders"]["buttonNewOrder"]
You can copy object aliases from the Name Mapping editor to the clipboard and use them when manually adding test operations with the tested application’s objects.
The following example shows a sample click on the buttonNewOrder button specified by an alias:
Note: | For simplicity, keyword tests do not display the Aliases identifier at the beginning of object aliases.
Also, keyword tests may not display intermediate objects in the application’s object hierarchy. To view the full name of an operation’s target object, double-click the operation or increase the Maximum depth option in Keyword Test Editor - Groups options. |
JavaScript, JScript
Aliases.browser.page.objectOrders.buttonNewOrder.ClickButton();
Python
Aliases.browser.page.objectOrders.buttonNewOrder.ClickButton();
VBScript
Call Aliases.browser.page.objectOrders.buttonNewOrder.ClickButton()
DelphiScript
Aliases.browser.page.objectOrders.buttonNewOrder.ClickButton();
C++Script, C#Script
Aliases["browser"]["page"]["objectOrders"]["buttonNewOrder"]["ClickButton"]();
Note that the fully-qualified mapped name for this object is as follows:
JavaScript, JScript
NameMapping.Sys.browser.page.objectOrders.orders.buttonbarBar.buttonNewOrder
Python
NameMapping.Sys.browser.page.objectOrders.orders.buttonbarBar.buttonNewOrder
VBScript
NameMapping.Sys.browser.page.objectOrders.orders.buttonbarBar.buttonNewOrder
DelphiScript
NameMapping.Sys.browser.page.objectOrders.orders.buttonbarBar.buttonNewOrder
C++Script, C#Script
NameMapping["Sys"]["browser"]["page"]["objectOrders"]["orders"]["buttonbarBar"]["buttonNewOrder"]
Since the orders and buttonbarBar objects are of no interest for our test, we exclude them from the path to the buttonNewOrder object in the Alias tree, so the object hierarchy becomes shorter. Using aliases lets you make your scripts shorter and more readable.
For more information about using Name Mapping and aliases, see About Name Mapping and Access Objects by Aliases.
Addressing Flash and Flex Objects Without Name Mapping
Your tests can work not only with applications and objects added to Name Mapping, but also with any other running applications, their windows and controls. These objects can be addressed using syntax that directly includes identification property values.
The following sections describe how you can address objects in Flash and Flex applications running under a web browser or under Flash Player standalone:
Addressing Objects in Flash and Flex Applications Running Under a Web Browser
Addressing Objects in Flash and Flex Applications Running Under Flash Player Standalone
Addressing Objects in Flash and Flex Applications Running Under a Web Browser
Consider the following sample code and keyword test that illustrate how you can refer to an object in your Flash (Flex) application running under a web browser:
JavaScript, JScript
Sys.Browser("iexplore").Page("https://services.smartbear.com/samples/testcomplete10/flex/").Object("orders").orders("orders").ButtonBar("Bar").ButtonBarButton("New Order").ClickButton();
Python
Sys.Browser("iexplore").Page("https://services.smartbear.com/samples/testcomplete10/flex/").Object("orders").orders("orders").ButtonBar("Bar").ButtonBarButton("New Order").ClickButton();
VBScript
Call Sys.Browser("iexplore").Page("https://services.smartbear.com/samples/testcomplete10/flex/").Object("orders").orders("orders").ButtonBar("Bar").ButtonBarButton("New Order").ClickButton
DelphiScript
Sys.Browser('iexplore').Page('https://services.smartbear.com/samples/testcomplete10/flex/').Object('orders').orders('orders').ButtonBar('Bar').ButtonBarButton('New Order').ClickButton();
C++Script, C#Script
Sys["Browser"]("iexplore")["Page"]("https://services.smartbear.com/samples/testcomplete10/flex/")["Object"]("orders")["orders"]("orders")["ButtonBar"]("Bar")["ButtonBarButton"]("New Order")["ClickButton"]();
To learn the exact syntax for referring to a particular object, use the Object Browser - the object tree and the FullName
property of objects always use this naming syntax. See the About Object Names in the Object Browser section above.
Let’s have a closer look at this notation and its components.
-
The notation starts with the
Sys
object that represents the operating system. -
The next object,
Browser("iexplore")
, represents under what browser the application is running. -
The
Page(URL)
object is a container web page that hosts the tested application. -
The next two objects,
Object("orders")
andorders("orders")
, correspond to the main window of the tested Flash or Flex application.- The first one,
Object("orders")
, corresponds to theOBJECT
element of the web page that embeds the tested application. - The second object,
orders("orders")
, corresponds to the top-level visual container of the tested Flash or Flex application.
- The first one,
-
Further objects represent visual objects in the Flash or Flex application.
TestComplete uses the following syntax for these objects:
ObjectType(ObjectIdentifier)
Here, ObjectType is an object class name specified by the object’s
FlexObject.className
property. ObjectIdentifier is the object name (value of theObjectIdentifier
property). This name is specified by the object’s native properties in the following way:- TestComplete tries to address Flash and Flex objects by the value specified in the native
FlexObject.id
property. - If TestComplete does not find any value in the
FlexObject.id
property, the object is addressed in tests by the nativeFlexObject.name
property. - If the name of an Flash or Flex object is not specified in the application (or if it is generated automatically), TestComplete tries to address such an object by its
FlexObject.label
. - If TestComplete does not find any value in the
label
,name
andid
object properties, the object is addressed in tests by the object type name and index among other objects of the same type that are located on the same hierarchy level (for instance, CheckBox(0)).
- TestComplete tries to address Flash and Flex objects by the value specified in the native
Addressing Objects in Flash and Flex Applications Running Under Flash Player Standalone and in Self-Executed Applications
Here is sample code and keyword test that illustrate how you can refer to an object in a Flash or Flex application running under Flash Player standalone (or a self-executed Flash or Flex application):
JavaScript, JScript
Sys.Process("flashplayer").Window("ShockwaveFlash", "Adobe Flash Player 11", 1).TestSimple(0).Button("btn").ClickButton();
Python
Sys.Process("flashplayer").Window("ShockwaveFlash", "Adobe Flash Player 11", 1).TestSimple(0).Button("btn").ClickButton();
VBScript
Call Sys.Process("flashplayer").Window("ShockwaveFlash", "Adobe Flash Player 11", 1).TestSimple(0).Button("btn").ClickButton
DelphiScript
Sys.Process('flashplayer').Window('ShockwaveFlash', 'Adobe Flash Player 11', 1).TestSimple(0).Button("btn").ClickButton();
C++Script, C#Script
Sys["Process"]("flashplayer").Window("ShockwaveFlash", "Adobe Flash Player 11", 1)["TestSimple"](0)["Button"]("btn")["ClickButton"]();
To learn the exact syntax for referring to a particular object, use the Object Browser - the object tree and the FullName
property of objects always use this naming syntax. See the About Object Names in the Object Browser section above.
Let’s have a closer look at this notation and its components.
-
The notation starts with the
Sys
object that represents the operating system. - The next object,
Process("flashplayer")
, represents that an application is running under Flash Player standalone. If you are running a self-executed Flash or Flex application, the name of the process corresponds to the name of its executable file (for example, Process("MyFlexApp")). -
The next object,
Window("ShockwaveFlash", "Adobe Flash Player 11", 1)
, is the main Flash Player window. -
Next objects represent top-level visual containers and visual objects in the tested Flash or Flex application.
TestComplete uses the following syntax for these objects:
ObjectType(ObjectIdentifier)
Here, ObjectType is the type of the object specified by the object’s
FlexObject.className
property. ObjectIdentifier is the object name (value of theObjectIdentifier
property). This name is specified by the object’s native properties in the following way:- TestComplete tries to address Flash and Flex objects by the value specified in the native
FlexObject.id
property. - If TestComplete does not find any value in the
FlexObject.id
property, the object is addressed in tests by the nativeFlexObject.name
property. - If the name of an Flash or Flex object is not specified in the application (or if it is generated automatically), TestComplete tries to address such an object by its
FlexObject.label
. - If TestComplete does not find any value in the
label
,name
andid
object properties, the object is addressed in tests by the object type name and index among other objects of the same type that are located on the same hierarchy level (for instance, CheckBox(0)).
- TestComplete tries to address Flash and Flex objects by the value specified in the native
For examples of this syntax applied to objects in your tested Flash or Flex application, examine your application in the Object Browser. You can also copy this syntax from the Object Browser and paste it to your test to avoid having to type it manually.
Combining Mapped and Unmapped Object Names
You can combine aliases specified in Name Mapping and the ObjectType(ObjectIdentifier)
notation when referencing an object hierarchy in tests. For example, you can use aliases for parent objects and the ObjectType(ObjectIdentifier)
notation for child objects:
JavaScript, JScript
Aliases.browser.pageSample.objectOrders.ButtonBar("Bar").ButtonBarButton("New Order").ClickButton();
Python
Aliases.browser.pageSample.objectOrders.ButtonBar("Bar").ButtonBarButton("New Order").ClickButton();
VBScript
Aliases.browser.pageSample.objectOrders.ButtonBar("Bar").ButtonBarButton("New Order").ClickButton
DelphiScript
Aliases.browser.pageSample.objectOrders.ButtonBar('Bar').ButtonBarButton('New Order').ClickButton();
C++Script, C#Script
Aliases["browser"]["pageSample"]["objectOrders"]["ButtonBar"]("Bar")["ButtonBarButton"]("New Order")["ClickButton"]();
However, keep in mind that aliases must always precede the ObjectType(ObjectIdentifier)
notation in the object hierarchy. Aliases cannot be used after the ObjectType(ObjectIdentifier)
notation within the same statement. That is, the following statement is invalid:
JavaScript, JScript
Sys.Browser("iexplore").Page("https://services.smartbear.com/samples/testcomplete10/flex/").Object("orders").orders("orders").buttonbarBar.buttonNewOrder.ClickButton();
Python
Sys.Browser("iexplore").Page("https://services.smartbear.com/samples/testcomplete10/flex/").Object("orders").orders("orders").buttonbarBar.buttonNewOrder.ClickButton();
VBScript
Sys.Browser("iexplore").Page("https://services.smartbear.com/samples/testcomplete10/flex/").Object("orders").orders("orders").buttonbarBar.buttonNewOrder.ClickButton
DelphiScript
Sys.Browser('iexplore').Page('https://services.smartbear.com/samples/testcomplete10/flex/').Object('orders').orders('orders').buttonbarBar.buttonNewOrder.ClickButton();
C++Script, C#Script
Sys["Browser"]("iexplore")["Page"]("https://services.smartbear.com/samples/testcomplete10/flex/")["Object"]("orders")["orders"]("orders")["buttonbarBar"]["buttonNewOrder"]["ClickButton"]();
Further Reading
The following topics explain how to refer to objects in Flash and Flex applications while performing some common operations with them:
See Also
Testing Flash and Flex Applications
Testing Flash and Flex Applications - Overview
Support for Flash and Flex Applications' Controls
Accessing Native Properties and Methods of Flash and Flex Objects