How to Speed Up Native Appium iOS Test Execution by Knowing How Appium Works
Sauce AI for Test Authoring: Move from intent to executing in minutes.|xBack to ResourcesBlogPosted
Sauce AI for Test Authoring: Move from intent to executing in minutes.
|
x
Blog
How to Speed Up Native Appium iOS Test Execution by Knowing How Appium Works
In this post, I ’ m going to explain how you can optimize your iOS mechanisation scripts for aboriginal apps—and speed up test execution time significantly—by first looking at how Appium works and secondly looking at different locator strategies. I ’ ll also let you in on a little secret!
Here are some of the almost mutual things I hear when I work with the open seed community:
Native apps are hard to automate.One of the reasons for this is that native iOS and Android apps are not equal. Not exclusively is the app source not adequate, but 9 out of 10 times, the way the apps behave isn ’ t the same either.
There are no cross platform selector.Right! I hear this commentary primarily from people who are used to automating with Selenium. I ’ ll speech more on this point after.
Appium exam are slow.Correct again! Appium tests can be 3-6 times slower than desktop.
Let ’ s explore why.
Automating Native Apps
A lot of people use their Selenium knowledge to automate aboriginal apps. I don ’ t think it ’ s a wrong approach, because if we seem at a antiphonal web app, we can almost always use the like script and selectors on background and mobile. They have the like source (the DOM), and are construe the like for every browser on desktop Chrome, Firefox, Safari, Internet Explorer, Microsoft Edge, but even on peregrine Safari and mobile Chrome.
However, I was not concern to web apps. I also see that a lot of people use their Selenium noesis onnativeapps and get into trouble. This mainly has to do with the app root of native apps, so let ’ s take a look at the native app source, the UI Hierarchy, for an iOS app. This can easily be visualized withAppium Desktop.
On the left you see the visualisation of the app and in the heart you see the UI hierarchy. This tree is not HTML, but XML, and as you can see—it ’ s a rattling orotund tree. The intellect for this is that all component can be establish in this tree, even the elements that you don ’ t see on your screen, such as the menu. This looks like the same behavior as we have witness with HTML.

Now let ’ s guide a look at Android.

Here you see the UI hierarchy that Appium sees, which is completely different in comparison to iOS. You don ’ t have HTML hither, but also an XML tree. What you might besides see is that Android will only give us back the ingredient that are show on the blind. This is, following to different element names, already a big difference between iOS and Android.
So iOS has all elements in the vista, but Android only the elements that are in the viewport. And as I mentioned sooner, people find it difficult to find a crisscross platform selector, which I can imagine with these different UI hierarchy. Do you now see why it ’ s harder to use your existing Selenium knowledge to interact with an iOS and Android app?
The No-XML Secret
As I state at the beginning of this post, I wanted to let you in on a little secret. Are you ready?
There is no XML. iOS and Android don ’ t have a UI hierarchy in XML.
Shocking, isn ’ t it? Well, I ’ m proceed to explicate it to you. Both iOS and Android employment with vista, and the views are translated by Appium to XML. Android furnish a useful dumpWindowHierarchy which give backward XML and make the translation from Views to XML pretty easy and pretty fasting.
Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.
XPATH and XML are not aboriginal lyric for iOS. Appium needs to perform some thaumaturgy with the app hierarchy. It must be recursively walked and serialized into XML. This by itself can occupy a lot of time, especially if your app has many elements. Then, once the XPath query has been run on this XML serialization, the leaning of matching elements must be deserialized into actual element objects before their WebDriver representations are returned to your customer vociferation. This translation is only do when we:
Ask for the root, like with Appium Desktop when we want to walk through the source of the app
Use an XPATH selector
This is one of the reasons that for example iOS is double as slow as Android when habituate XML. So how can we fix that?
Locator Strategy
That take us to something very important, the locator strategy.
Below is a inclination of locator strategies that you can use for aboriginal apps. It ’ s in my favorite order based on hurrying. You ’ ll tone XPATH is last, despite being used most often, and I ’ ll explain why.
accessibiltyID
An accessibility label in an iOS or Android app is a twine that will tell a screen reader what the function of an element on the screen is.
So why should you use accessibilityIDs? Well, there are numerous understanding, but the most significant ones are these:
They are already indexed, and that makes it much quicker than XPATH, because they are directly query on the views.
They are cross-platform. (So you now receive an answer on how to create a cross-platform locator scheme)
In some countries, you can even be fine if you don ’ t have them.
iOS predicate string
A different way of selecting elements can be done withiOS predicate string.
This is something that is already progress in XCUITEST and queries the attributes on an constituent like name, value, label, type and visible. One of the advantage of theiOS predicate stringis that it is really fast.
iOS stratum chain
But next to theiOS predicate twinethere is also a way of query some component from parent to child. This can be compared with XPATH, but XPATH is more powerful in this due to the fact that it can query element from child to parent. But as I said, this will trigger generate XML which makes discover elements take longer. So here you need to believe about a full proportion between costs and win.
className
This one is simple, it ’ s only the form name, but with so many elements you might ask yourself if this will give you a unique element.
XPATH
XPATH, although it tends to be everybody ’ s favorite, is brickle and slow. I think, based on the points above, you can already draw your own determination why.
Finally, by now you should know that both iOS and Android don ’ t work with XML and each time you use XPATH, Appium first needs to read the UI-view into XML which lead time. Android is faster than iOS simply because it doesn ’ t render all elements, only the element in the position. Thus regardless of platform, using XPATH leads to slower tests.
If you ’ d like to see the existent number and comparison of all these locator strategies check out my Tech Talk:How to speed up your native Appium iOS tests by almost 50 %, where I demo of each one of these on a sample app. Happy examination!
Staff Product Manager at Sauce Labs
Topics
Share this post
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free