How to use Genymotion, Appium & Applitools to visually test Android apps
Tags: android, testing, java, tutorial
Published: 2020-01-21 22:08:08

If you want to run mobile applications, you want to run on Android. Android devices dominate the smartphone market. Genymotion allows you to run your Appium tests in parallel on a range of virtual Android devices. Applitools lets you rapidly validate how each device renders each Appium test. Together, Genymotion and Applitools give you coverage with speed for your functional and visual tests.

As a QA automation professional, you know you need to test on Android.  Then you look at the market and realize just how fragmented the market is.

##How fragmented is Android?##
Fragmented is an understatement. A [**study by OpenSignal**](https://www.opensignal.com/sites/opensignal-com/files/data/reports/global/data-2015-08/2015_08_fragmentation_report.pdf) measured over 24,000 unique models of Android devices in use, running nine different Android OS versions across over three dozen different screen sizes, manufactured by 1,294 distinct device vendors. That is fragmentation. These numbers are mind-boggling, so here’s a chart to explain. Each box represents the usage share of one phone model.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/28u64i5krlcpajsq7eo9.png)

Plenty of other studies confirm this. There are [**19 major vendors of Android devices**](https://phandroid.com/manufacturers/). Leading manufacturers include Samsung, Huawei, OnePlus, Xiaome, and Google. The market share of the leading Android device is [**less than 2% of the market**](https://www.appbrain.com/stats/top-android-phones), and the market share of the top 10 devices is 11%. The most popular  Android version accounts for only [**31% of the market**](https://www.appbrain.com/stats/top-android-sdk-versions).

We would all like to think that Android devices behave exactly the same way.  But, no one knows for sure without testing. If you check through the [**Google Issue Tracker**](https://issuetracker.google.com/issues?q=android&p=1), you’ll find a range of issues that end up as platform-specific.

##Implications for Android Test Coverage##
So, if every Android device might behave differently, exactly how should you test your Android apps? One way is to run the test functionally on each platform and measure behavior in code – that’s costly. Another way is to run functionally on one platform and hope the code works on the others. Functionally, this can tell you that the app works – but you are left vulnerable to device-specific behaviors that may not be obvious without testing.

To visualize the challenge of testing against 24,000 unique platforms, imagine your application has just 10 screens. If you placed these ten different screens on 24,000 unique devices end-to-end, they would stretch over 30 miles. That’s longer than the distance of a marathon!

Could you imagine manually checking a marathon’s worth of screens with every release?
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/t1yhs3jndnvyhxiih599.jpg)

I can’t run a marathon, much less do while examining thousands of screens. Thankfully there’s a better way, which I’ll explain below: using [Genymotion](https://www.genymotion.com/), [Appium](http://appium.io/), and [Applitools](https://applitools.com/).

##What is Genymotion?##
Genymotion is a leading provider of cloud-based Android emulation and [virtual mobile infrastructure](https://en.wikipedia.org/wiki/Remote_mobile_virtualization#Virtual_mobile_infrastructure_(VMI)) solutions. Genymotion frees you from having to build your own Android device farm.

Once you integrate your Appium tests with [Genymotion Cloud](https://www.genymotion.com/cloud/), you can run them in parallel across many Android devices at once, to detect bugs as soon as possible and spend less time on test runs. That’s powerful.

With Genymotion Cloud, you can choose to test against just the most popular Android device/OS combinations. Or, you can test the combinations for a specific platform vendor in detail. Genymotion gives you the flexibility to run whatever combination of Androids you need.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/lr21pojk2lyro0oepfuf.jpg)

##Why use Genymotion Cloud & Applitools?##
Genymotion Cloud can run your Android functional tests across multiple platforms. However, functional tests are a subset of the device and OS version issues you might encounter with your application. In addition to functional tests. you can run into visual issues that affect how your app looks as well as how it runs. How do you run visual UI tests with Genymotion Cloud? Applitools.

Applitools provides AI-powered visual testing of applications and allows you to test cross-platform easily to identify visual bugs. Visual regressions seem like they might be simply a distraction to your customers. At worst, though, visual errors block your customers from completing transactions. Visual errors have real costs – and without visual testing, they often don’t appear until a user encounters them in the field.

Here’s one example of what I’m talking about. This messed-up layout blocked Instagram from making any money on this ad, and probably led to an upset customer and engineering VP. All the elements are present, so this screen probably passed functional testing.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/dpmv2q8gros4zftfrvom.png)
You can find plenty of other examples of visual regressions by following [**#GUIGoneWrong on Twitter**](https://twitter.com/search?q=%23guigonewrong&src=typed_query).

Applitools uses an AI-powered visual testing engine to highlight issues that customers would identify. More importantly, Applitools ignores differences that customers would not notice. If you ever used snapshot testing, you may have stopped because you tracked down [**too many false positives**](https://applitools.com/blog/why-screenshot-image-comparison-tools-fail?utm_term=cat&utm_source=syndication&utm_medium=&utm_content=blog&utm_campaign=&utm_subgroup=devto). Applitools finds the issues that matter and ignores the ones that don’t.

##How to use Genymotion, Appium & Applitools?##
Applitools already works with Appium to provide visual testing for your Android OS applications. Now, you can use Applitools and Genymotion to run your visual tests across numerous Android virtual devices. To sum up:

 - Write your tests in Appium using the [**Applitools SDK**](https://applitools.com/tutorials/appium-native-java.html?utm_term=cat&utm_source=syndication&utm_medium=&utm_content=tutorial&utm_campaign=&utm_subgroup=devto) to capture visual images.
 - Launch the Genymotion cloud devices via command line.
 - Your Appium scripts will run visual tests across the Genymotion virtual devices.

That’s the overview. To dive into the details, check out this [**step-by-step tutorial on GitHub**](https://github.com/applitools/applitools-genymotion-sample) demonstrating the integration of Applitools & Genymotion Cloud using Java / TestNG.

While it’s pretty complete, here’s some additional information you’ll need:

 - Download and install [**Python 3**](https://realpython.com/installing-python/)
 - Next, install pip3 on [**Windows**](https://www.liquidweb.com/kb/install-pip-windows/) or [**macOS**](https://evansdianga.com/install-pip-osx/)
 - Finally, make sure you install [**Android SDK**](https://www.androidcentral.com/installing-android-sdk-windows-mac-and-linux-tutorial)

Here is a series of [**step-by-step tutorial videos**](https://www.youtube.com/watch?v=qXuMglfNEeo&list=PLkqF-NUszJY5aTOZ9Uj7KaR3j3_6RT5on) using Genymotion, Appium, and Applitools. Here’s the first one:

{% youtube qXuMglfNEeo %}

##Genymotion, Appium, and Applitools: Better Together##
When you run Appium, Applitools, and Genymotion together, you get a huge boost in test productivity. You get to re-use your existing Appium test scripts. Genymotion lets you run all your functional and visual tests in parallel. And, with the accuracy of Applitools AI-powered visual testing, you track down only issues that matter, without the distraction of false positives.