Using Namespaces

Applies to TestComplete 15.45, last modified on December 01, 2022

When you are testing an Open Application, namespaces let you access native object properties and methods that have the same name as some property or method added by TestComplete. For example:

  • webObj.Click(x, y) - The Click method added by TestComplete.

  • webObj.NativeWebObject.click() - the native click method of web page elements. This method is accessed via the NativeWebObject namespace.

TestComplete uses different namespaces for different application types.

Namespaces for Desktop Applications

Namespace Application or Object Type
NativeClrObject .NET and WPF applications
NativeCPPObject Visual C++ applications
NativeDelphiObject Delphi and C++Builder applications
NativeVBObject Visual Basic 6 applications
NativeJavaObject Java applications
NativeJavaFXObject JavaFX applications
NativeQtObject Qt applications
NativeMSAA Objects identified by the MSAA engine
NativeUIAObject Objects identified by the Microsoft UI Automation engine
NativeTextObject Objects identified by the Text Recognition engine

The following example shows the difference between the TestComplete Name property and the native Name property in the .NET Orders sample:

JavaScript, JScript

function Test()
{
  var wnd = Sys.Process("Orders").WinFormsObject("MainForm");

  Log.Message(wnd.Name); // WinFormsObject("MainForm")
  Log.Message(wnd.NativeClrObject.Name); // MainForm
}

Python

def Test():
  wnd = Sys.Process("Orders").WinFormsObject("MainForm")

  Log.Message(wnd.Name) # WinFormsObject("MainForm")
  Log.Message(wnd.NativeClrObject.Name) # MainForm

VBScript

Sub Test
  Dim wnd
  Set wnd = Sys.Process("Orders").WinFormsObject("MainForm")

  Log.Message wnd.Name ' WinFormsObject("MainForm")
  Log.Message wnd.NativeClrObject.Name ' MainForm
End Sub

DelphiScript

procedure Test;
var wnd;
begin
  wnd := Sys.Process('Orders').WinFormsObject('MainForm');

  Log.Message(wnd.Name); // WinFormsObject('MainForm')
  Log.Message(wnd.NativeClrObject.Name); // MainForm
end;

C++Script, C#Script

function Test()
{
  var wnd = Sys["Process"]("Orders")["WinFormsObject"]("MainForm");

  Log["Message"](wnd["Name"]); // ["WinFormsObject"]("MainForm")
  Log["Message"](wnd["NativeClrObject"]["Name"]); // MainForm
}

Namespaces for Web Applications

Namespace Browser or Application Type
NativeWebObject Edge, Internet Explorer or WebBrowser control
NativeFirefoxObject Firefox
NativeChromeObject Chrome
NativeSlObject Silverlight
Note: In Flash and Flex applications, all native properties and methods are available through the FlexObject namespace. For more information, see Accessing Native Properties and Methods of Flash and Flex Objects.

The following example presses a button on a web page in Internet Explorer using the native click method.

JavaScript, JScript

function Test()
{
  var url, page;

  url = "https://services.smartbear.com/Samples/TestComplete15/WebOrders/Login.aspx";
  Browsers.Item(btIExplorer).Run(url);
  page = Sys.Browser().Page(url);

  page.FindChildByXPath("//input[@type='text']").SetText("Tester");
  page.FindChildByXPath("//input[@type='password']").SetText("test");

  // Press the "Login" button using the native click() method
  page.FindChildByXPath("//input[@type='submit']").NativeWebObject.click();
}

Python

def Test():
  url = "http://services.smartbear.com/Samples/TestComplete14/WebOrders/Login.aspx"
  Browsers.Item[btIExplorer].Run(url)
  page = Sys.Browser().Page(url)

  page.FindChildByXPath("//input[@type='text']").SetText("Tester")
  page.FindChildByXPath("//input[@type='password']").SetText("test")

  # Press the "Login" button using the native click() method
  page.FindChildByXPath("//input[@type='submit']").NativeWebObject.click()

VBScript

Sub Test
  Dim url, page

  url = "https://services.smartbear.com/Samples/TestComplete15/WebOrders/Login.aspx"
  Browsers.Item(btIExplorer).Run url
  Set page = Sys.Browser.Page(url)

  page.FindChildByXPath("//input[@type='text']").SetText "Tester"
  page.FindChildByXPath("//input[@type='password']").SetText "test"

  ' Press the "Login" button using the native click() method
  page.FindChildByXPath("//input[@type='submit']").NativeWebObject.click
End Sub

DelphiScript

procedure Test;
var url, page;
begin
  url := 'https://services.smartbear.com/Samples/TestComplete15/WebOrders/Login.aspx';
  Browsers.Item(btIExplorer).Run(url);
  page := Sys.Browser.Page(url);

  page.FindChildByXPath('//input[@type="text"]').SetText('Tester');
  page.FindChildByXPath('//input[@type="password"]').SetText('test');

  // Press the "Login" button using the native click() method
  page.FindChildByXPath('//input[@type="submit"]').NativeWebObject.click;
end;

C++Script, C#Script

function Test()
{
  var url = "https://services.smartbear.com/Samples/TestComplete15/WebOrders/Login.aspx";
  Browsers["Item"](btIExplorer)["Run"](url);
  var page = Sys["Browser"]()["Page"](url);

  page["FindChildByXPath"]("//input[@type='text']")["SetText"]("Tester");
  page["FindChildByXPath"]("//input[@type='password']")["SetText"]("test");

  // Press the "Login" button using the native click() method
  page["FindChildByXPath"]("//input[@type='submit']")["NativeWebObject"]["click"]();
}

Namespaces for Mobile Applications

Namespace Application Type
iOSView iOS applications
Java Android applications
NativeXFObject Xamarin.Forms applications

The example below demonstrates how to use the native Enabled property of a button in an iOS application:

JavaScript, JScript

function Test()
{

  var p, myBtn;

  // Select the mobile device
  Mobile.SetCurrent("IPhone");
  // Obtain the Button object
  p = Mobile.Device().Process("SampleApp");
  myBtn = p.Window().Button(0);
  
  // Touch the button if it is enabled
  if (myBtn.iOSView.Enabled)
    myBtn.Touch();
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("IPhone")
  # Obtain the Button object 
  p = Mobile.Device().Process("SampleApp")
  myBtn = p.Window().Button(0)
  
  # Touch the button if it is enabled
  if myBtn.iOSView.Enabled:
    myBtn.Touch()

VBScript

Sub Test()
  Dim p, myBtn
  ' Select the mobile device
  Mobile.SetCurrent("IPhone")
  ' Obtain the Button object
  Set p = Mobile.Device.Process("SampleApp")
  Set myBtn = p.Window.Button(0)
  
  ' Touch the button if it is enabled
  If myBtn.iOSView.Enabled Then 
    myBtn.Touch
  End If 
End Sub

DelphiScript

function Test();
var
  p, myBtn;
begin
  // Select the mobile device
  Mobile.SetCurrent('IPhone');
  // Obtain the Button object
  p := Mobile.Device.Process('SampleApp');
  myBtn := p.Window.Button(0);
  
  // Touch the button if it is enabled
  If myBtn.Enabled Then 
    myBtn.Touch;
end;

C++Script, C#Script

function Test()
{
  // Select the mobile device
  Mobile["SetCurrent"]("IPhone");
  // Obtain the Button object
  var p = Mobile["Device"].Process("SampleApp");
  var myBtn = p["Window"]()["Button"](0);
  
  // Touch the button if it is enabled
  if (myBtn["iOSView"].Enabled)
    myBtn["Touch"]();
}

See Also

About Open Applications

Highlight search results