Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Jan 27, 2020 12:10

Introduction

When an automation script attempts to identify a particular UI Element in an iOS application, Perfecto scans the applications UI Object Tree and then identifies the element to interact with. Different iOS applications may include a View object (for example, a TableView) that has a large number of child UI elements, not all of which may be visible on the current application display. Parsing all children may take many minutes of processing (in one case parsing and building the search tree took almost an hour of processing time). This parsing operation negatively affects the script execution time and in extreme cases may cause a Perfecto  "Premature end of file" exception.
To overcome these situations, Perfecto now supports Object Tree Optimization commands, for native iOS applications, that instruct the system to limit the parsing of the UI Elements -
  • For XCUITest Devices - setting the maximum number of child UI elements retrieved for every element node, regardless if they are displayed or not.
  • For UIAutomation Devices - limiting to those elements that are visible on the current display and perform the Element identification on this limited Object Tree.


By performing this optimization:
  • Speedup the UI element identification.
  • Prevent script from failing due to a timeout of the element identification.

Object tree optimization - XCUITest Devices

XCUITest Specific Behavior Difference

Unlike UIAutomation, where the retrieved objects are constrained to the currently displayed elements, XCUITest optimizations only support setting the maximum number of child UI elements retrieved for every element node, regardless if they are displayed or not.

For example in case of a large TableView, the number of retrieved table cells will be counted from the first cell of the table regardless if it is visible or not; in practice this means that refreshing the Object Spy after scrolling down the page may not retrieve the currently displayed elements.

This behavior stems from the abilities provided by the XCUITest Framework, and, currently, there is no way for aligning the behavior to UIAutomation.

Object Spy Usage

To use objects optimization from the Perfecto Lab IDE:

  • Set the number of Max child elements per node in the Settings (under the More button), under the Automation tab (0 is the default value, meaning the feature is disabled):

  • For instrumented applications select the Appium Automation Framework.

    Note: Object Optimization does not affect instrumented applications when using the Perfecto Mobile Automation Framework. It will affect non-instrumented applications when using either of the Application Frameworks.

For example, if the value has been set to 3, then opening Object Spy for SpringBoard will result in a view similar to the following (each element at any level shows only, at most, 3 children):

Note: The Max child elements per node setting affects the execution of any Interactive (Manual) sessions.

Appium Script Usage

Applying Optimization for the Entire Execution

To apply the optimization for the entire execution, use the maxChildren capability during the IosDriver creation with the required maximum number of children elements per node:

capabilities.setCapability("maxChildren", 8);

Applying Optimization to a particular section of the Appium Test Script

To apply the Object Tree optimization to a particular section of the test script, use the following Perfecto commands:

  • mobile:objects.optimization:start - Starts objects optimization for any object tree operation, requires a parameter named "children".
  • mobile:objects.optimization:stop - Terminates the optimization. If the stop command is not added, optimization will continue until the end of the script.

Note: Using the stop command will turn off optimization entirely, regardless of the maxChildren value.

These commands are applied using the driver.executeScript() method.

Map<String, Object> pars = new HashMap<>();
pars.put("children", 8);
driver.executeScript("mobile:objects.optimization:start", pars);
//
// Add the script actions on the large display
//
Map<String, Object> pars2 = new HashMap<>();
driver.executeScript("mobile:objects.optimization:stop", pars2);

Native Automation Test Script Usage

To enable the optimization for a Native Automation test script, a new parameter has been added to the objects optimization start command named Max children per node (enable "Show Advanced Parameters" to show the parameter):

Setting the value to 0 is equivalent to using the objects optimization stop command.

The objects optimization stop command does not require any new parameters.

Object tree optimization - UIAutomation

When this optimization is in effect the script should only search for UI elements displayed on the screen, not elements that may be available by scrolling the display to show currently hidden UI elements.

This functionality may apply the object tree optimization to an entire test script or limit the optimization. This would allow the Perfecto Lab to be configured for limited for non-optimization, but to apply the optimization to a particular application screen.

Note: This functionality applies to automation test scripts for iOS applications on iOS 8 or later only. Applicable to UIAutomation devices only.

Applying optimization to application

To apply the Object tree optimization to the entire application, use the objectsOptimization capability during the IosDriver creation. A value of true, applies the optimization.

capabilities.setCapability("objectsOptimization", true);

Applying optimization to a particular section of Appium test script

To apply the Object Tree optimization to a particular section of the test script, use the following set of Perfecto commands:

  • mobile:objects.optimization:start - Starts ObjectSpy optimization for any object tree operations.
  • mobile:objects.optimization:stop - Terminates the optimization. If the stop command does not appear, optimization will continue until the end of the script.

These commands are applied using the driver.executeScript() method.

Map<String, Object> pars = new HashMap<>();
driver.executeScript("mobile:objects.optimization:start", pars);
//
// Add the script actions on the large display
//
driver.executeScript("mobile:objects.optimization:stop", pars);

Applying optimization to a section of Native Automation test script

The Object Tree optimization is supported for Perfecto Native Automation of iOS applications using the new commands:

  • objects.optimization start - Activate before searching for the element child of a large View object.
  • objects.optimization stop - Activate when completed with the large View object.

These commands do not require any parameters.

Special Notes

  • This feature only affects native apps or the native sub-trees of hybrid apps (essentially, not applicable to WebViews or children of WebViews)
  • Appium caching of object identifiers is suspended while the object optimization is in effect.
  • XCUITest Limitation: For a Scrollable View whose child elements are not all visible on the screen, even if the number of visible child elements is less than the Max children per node value, trying to scroll to an off-screen child element (even if it is within the Max children per node value) will fail.
  • Limitation: Object optimization does not affect instrumented hybrid applications when using the Perfecto Mobile Automation Framework