Share this page

# Access native objects, methods, and properties

This topic describes interacting with an object in your application using its native methods and properties.

In this topic:

## Introduction

If the test object methods and properties available for a particular test object do not provide the functionality you need, you can access the native methods and properties of the run-time object in your application using the relevant property/method/function for your programming language.

For example, suppose you have a Web edit test object defined in your test called searchBox. You could access the native (run-time) search box object, and then use the native isDisabled property to make sure your search box has the expected state.

Programming language |
--- | ---
C# | Use the NativeObject property Example: `var searchBoxRunTimeObject = searchBox.NativeObject;` `Verify.IsTrue(searchBoxRunTimeObject.isDisabled);` When you use the NativeObject property in C#, it returns a dynamic object. You can then directly access the native methods and properties of that object.
Java | Use the getNativeObject method. Example: `NativeObject searchBoxRunTimeObject = searchBox.getNativeObject(); Verify.isTrue(searchBoxRunTimeObject.GetProperty("isDisabled", Boolean.class);` When you use the getNativeObject property in Java, it returns an instance of a `NativeObject` interface. You can use the methods of the NativeObject interface to access the native methods and properties of that object. For details on the available NativeObject methods, see NativeObject in the OpenText Functional Testing for Developers Java SDK Reference.
JavaScript | Use the nativeObject function. Example: `searchBox.nativeObject().then(function(nativeSearchBox) { expect(nativeSearchBox.isDisabled).toBeTruthy(); });` The nativeObject function returns a promise that will be resolved with the instance of the native object represented by the searchBox test object. To access native properties\methods of the native object, use them in the appropriate syntax. Note that all methods and properties of the native object in JavaScript return promises that will be resolved with the result of the operation. In this example, expect is used. For more details about expect, see Validate values.

IntelliSense is not available for NativeObjects, but you can query your object for the list of available methods and properties, as described below.

Additionally, make sure you are aware of these Considerations .

Back to top

## Query an object to find the available methods and properties

The OpenText Functional Testing for Developers SDK provides the ability to retrieve the list of available native methods and properties for any object.

Programming language | Instructions
--- | ---
C# | Use the NativeObject.MEMBERS property. Note that like other NativeObject properties, the MEMBERS property is not available in the IntelliSense. Example: `var ServicesLink = browser.Describe<ILink>(new LinkDescription { TagName = @"A", InnerText = @"Services " }); var nativeLink = ServicesLink.NativeObject; string[] linkMembers = nativeLink.MEMBERS;`
Java | The getNativeObject() method returns an instance of the NativeObject interface. The NativeObject interface has a getMembers() method. Example: `Link servicesLink = browser.describe(Link.class, new LinkDescription.Builder() .tagName("A").innerText("Services ").build()); NativeObject nativeLink = servicesLink.getNativeObject(); List<String> LinkMembers = nativeLink.getMembers();`
JavaScript | Use the MEMBERS() function on the native object instance. This function returns a promise that is fulfilled with an array of strings of the available members. Example: `servicesLink.nativeObject().then(function(nativeLink) { nativeLink.MEMBERS().then(function(members) { var linkMembers = members; //do something with list - for eg: check value using the debugger }); });`

Both C# and Java return a string collection of the available members. You can write the list to a file or use the Locals or Watch debug panes to view the returned list.

In the returned list, each method has a () suffix. In some technologies and browsers, the full syntax of methods is displayed and read-only (get) properties have a [ReadOnly] suffix.

Back to top

## Considerations

- Test compilation. The native operation names and argument syntax are not validated when the test is compiled.
- Supported technologies. NativeObject support is not available for the Standard Windows and Mobile technologies.
- Code reliability. Keep in mind that NativeObject gives you access to the actual object in your application. It is your responsibility to make sure that methods and properties you perform on the object are safe and reliable, and that any objects opened or created using native methods and properties are handled by your code. For example, if you raise a message box using a native operation, you may have to close it manually or using native object code before the test can continue to perform steps on your application.
- C# Enumerations. If a NativeObject operation returns an enumeration, use ToString() to return the enum's value.

- Indexers and JavaScript arrays. If you return a C# (Windows Forms or WPF) native object that has an indexer, you can access the indexer value just as you would with the object itself. The same is true for JavaScript arrays in Web applications.

  For example:

        var arr = webElement.NativeObject.array;
        Assert.NotNull(arr);

        arr[1] = 100;
        arrValue = arr[0];

  You can also work with multidimensional indexers:

  - If you are using the .NET SDK, you can reference it as you would any multidimensional indexer. For example: `myNativeObject[1,2]`

  - To retrieve or set a multidimensional indexer using the Java SDK, use the NativeObject getItem and setItem methods and supply the array of indexes you want to retrieve or set.

- JavaScript SDK syntax. Any operation of the native object is an asynchronic operation even if it looks like a normal assignment.

  For example:

      edit.nativeObject().then(function(e) {
          expect(e.value).toEqual("AAA");
          e.value = "BBB";
          expect(e.value).toEqual("BBB");
      });

  In this case, value is a property of the native object, and assigning a value to it invokes the get method of the property, which in this case is an asynchronic operation.

  Synchronization of such methods occurs the same way as synchronization of operations on the test object, meaning that each operation on the native object is performed only after the previous operation is completed.

  Note that just as accessing a non-existing key on a JavaScript object does not fail, accessing a non-existing property of the native object does not fail either. This is unlike C# (or Java) where, in such a case, the object is expected to fail.

  For example, the operation:

  nativeObject.nonExsitingKey = 8;

  creates a new key for nativeObject called nonExsitingKey, and sets its value to 8, while in C# (or Java) such an operation is expected to fail.

- Web. When you use the NativeObject property on a Web-based object, you get a reference to the DOM object, meaning all methods and properties that can be performed on the DOM object are available. However, keep in mind that many DOM methods and properties are browser-specific and such could affect the cross-browser viability of your test.
- SAP GUI for Windows. The NativeObject returned for a SAP.GUI object gives access to the native methods and properties of the SAP Scripting API. For more information on these methods and properties, refer to your SAP Scripting API documentation.
- .NET Windows Forms. If a native method's return value or a native property's value is a structure, a string value representing the structure is returned.

Back to top

See also:

- .NET SDK Reference
- Java SDK Reference
- JavaScript SDK Reference

https://admhelp.microfocus.com Functional Testing for Developers 8942
Tips to improve your search results... OpenText™ Functional Testing for Developers Help Center OpenText™ Functional Testing for Developers Help 25.2 All View Local Help Center View Online Help Center Version: