Last updated: Jun 22, 2020 11:30
By Eynav Cohen and Jacob Komarovsky
With the introduction of iOS 10, Apple has deprecated its legacy UI Automation framework and instructed all developers to start using the XCUITest framework, introduced in iOS 9. Perfecto’s automation solution so far relied on the UI Automation framework for extracting the native object tree.
Perfecto now supports automation for iOS devices based on the XCUITest framework. While using the XCUITest-based infrastructure is optional for iOS 10, it is mandatory to ensure support for iOS 11, which to date does no longer includes support for UI automation.
The XCUITest-based infrastructure is integrated with the latest Appium 1.6 server software, which allows your Appium automation scripts to take advantage of the following benefits:
- XCUITest's enhanced performance.
- Automating new iOS functionality, like 3D Touch or Siri injection.
- Provide the latest function updates from Appium IosDriver classes.
Enabling the XCUITest-based automation infrastructure does not affect current automation scripts or general behavior. The current UI Automation-based ios automation infrastructure continues to work seamlessly with the new infrastructure enabled.
iOS 10: The infrastructure is available for Appium and Quantum users. In future releases, Perfecto will also enable the XCUITest-based infrastructure for manual testing support, native automation, UFT, and other automation frameworks.
iOS 11: Full automation support across all frameworks: Appium, Quantum, UFT, native automation, interactive an more.
The XCUITest-based infrastructure is supported on the following Apple models running iOS 10 or later:
- iPhone 7 Plus
- iPhone 7
- iPhone 6s Plus
- iPhone 6s
- iPhone SE
- iPhone 6 Plus
- iPhone 6
- iPhone 5s
- iPad Pro
- iPad Air 2
- iPad Air
- iPad mini 4
- iPad mini 3
- iPad mini 2
Other devices, or any device running iOS 9 and below should continue to be automated using the UI automation based infrastructure.
How to use the XCUITest-based infrastructure
To prepare your Perfecto Lab and automation scripts to use the new automation infrastructure, you need to perform a few simple procedures:
- Enable the infrastructure on your Perfecto Lab.
- Add the relevant capability to your Appium scripts to use the XCUITest infrastructure.
- Adjust your object locators.
- Verify that your script does not use any deprecated commands or methods.
The following sections detail these procedures.
Enable the XCUITest-based infrastructure on your Perfecto Lab
Contact your CSM or Perfecto Support to request that the XCUITest-based automation infrastructure be enabled for your CQ Lab.
Changes to Appium Scripts
The migration to the XCUITest-based automation infrastructure requires some adaptations in existing Appium scripts. These are detailed in the sections below.
Select the XCUITest-based automation infrastructure
Use the automationName capability with the value XCUITest to indicate the XCUITest framework as the target automation infrastrcture.
Adjust Object Locators
Apple's XCUITest framework introduced several changes to the object tree of native applications which may require changes in some XPath locators. The highlights of the changes include:
- Xpath locators with XCUITest infrastructure framework support Xpath 1.0
- Change of object class names: The UIA prefix of the UI element class names are replaced by a XCUIElementType prefix. For example, the Button element whose class-name is UIAButton in UIAutomation is identified as class XCUIElementTypeButton in the XCUITest framework. See Translation table below.
- Introduction of the XCUIElementTypeOther class: This class is a container object introduced at various points in the Object Tree.
- Changes to the Object Tree structure: Some objects may be mapped inside new containers that did not exist in the UI Automation tree, and some containers exposed in the UI Automation based tree may no longer be exposed in the XCUITest framework.
Sample UI Object tree in different frameworks
The following shows a partial object tree for the status bar of an application. On the left is the UIAutomation tree, on the right the same tree in XCUITest.
Tips & Tools for XPath Locators
Since the transition to the XCUITest-based infrastructure requires some effort in identifying object identifiers that need to change, Perfecto is providing several tips and tools to ease this task:
- Create strong XPath locators by following the Do's and Dont's.
→ Strong locators are unique and easier to maintain across environments. These kind of XPath locators will match an an element on both UIAutomation-based Appium scripts and XCUItest-based Appium scripts in 95%.
- Refrain from using XPaths that explicitly traverse the object tree.
→ Due to the restructuring of the object tree these locators are most likely to fail with XCUITest-based automation script.
- It is recommended to verify that the XCUITest class names are used for the UI Elements. See table of translations below.
→ Perfecto added an auto translation mechanism from basic UI Automation locators to XCUITest locators which allows existing strong locators to work with the XCUITest-based infrastructure. For example, the XPath: //UIAButton[contains(@label, '9')] will be automatically translated to //XCUIElementTypeButton[contains(@label, '9')]
→ The translation mechanism also automatically translates the @class field used with UI automation to @type used with XCUITest. For example, the XPath:
//*[@class='XCUITestElementTypeButton'] will be auto-translated to //*[@type='XCUIElementTypeButton']
→ The mechanism currently does not work well with compound expressions (when 'and' or 'or' operators are used)
→ The mechanism will not help when an explicit XPath traversing through the tree structure is used, due to the different layout of the element tree.
- Use this online tool to validate XPath locators in general and specifically for the XCUITest-based infrastructure to check the strength of your XPath locators and their compliance with XCUITest UI Element specifiers.
- Try the Analyser to extract all locators from a given test code and validate them or XCUITest-based object tree locators.
- If an XPath locator still fails after the required modification; use the Appium driver.getPageSource() method to retrieve the object tree from Appium, then
- Print the tree or save to a file to analyze how the object is identified within the script execution.
- Update the XPath that the script uses to access the object.
- Rerun the automation script to verify that the object is now identified.
- Professional Services: In case the transition seems daunting or customers would like advice or guidance, please contact our customer success managers to coordinate relevant activity.
Element Type Translation Table
The following table presents the equivalences between the UIAutomation object class names and the XCUIElementType classes.
The Perfecto Git repository includes different sample scripts that use the XCUITest-based automation infrastructure to automate different applications on devices running iOS 10 or later.
The following code snippet demonstrates the use of the XCUITest-based infrastructure to identify an iOS PickerWheel object and provide a value for the picker:
Deprecated Appium methods and classes
Perfecto's XCUITest-based infrastructure is integrated with version 1.6 of Appium. In this server version, Appium has depreciated several methods and APIs.
Appium automation scripts with XCUITest enabled should adjust these automation scripts according to following Appium APIs changes:
Deprecation of scrollTo and scrollToExact methods.
→ use the executeScript("mobile: scroll") script command instead.
- Deprecation of AppiumDriver touch methods - tap, swipe, zoom, pinch, and getMouse
→ Use Appium TouchAction or MultiTouchAction, or Perfecto Touch Extensions
findElement using IosUIAutomation not supported – includes findElementByIosUIAutomation() method and driver.findElement(MobileBy.IosUIAutomation(""))
API changes & Known Limitations
Working with Perfecto framework and XCUITest:
Following the transition to the XCUITest-based infrastructure, Perfecto will no longer maintain two different object trees: Appium tree and Perfecto tree (both trees are based on Apple’s deprecated UIAutomation framework).
Any device using XCUITest framework will only be able to retrieve an Appium tree.
There are some differences between Perfecto’s tree and XCUITest’s tree. These differences stem from changes introduced by Apple's automation framework.
In order to maintain backward compatibility, Perfecto backward compatible as much as possible, added a mechanism to translate Perfecto-compatible XPath expressions to XCUITest-compatible ones.
This mechanism translates an XPath capable of locating a certain object in Perfecto’s tree to an XPath that locates the same object in XCUITest’s tree.
However, this mechanism cannot ensure a 100% rate of success. ‘Strong’/’Smart’ XPath expressions should have no issues while ‘weak’ expressions might fail.
The major differences between the two frameworks (and object trees) are:
- Class type names have changes. For example, ‘button’ -> ‘XCUIElementTypeButton’.
- There is no @text attribute so it should not be used to create object locators.
- Using text() function may fail as objects in XCUITest framework don’t have a text node value.
- The values of @x, @y, @width, @height attributes might be different and should not be relied on when constructing an XPath locator.
- Absolute XPath expressions (and sometimes relative ones as well) will most likely fail because in XCUITest framework there are container objects of type ‘XCUIElementTypeOther’ added at various point to the objects tree by the OS.
Better alignment with Appium API:
As part of the effort to better align with Appium APIs, the following Perfecto extended functions are no longer supported. Scripts will throw an exception with the message: the command is not supported with capability automationName - XCUITest.
Please use a compatible Appium method instead:
- Cookie functions: Add Cookie, Delete Cookie, Get Cookie
→ use driver.manage().[getCookies|addCookie] instead
→ use driver.rotate(<orientation>);
- Type text
→ for specific objects with text editing ability use WebElement sendKeys() command
- Touch actions - drag, trackball
→ use Appium TouchActions commands
Note: The above is ONLY applicable to iOS automation, and ONLY to scripts running on the XCUITest-based automation infrastructure. Android scripts or scripts running on the UI Automation based infrastructure are NOT affected.
Improvements over current level of Appium API support
Appium has declared a list of known Issues with some APIs when used with the XCUITest framework.
→ Methods: Perfecto's Appium solution supports the APIs on the list - except for the shake command - in order to minimise the required modifications for Appium XCUITest scripts.
→ Capabilities :Auto accepting/dismissing alerts funcinlaty is missing with Appium XCUITest driver (see #issue 6864)
Use the following methods in run-time instead:
APIs under development
As part of Perfecto's support of the XCUITest framework, the following features are not fully supported as they are under development and will become available in future releases:
- The following Appium classes and methods are not supported:
io.appium.java_client.FindsByIosNSPredicate class(supported in V10.7) io.appium.java_client.MobileBy.ByIosNsPredicate class(supported in V10.7) io.appium.java_client.pagefactory.iOSXCUITFindBy annotation(supported in V10.7)
- io.appium.java_client.ios.IOSTouchAction#doubleTap(WebElement, int, int)
- The following Desired Capabilities are currently not supported
fullReset(supported in V10.8)
- Capabilities defined as part of the IOSMobileCapabilityType class: