App Development

Automated Testing & Mobile Gestures: The Swipe

automating-mobile-gestures blog-featured-image ab-510x296

Automated tests play an integral role in software QA. These tests are designed to run through the system quickly and verify core app functionality is intact. They are also very useful for determining whether recent development work has resulted in negative side effects. Automating tests for mobile platforms is a relatively new field and comes with its own set of unique challenges.

One of those challenges is replicating the many gestures we use with mobile devices. Mobile apps support a variety of ways for users to interact with a UI. These interactions are so intuitive now we often use them without noticing. One of the most commonly used touch gestures is the swipe. Swiping allows users to view more content with the flick of a finger and is the primary way to navigate. Because of this, it’s critical automated tests be able to simulate this action.

Using the Appium library, we can swipe in iOS and Android with the same code. The swipe method lets you specify the exact coordinates of the swipe action. This method also allows for some precise swiping and even lets you specify the duration of the swipe, down to the millisecond:

swipe(start_x:50, start_y:50, end_x:100, end_y:50, duration:1000)

So we have an easy way to swipe anywhere we want, but how do we find anywhere on the screen? Android provides an easy solution to this with the “Pointer Location” setting. This setting can be enabled in Developer Settings on any Android device and will display the user’s swipe coordinates in real time on the top of the screen.

Embedded content: https://www.youtube.com/embed/9ctIObEWtA8?rel=0&controls=0&showinfo=0

Unfortunately, iOS has no such setting, but there are still ways to map out the view so you are not just blindly swiping all over the page. One way is to approximate swipe coordinates using nearby elements. Because Appium uses Selenium WebDriver elements, you have access to the location method. This method simply returns an x and y coordinate of an element and allows you to give a more accurate estimate for start and end points.

To get more precise coordinates on iOS, you can also implement some debug logging into your builds. By returning the CGPoint of every touch event, you get instant visibility of where the user is interacting within the view.

Swiping through pages is such a common action that it is worth abstracting the swipe method into “swipe left," “swipe down," etc. You can drop these methods into any of your automated test suites, and they also make your tests more readable. Testers should be wary of using the same swipe on different devices; however, the coordinates are relative to the size of the display, and it may break your test.

Navigating through the app with precision is huge for creating confidence in your tests. With stable test suites, we can run our tests against builds to ensure quality at every level of development.

Quickstart-Guide-to-Kotlin-Multiplatform

A Quick Start Guide to Kotlin Multiplatform

Kotlin Multiplatform, though still experimental, is a great up-and-coming solution...

Read the article