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

Last updated: Jun 28, 2018 23:49

Problem

Observance of varying levels of object retrieval via XCUITest framework to address slow performance

Solution

In this article we'll review various ways of retrieving objects from an application through XCUITest and their impacts on response time.


As many of you may know with the launch of XCUITest came a hit to performance of retrieving objects from iOS applications.

We have recently launched the ability to limit the number of recursive children pulled from the object tree through Optimization which greatly reduces the time it takes to pull objects from iOS applications. Although this is a great addition to our toolset it also requires you to manually verify just how deep you need the children to be pulled prior to running your find element command.


We have also been recommending to use the newly introduced Class Chaining as a means of retrieving objects instead of xPath. Class Chaining through Appium has built in optimization which reduces the amount of time to pull objects from iOS applications. What is nice with this implementation is it doesn't require you to first analyze the object tree for the depth of children and still provides a great reduction in execution time.


Below we'll take a look at the differences between xPath with and without optimization and Class Chaining with and without optimization. If you decide to spend the time with Optimization you'll find in either case its greatly reduce response time however Class Chaining provides a means of object lookup with reduced execution time out of the box.


Xpath

  • Using xPath to locate user id field without optimization
    • 3 minutes and 20 seconds to find the User id field
    • //*[@value="User ID" and @visible="true"]
  • Using xPath to locate user id field with optimization set to child level 4
    • Only 6 seconds to find the User id field
    • //*[@value="User ID" and @visible="true"]
    • Code used below


                     Map<String, Object> pars = new HashMap<>();

                     pars.put("children", 4);

                     driver.executeScript("mobile:objects.optimization:start", pars);


                     WebElement we2 = driver.findElementByXPath("//*[@value=\"User ID\" and @visible=\"true\"]");


                     we2.click();

                     we2.sendKeys("test");


                     Map<String, Object> pars2 = new HashMap<>();

                     driver.executeScript("mobile:objects.optimization:stop", pars2);


Class Chaining

  • Using class chaining to locate user id field without optimization
    • Only 10s to find the user id field
    • **/XCUIElementTypeTextField[$name =="UserId" and visible==1$]
  • Using class chaining to locate user id field with optimization set to child level 4
    • Only 1 second to find the user id field
    • **/XCUIElementTypeTextField[$name =="UserId" and visible==1$]
    • Code used below


Map<String, Object> pars = new HashMap<>();

                     pars.put("children", 4);

                     driver.executeScript("mobile:objects.optimization:start", pars);


                     WebElement we =

                     driver.findElementByIosClassChain("**/XCUIElementTypeTextField[$name ==\"UserId\" and visible==1$]");

                     we.click();

                     we.sendKeys("test");


                     Map<String, Object> pars2 = new HashMap<>();

                     driver.executeScript("mobile:objects.optimization:stop", pars2);

Testing Class Chaining


At this moment Object Spy has yet to support Class Chaining however you do have options to ensure the syntax is sound and an object was found via the query you wrote.

First find the Application.Find command under functions in either your cloud or your IDE plugin

 



Make sure execute on add is selected and Class Chain is selected in By parameter then add your Class Chain query to Element Identifier

If you don’t receive an error when you click OK then your syntax was successful and an object was found. If syntax is wrong or an object was not found you’ll receive the below

Finally if you want to test your query and see if it controls the correct object you can use the Application.Click command using the same process as Application.Find to see if your app responds appropriately