Conquering Mobile Test Automation's Locator & Visibility Challenges
Conquering Mobile Test Automation 's Locator & amp; Visibility Challenges Mauro Mackinze August 22, 2024
Conquering Mobile Test Automation 's Locator & amp; Visibility Challenges
Transitioning from web to mobile testing? You 're not alone. Many seasoned web automation expert find themselves wrestling with challenge unique to mobile apps–challenges that don ’ t always employ on the web:
- The elusive nature of ingredient in peregrine apps, oftentimes because attributes are missing or misuse
- The `` visible view '' restraint, where you only experience access to the source codification of what 's currently on the screen
Here, we aim to shed light on these challenges, specifically as they pertain to web mechanisation teams transitioning to mobile. We 'll also explore how mabl ’ s built-in tool are designed to harness these very matter.
Web DOM and the Mobile Equivalent
Web DOM Explained
The Document Object Model (DOM) is a tree-like representation of a web page 's structure, where each element on the page is a node in the tree. The DOM is essential for automation because it provides a map for test scripts to pinpoint and interact with specific constituent.
Let 's take a looking at a simple HTML code snippet and its like DOM:
The Mobile `` Page Source ''
Mobile apps do n't receive a traditional DOM. Instead, they feature what 's usually referred to as the `` view hierarchy '' or `` page source '' (which is Appium ’ s specific interpretation of the nomadic device 's accessibility layer). This correspond the construction of the screen you ’ re screening, similar to the DOM. Take a expression at this comparison of a web page 's DOM and a mobile app 's Appium page source:
While both layout a representation of the structural constituent on a blind, there 's a crucial distinction to keep in mind. The web 's DOM offers a comprehensive blueprint of the entire webpage, yet elements that aren ’ t in aspect. In contrast, Appium 's `` Page Source '' provides a snapshot specific to what is seeable on the mobile app 's blind. It ’ s akin to comparing a detailed architectural plan of a building to a exposure of a single room within that building. This inherent difference underscores one of the key challenges in wandering mechanization: the want to navigate and interact with component that might initially be off-screen.
Element Locators: The Backbone of Test Automation
As the identifiers that allow your scripts to find and interact with specific factor on the blind, locators are the linchpins of scripted trial automation. The way they prove up, withal, isn ’ t always the like.
Web Element Locators: A Bounty of Locator Riches
In web mechanisation, there is no shortage of attributes at your disposal: IDs, classes, names, CSS selectors, and even XPaths. When you inspect a page with DevTools you can see easily see the source codification for a page and find an element ’ s tag, classes, attributes, contents, parent, and children:
When it comes time to depart writing test codification either in Selenium or Playwright so that you can interact with those element, the locators are how you will be capable to target them in your code:// Selenium - Find element by ID
WebElement element = driver.findElement (By.id (`` myElementId ''));
// Playwright - Find element by CSS picker
const element = await page.locator ('.myElementClass ');
Mobile Element attributes: The Scarcity
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.
For many reasons, mobile apps often lack the rich multifariousness of attributes you can encounter in web Page. Accessibility IDs are think to function a similar purpose, but they 're often missing, misused, or only unreliable.
For example, hither ’ s a conceptual representative of an Appium Page Source snippet:
& lt; android.widget.Button & nbsp;The & nbsp;content-descattribute (symbolize Accessibility ID on Android) is empty, create it hard to uniquely identify this button in machine-controlled test. If another push on the same screen had the same resource-id or text value, it would create ambiguity for mechanization scripts swear on these locators.
& nbsp; & nbsp; text= '' Login ''
& nbsp; & nbsp; resource-id= '' com.example.app: id/login_button ''
& nbsp; & nbsp;
& nbsp; & nbsp; package= '' com.example.app ''
& nbsp; & nbsp; content-desc= '' '' & nbsp;
& nbsp; & nbsp; checkable= '' false ''
& nbsp; & nbsp; checked= '' false ''
& nbsp; & nbsp; clickable= '' true ''
& nbsp; & nbsp; enabled= '' true ''
& nbsp; & nbsp; focusable= '' true ''
& nbsp; & nbsp; focused= '' mistaken ''
& nbsp; & nbsp; scrollable= '' false ''
& nbsp; & nbsp; long-clickable= '' false ''
& nbsp; & nbsp; password= '' false ''
& nbsp; & nbsp; selected= '' mistaken ''
& nbsp; & nbsp; x= '' 144 ''
& nbsp; & nbsp; y= '' 528 ''
& nbsp; & nbsp; width= '' 144 ''
& nbsp; & nbsp; height= '' 48 ''
& nbsp; & nbsp; bounds= '' [144,528] [288,576] ''
& nbsp; & nbsp; displayed= '' true ''
/>
Yet, when is arrive to writing test code in Appium, you must find and determine on which element attributes to use in your code (as shew below):
// Appium - Find constituent by Accessibility ID (with potential pitfalls)
const constituent = driver. $ (`` ~elementId '');
Why Mobile Test Automation is Harder
Delicate Locators
As find in the examples above, web tests often rely on a encompassing range of attributes to pinpoint elements, while mobile tests are usually working with a scarce set of options. This scarcity means that yet minor UI changes can disrupt tests, which requires more frequent update and potentially slows down the examination procedure.
The Visible View Challenge
When setting up automation tests for the web, the entire DOM is available for inspection. Mobile automation testing, yet, is limited to the `` visible view '' –you can only see the source code for the element that are currently display on the blind. Because of this, mobile automation front a major obstacle: scrolling, as many elements in nomadic apps are only revealed after moving down the page.
Traditional scrolling methods in automation tools aren ’ t the well-nigh reliable, and finding elements that appear during the scroll is even trickier.
- Appium Scrolling Strategies: Appium proffer several scrolling methods (scrollTo, scrollToExact, scrollIntoView, swipe, mobile: gyre) with varying levels of tractableness and control.
- Perfecto Swiping Techniques: Perfecto provides techniques like swipe, swipeTo, and visualSwipe, the latter being particularly useful when text-based locators are unreliable.
mabl 's Solution: Intelligent Find & amp; Scroll-to-Element
mabl 's nomadic app screen solution is plan to overwhelm the unique challenges of wandering automation by updating how we find locators and expanding our view.
Beyond Basic Locators
mabl does n't swear solely on single attributes. Instead, our Intelligent Find feature captures multiple attribute for each constituent you interact with, creating a more robust and reliable identification mechanics. This means your tests are less likely to break due to UI and content changes, while also simplifying tryout creation, since you do n't need to worry about take the `` perfect '' locator.
Conquering the Visible View
mabl 's innovative Scroll-to-Element feature tackles the visible view challenge head-on. It intelligently scrolls to find and interact with elements that are initially off-screen, making your tests more springy and less prone to scrolling-related failures.
Scroll to Element
Scroll within Element
For a deeper dive into how mabl 's scroll-to-element plant, check out tests.
Wrapping Up
Mobile automation presents unique challenges that can trip up even seasoned web automation expert. The scarcity of reliable locators and the `` visible view '' constraint can get trial creation and upkeep frustrating and time-consuming.
mabl 's mobile app test answer is design to address these challenge head-on. With Levelheaded Find and seamless scroll-to-element capabilities, mabl empowers your team to make reliable, scalable, and maintainable mobile tests, so you can focalise on delivering high-quality apps at the speed of DevOps.
Ready to receive the ease and reliability of mabl ’ s mobile app try? Try mabl complimentary for 14 days and see how low-code test creation, advanced element finding, and & nbsp; seamless scroll-to-element can revolutionize your mobile examination. Empower your team to deliver flawless peregrine experiences, faster.
Try mabl Free for 14 Days!
Our AI-powered quiz platform can transform your software quality, integrating automated end-to-end testing into the entire growth lifecycle.
Quality Engineering Resources
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