Faster iOS Test Automation
https://www.google.com/url?sa=i&source=images&cd=&ved=2ahUKEwi25-uR-dzgAhVGT30KHecdCSAQjRx6BAgBEAU&url=https%3A%2F%2Ftwistedsifter.com%2Fvideos%2Fspeed-test-comparison-of-every-iphone-ever%2F&psig=AOvVaw2KKDxalM4KhwSEfVfHOlz-&ust=1551392316676562

Faster iOS Test Automation

Pinpointing the element for consuming in automated testing is one of the fundamental and puzzling responsibilities in test automation. There are numerous strategies for identifying the elements but when it comes to dynamic elements or elements without proper identifiers we mostly be influenced by XPath or CSS selector. If you have observed a delay in performance while using Appium ? for iOS App test automation then this article is for you.

XCUITest is the most commonly used driver for Appium ? in iOS App test automation. In this setting if XPath is used to recognise the elements then there would be an impact to the execution speediness. This is in contrast to the usage of other attributes like id, name and class or while using the same XPath in an Android device. 

The reason for delay is because XPath is not native language for iOS development. Actually to make XPath work in XCUITest driver the Appium ? team has squeezed things internally. It’s done in such a way that the hierarchy of app elements must be serialised into an xml by walking through the elements recursively. Then the XPath query would be executed on this xml and the list of matching elements must have to be de serialised. Logging of all these activities can be grasped in Appium ? console while using XPath for identifying the element. In short the delay would be supplementary for Apps with extra elements and slighter for Apps with lesser number of elements.

The Alternative options for XPath in iOS Apps are usage of predicate and class chain queries. Both these are applicable only for Appium ? and not applicable for Selenium. The good news is AppiumLibrary has started supporting both of them in their latest (1.5.3) version. I was able to completely replace the usage of XPath in my project with these queries and thereby better iOS execution speed.

Predicate Queries

This is natively supported by XCTest driver and hence this is an efficient and quick identifier for identify elements comparing to Class chain queries, which is mentioned below. Usage of the identifier in Robot Framework

nsp=type==` XCUIElementTypeButton`

This would find the element of type XCUIElementTypeButton. nsp is the name of the locator type which AppiumLibrary would understand and find element matches by iOSPredicate. Along with type other attributes can be logically concatenated refer Predicate-Queries-Construction-Rules.

Class Chain Queries

This is a layer over the native XCTest. Unlike predictive queries this query supports direct and indirect children search requests much similar to the XPath without impacting the execution time. Usage of the identifier in Robot Framework

chain=XCUIElementTypeWindow/XCUIElementTypeButton[3]

This is an example of direct children search request and this query would select the third child button of the first child window element. Chain is the name of the locator type which AppiumLibrary would understand and find element matches by iOSChainString. The same button can be found indirectly by using

chain=**/XCUIElementTypeButton[3]

In the above case **/ defines the next following item.

Instead of mentioning the index a predicate string can also be enclosed in that case the usage would be

chain=**/ XCUIElementTypeButton[`name BEGINSWITH “O”`]

As word of caution single quotes should be used inside the square brackets for predicate strings. Many more options are available to replace the XPath refer Class-Chain-Queries-Construction-Rules.

Reference:- iOS Predicate

要查看或添加评论,请登录

社区洞察

其他会员也浏览了