Speeding Up Your Test Execution
Sauce AI for Test Authoring: Move from aim to performance in min.|xBack to ResourcesBlogPosted
Sauce AI for Test Authoring: Move from aim to performance in min.
|
x
Blog
Speeding Up Your Test Execution
Yi Min Yang reviews five thorough, field-tested hint to help your tests run quicker. These tips were originally presented during his session at Agile Testing Days 2020.
For the on-line version of Agile Testing Days 2020, I had the opportunity to do a talk. I prefer to talk about speeding up test execution; specifically, the five backsheesh I have hoard that will help you do merely that. Overall, these five tips tie together quite well, but can also be applied separately. In the course of researching and preparing this talk, I was surprised to discover a new finding on a widespread passport related to utilize XPath as a locator strategy for automated tryout.
Driver for faster tryout execution
Before we start talking about how to quicken up examination execution, we need to understand first why and what the driving movement behind this initiative is. For that, let & # x27; s take a look at the DevOps cycle.

Continuous Testing means that there are multiple different exam execute throughout the unharmed cycle. If we can pass the testing stages faster, QA and developers benefit from faster feedback. Overall, this will also cut clip to market.
Tip # 1 - Quit your driver
Various testing frameworks live in the market. Some frameworks might take tending of clean up resources on their own, but some others won ’ t. If a driver is not block after the test script has finished, the server will wait continuously for farther commands until it hits the idle timeout. The default is 90 seconds in the Sauce Labs Continuous Testing Cloud. As a result, not feature a elementary one-liner like in this image shown can cause each tryout script to run 90 seconds longer than it needs to.

This means as a writer of trial scripts, it is important to create certain that the driver quits under all circumstances. Fourth-year Solutions Architect Titus Fortner explains it in more particular in this videohere.
Tip # 2 - Avoid XPath
Using XPath as the locator strategy of option when pen test scripts is a common occurrence. It is easy to understand and allows you to aim all elements of a mobile app easily. There are two main reason why XPath should be deflect, however, and one of these reasons only applies when used with older Appium versions on senior OS version.
First understanding
XPath is ordinarily dim than other available locator strategies like Accessibility ID. The usual timing difference between XPath and others is around 200-500ms, although this depends heavily on the structure of the app. In more complex apps with multiple level deep bed, the timing to find ingredient will increase exponentially. Appium Desktop in version & gt; 1.18 can show the different clip needed to place an factor based on the used locator. As establish in this illustration the time needed to locate the Login button is 744ms, which is more than doubly as long as utilise Accessibility ID (350ms).

2nd reason
XPath contributes to flakiness and instability of the whole test retinue. XPath reflexion are used to traverse XML trees. This XML tree is based on the current state of the mobile app, which can change after an interaction and therefore requires recalculation and a new traversing through it (dense!). Using XPath too cause a sure mismatch between the expectation of the test creator and the actual state.
For model, the XPath for the choose component has the index of [1], which makes sentience because it is the initiatory component in this hierarchy.


The second ingredient in this list has an power of [2], so as a test Almighty I would note these expressions down and add them to my test script, expecting to choose the backpack and bike light.


But the reality is that when we experience selected the backpack, the XPath expression changes to something completely different as shown in the undermentioned image.

This makes sense so far, but when we take a look at the bike light we will see that it has changed.

The bike light now has the index of [1] and as such, the test lawsuit referring to the item with index [2] would choose the T-Shirt instead of the bike light—making the test script wrong.
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.
Tip # 2.5 - Use non-XPath locator for less maintenance
The generated XML tree for an Android app is different from the one generated for an iOS app, thence making it necessary to maintain two different sets of locators. Accessibility IDs are cross-compatible, making it possible to have a individual locator file for both Android and iOS. In addition, using Accessibility IDs is a best practice that will meliorate the accessibility of the app.
Tip # 3 - Use the latest Appium version
As I refer in the beginning as part of my preparation for my talk at Agile Testing Days 2020, I wanted to furnish code model showcasing how much obtuse XPath is compare to Accessibility ID. To my surprise, this wasn ’ t the case (anymore). Thinking that the difference in timing would not be outstanding enough to affect a speedy examination, I created some longer-running end-to-end tests mimicking a user journey through Sauce Labs Swag Labs app. There was no obtrusive difference. This prompted me to look for direction from Sauce Labs Senior Solution Architect Wim Selles. After some investigating, he distrust a change in Appium and iOS (I only concentre on iOS for this). Sure enough, after running both test handwriting, one utilize only XPath and the other one IDs, against respective combination of Appium and iOS versions it was clear there was a performance improvement.

Starting with Appium 1.16 and iOS 13, both Appium and Apple experience improved the speed importantly when employ XPath, making it a viable locator scheme if the lonesome KPI is speed.
This means it is improper to say XPath is ever slower, because under the right circumstances it is not. But it withal should be avoided wherever possible.
As note, the drawback of having to maintain two locator files because of incompatibility between Android and iOS XMLs, the underlying flakiness introduced and the positive side-effect of making one ’ s app more approachable when using Accessibility IDs get it a no-brainer to choose IDs over XPath.
Although it should be noted that develop an app for Android and iOS in two different technology stacks and follow the pattern + befool guidelines will leave in accessibility IDs being less compatible between both apps. The real value of accessibility IDs is not only in testing but sooner than they give real added value to visually handicapped end user.
Tip # 4 - Parallelize as much as possible
Parallelization allows us to run multiple tests at the like clip on multiple device instead of running everything consecutive. For the purpose of running tests early in the ontogeny pipeline/lifecycle, I recommend use practical devices. This means emulators (Android) and simulators (Apple) should be used instead of real devices. They are easygoing to set up and use, cheap, and will present quick results. On the early hand, real device should be used mainly later in the pipeline/lifecycle.

The table present the datum for scat the comparison XPath vs. ID. Overall there were ten configurations (Appium/iOS version), two tests (XPath/ID) leave in 20 trial executions in total. The average test executing comes down to 2m 18s. This solution in a total trial continuance of 46m when run sequentially.
If full parallelization is used the total examination continuance drop down to 2m and 18s—an improvement of more than 20x.
Tip # 5 - Reduce web requests
When testing an application in the cloud, every Appium dictation turn two web requests: one to get the element and the 2d one to act on it. Reducing the amount of web request will naturally decrease the test duration. Depending on the used framework, the model itself might cause a lot of unnecessary requests. This bloats tests up, causing simple examination to have hundreds or thousands of requests and responses.

The full amount of requests and responses for the create end-to-end test amounts to 36 event only, as there are no unneeded querying of elements. Most frameworks utilize implicit waiting, which intend that the fabric will look for elements to get useable. Appium is too using it as documentedhere. The use of an explicit wait as shown in the following figure is not take.

Instead the use of an unquestioning wait as constituent of the driver object can be habituate to simplify the wait strategy:

In cases where it is expect that an element might take longer than the timeout to lade an explicit wait makes sense.
Conclusion
As a companionship progresses through its automation journeying, it is important to do due diligence on tool and frameworks. This includes researching and comparing them with each early to try and discover the better ones based on each organization & # x27; s alone necessary.
The tips in this post should be easily implement into existing frameworks. But as with all optimizations, it is better to have a solid foundation before expend a significant amount of clip on optimize the last few percents.
This post has hopefully facilitate cut the amount of time you want to research test speed advance and aid you understand why test can be slow and how to better them.
Sr. Solution Engineer at Sauce Labs
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