We live in a mobile era. There is a mobile app out there for possibly everything you can imagine. As per statistics, iOS and Android app stores each contain close to 2 million apps! Additionally, majority of web applications are responsive nowadays, allowing mobile users to enjoy seamless browsing experience on their mobile devices. Needless to say, with all these inroads of mobile technology, all software testers have a daunting task at their hand. And that is to perform mobile testing!
Now, since mobile testing involves testing on a lot of different devices and platforms, it can become tedious quickly. And due to this, there are chances that a tester would get bogged down by the repetitive nature of this task. Thankfully, there is a way out of this. And that is to leverage automation using mobile automation tools. While there are many tools available for mobile automation right now, Appium is one of the most widely used among them. It’s flexible, scalable, feature rich and immensely helpful. No doubt learning it would make our mobile testing life a whole lot easier. So why not start learning it right now with this detailed Appium tutorial? Sounds exciting, right? Let’s start then, with our first step towards Appium journey.
A bit about this Appium tutorial
In this article, we will try to cover every aspects of Appium that a user starting from scratch would find interesting. So yes, you guessed it right. The target audience of this Appium tutorial is complete beginners. Although, experienced users will also find it a great refresher. In any case, if Appium is something that interests you, you will find this Appium tutorial useful.
Well, enough with the talks. Let’s get down to business and start this Appium tutorial with introduction to Appium.
Introduction to Appium
To put it simply, Appium is an open-source tool for mobile automation. It allows automation of native, mobile web and hybrid mobile applications. Using Appium, we can automate iOS, Android and Windows Phone apps on both emulator/simulator and on physical mobile devices.
However, the real beauty of Appium lies in its ‘cross-platform’ support. It lets us write tests for multiple platforms (iOS, Android and Windows Phone), using the same API. That means you can write your test for Android platform and use that same test for iOS or Windows Phone! The underlying API remains same. This results in large amount of code reuse between different test suites.
Another cool feature of Appium is its ability to automate without recompiling the app. That means we don’t need access to our application code. Other mobile automation tools such as Calabash and Frank requires an extra agent compiled with the app code. But there’s no such requirement for Appium! This essentially means you will be testing the same app which you are going to submit in app stores.
Additionally, Appium is built according to philosophy which follows below 4 tenets. Let’s check out each of these and see how Appium follows them.
- You shouldn’t have to recompile your app or modify it in any way in order to automate it
As we saw earlier in this Appium tutorial, Appium does not require any extra agent in application code. Therefore, we don’t need to recompile or modify our app.
- You shouldn’t be locked into a specific language or framework to write and run your tests
Appium allows writing tests in Ruby, Python, Java, Node.js, Objective-C, PHP and C#. Users need not learn any new language/framework to use it.
- A mobile automation framework shouldn’t reinvent the wheel when it comes to automation APIs
Appium uses WebDriver API, which is pretty well known among automation testers already. So, it doesn’t reinvent the wheel by introducing the entirely new API.
- A mobile automation framework should be open source, in spirit and practice as well as in name!
This philosophy is obvious. Appium is freely available and users can freely modify it as per their requirements. Truly open source in spirit and in practice!
Till now in this Appium tutorial, we have got a good idea about Appium basics. Now from here, we can start exploring the actual technology side of Appium. So, let’s start by understanding Appium architecture first.
Understanding Appium architecture in this Appium tutorial will help us grasp a lot of important concepts. While its architecture is fairly straight forward, we have made its illustration as detailed as possible for you to understand it thoroughly. So, let’s dive right in.
Probably the most important aspect of Appium architecture is its client/server nature. Appium follows a client/server architecture. So at this point, it would be important for us to understand what is client and what is server in its design. We will check them out one by one below.
Server: If you have ever used Selenium RC before, you’ll find that Appium works in a similar line. Just like Selenium server in Selenium RC, Appium essentially is a server at its very core. It facilitates communication between client and a mobile device. It is important to note here that Appium server is written in Node.js. That’s why we need Node.js installed in our system to use it.
Clear about client and server in Appium? Now, let’s see how they communicate with each other.
Communication between client and server
When Appium server starts, it basically exposes a REST API to client. Client initiates a session with it using a JSON ‘desired capabilities’ object. Server in turn starts a session and responds to client with a session ID. This results in creation of session between client and server.
Now that the session is established between them, client sends automation commands to server. Appium server executes those commands on mobile device and responds to client with results.
At this point, it is worth noting that Appium does not execute commands on mobile devices directly. Instead, it invokes vendor-provided automation frameworks specific to the platform that we are testing on. Vendors like Apple, Google and Microsoft provides automation frameworks for their platforms. Appium server hooks to these frameworks and carries out automation on device.
Below diagram explains the whole process.
Below is a list of vendor frameworks Appium uses for automation on different platforms.
- iOS: Apple’s UIAutomation
- Android 2.3+: Google’s UIAutomator
- Android 4.2+: Google’s Instrumentation
- Windows: Microsoft’s WinAppDriver
A note about desired capabilities
We saw earlier in this Appium tutorial that client sends JSON ‘desired capabilities’ object to server to initiate a session. You must be wondering as to what is ‘desired capabilities’. Well, to put it simply, they are a set of key-value pairs to tell the Appium server what kind of automation session is required. For example, setting ‘platformVersion’ capability to 4.4 tells Appium to initiate an Android 4.4 session. Similarly, ‘platformName’ capability tells Appium to start iOS, Android or Windows platform session.
So, till now in this Appium tutorial, we have got all the basics covered. As you may already know, there are various other open source mobile automation tools available. Let’s see how Appium stacks up against each of them.
Comparing Appium with other mobile automation tools
As you can see in above comparison, Appium provides a lot of flexibility in terms of features and platform support. In addition to the features mentioned above, Appium provides GUI mode and a built in test recording tool called Inspector. This tool is detailed below.
Much like Selenium IDE, Appium too provides a record and playback tool called Inspector. This tool can generate a test code by simply navigating around in mobile application. Pretty handy feature we must say. Not only this. Appium Inspector also makes finding locators an easy task. You just need to click on your app’s UI element and Inspector will load all of its available attributes in side panel.
The only gripe about this tool is its limited platform support. It is Mac and Windows only at the moment. So, you will not be able to use it on Linux platform. Nonetheless, it’s a great addition to Appium and it certainly makes mobile automation easier. Check out this amazing tool in action below.
Appium Inspector in Action
So far, we have seen many advantages of Appium in this Appium tutorial. However, with all its cool features, Appium has some limitations as well. Namely below are some aspects where Appium falls short.
- Probably the single most limiting factor for Appium is its inability to properly synchronize with AUT. We can look at it this way. When our automation tests are running, we wait for some action to complete. It can be waiting for some element to load or waiting for an element to get ready for further actions. Appium does not handle this delay intelligently. Sure, you can put wait command to overcome this. But it is not efficient solution and it can make your automation tests slower, ultimately defeating the very purpose of automation. Tools like Espresso and EarlGrey takes the cake here for intelligently handling synchronization.
- As an automation tester, you always want your tests to be scalable, right? However from scalability perspective, Appium can be a tough nut to crack if you are testing on iOS platform. Due to technical limitation of Apple’s Instruments framework, you can only execute one test at a time per Mac. This is a big limitation as buying multiple Macs can prove costly. One way to control this limitation is to take help of mobile cloud services like SauceLabs.
- As we have seen earlier in this Appium tutorial, Appium uses Selendroid framework for API level < 16 and UIAutomator framework for API level > 16. This different configuration for single platform can be an overhead while setting up Appium.
- You will need Mac system to run iOS tests. So you can’t automate iOS apps on Windows or Linux systems. It’s because Appium requires Xcode for iOS automation which is Mac-only at the moment.
- Furthermore, if you are just starting out with automation, Appium can be a little tough to setup.
OK, so we are getting at the end of our Appium tutorial. But before we finish it, let’s check out some Appium cloud services.
Appium cloud services
Here are some notable cloud services which allows us to scale our Appium tests.
- AWS Device Farm
- Xamarin Test Cloud
- Testdroid Cloud
Well, that marks the end of our Appium tutorial. Now that you know all the bare bones of Appium, you can start getting the actual hands-on with the tool. Can’t wait to get started? No worries. We have got you covered with some setup tutorials. Check them out.
We hope you have enjoyed reading this Appium tutorial. If yes, we urge you to share it with fellow testers who might also be interested in learning Appium. Oh and please don’t forget to share your feedback in comments.