Appium

Download PDF

Keep it functional. Selendroid However among all these tools, APPIUM is emerging as a front runner as a choice for mobile apps automation. There are lots of reason for choosing Appium, Few are listed below. Appium being an open source tool is the perfect choice for automating native, mobile web and hybrid applications on their respective platforms. Use of standard API: Appium is widely popular because modification of codes or a recompilation of your app is not required as it uses the standard API in all the platforms. February 20, 2015. Switch App to browser and back to app. Issue where I want to assert that a word shows up 10 times on a mobile screen. Creating Accessibility Id's for app I see them in IOS but not Android.

1) Explain what is Appium?

Appium is a freely distributed open source mobile application UI Testing framework.

2) List out the Appium abilities?

Appium abilities are

  • Test Web
  • Provides cross-platform for Native and Hybrid mobile automation
  • Support JSON wire protocol
  • It does not require recompilation of App
  • Support automation test on physical device as well as similar or emulator both
  • It has no dependency on mobile device

3) List out the pre-requisite to use APPIUM?

Pre-requisite to use APPIUM is

  • ANDROID SDK
  • JDK
  • TestNG
  • Eclipse
  • Selenium Server JAR
  • Webdriver Language Binding Library
  • APPIUM for Windows
  • APK App Info On Google Play
  • js

4) List out the limitations of using Appium?

  • Appium does not support testing of Android Version lower than 4.2
  • Limited support for hybrid app testing. E.g., not possible to test the switching action of application from the web app to native and vice-versa
  • No support to run Appium Inspector on Microsoft Windows

5) Explain how to find DOM element or xPath in a mobile application?

To find the DOM element use 'UIAutomateviewer' to find DOM element for Android application.

6) Explain the design concept of Appium?

  • Appium is an 'HTTP Server' written using Node.js platform and drives iOS and Android session using Webdriver JSON wire protocol. Hence, before initializing the Appium Server, Node.js must be pre-installed on the system
  • When Appium is downloaded and installed, then a server is setup on our machine that exposes a REST API
  • It receives connection and command request from the client and execute that command on mobile devices (Android / iOS)
  • It responds back with HTTP responses. Again, to execute this request, it uses the mobile test automation frameworks to drive the user interface of the apps. Framework like
    • Apple Instruments for iOS (Instruments are available only in Xcode 3.0 or later with OS X v10.5 and later)
    • Google UIAutomator for Android API level 16 or higher
    • Selendroid for Android API level 15 or less

7) What language does Appium support?

Appium support any language that support HTTP request like Java, JavaScript with Node.js, Python, Ruby, PHP, Perl, etc.

8) Explain the pros and cons of Appium?

Pros:

  • For programmer irrespective of the platform, he is automating ( Android or iOS) all the complexities will remain under single Appium server
  • It opens the door to cross-platform mobile testing which means the same test would work on multiple platforms
  • Appium does not require extra components in your App to make it automation friendly
  • It can automate Hybrid, Web and Native mobile applications

Cons:

  • Running scripts on multiple iOS simulators at the same time is possible with Appium
  • It uses UIAutomator for Android Automation which supports only Android SDK platform, API 16 or higher and to support the older API's they have used another open source library called Selendroid

9) Explain what is APPIUM INSPECTOR?

Similar to Selenium IDE record and Playback tool, Appium has an 'Inspector' to record and playback. It records and plays native application behavior by inspecting DOM and generates the test scripts in any desired language. However, Appium Inspector does not support Windows and use UIAutomator viewer in its option.

10) Mention what are the basic requirement for writing Appium tests?

For writing Appium tests you require,

  • Driver Client: Appium drives mobile applications as though it were a user. Using a client library you write your Appium tests which wrap your test steps and sends to the Appium server over HTTP.
  • Appium Session: You have to first initialize a session, as such Appium test takes place in the session. Once the Automation is done for one session, it can be ended and wait for another session
  • Desired Capabilities: To initialize an Appium session you need to define certain parameters known as 'desired capabilities' like PlatformName, PlatformVersion, Device Name and so on. It specifies the kind of automation one requires from the Appium server.
  • Driver Commands: You can write your test steps using a large and expressive vocabulary of commands.

11) Mention what are the possible errors one might encounter using Appium?

The possible errors one might face in Appium includes

  • Error 1: The following desired capabilities are needed but not provided: Device Name, platformName
  • Error 2: Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path
  • Error 3: openqa.selenium.SessionNotCreatedException: A new session could not be created
  • Error 4: How to find DOM element or XPath in a mobile application?
Appium

12) Do you need a server machine to run tests on Appium?

No, you don't need server machine to run tests on Appium. Appium facilitates a 2-tier architecture where a test machine connects to a test server running Appium and automating the whole thing. You can have Appium running on the same machine where your test runs.

13) Is it possible to interact with my apps using Javascript while I am testing with Appium?

Yes, it is possible to interact with App while using Javascript. When the commands run on Appium, the server will send the script to your app wrapped into an anonymous function to be executed.

14) Mention what are the most difficult scenarios to test with Appium?

The most difficult scenario to test with Appium is data exchange.

15) While using Appium can I run my tests in a multithreaded environment?

Yes, you can run the test in a multithreaded environment but you have to ensure that no more than one test runs at the same time against the same Appium server.

16) In Android, do you need an app's .apk to automate using Appium or you also need app in my workspace?

In Android, you only need .apk file to automate using Appium.

17) Explain what is Appium package master? How to create package?

Appium package master is a set of tools manage and create appium packages. For example to create package you can use the code

# using es7/babe1

Gulp create-package –n <package-name>

#regular es5

Gulp create-package ---nobabe1 –n <package-name>

The package will be generated in the out/<package-name>

18) Explain how test frameworks are supported by Appium?

Appium does not support test framework as such there is no need to support them. Appium can be used with any frameworks you want.

Appium is an open-source test automation tool that is used for automating mobile web, native, and hybrid applications across platforms like Android and iOS devices by executing our test scripts using the Appium server. If you are looking to completely automate your mobile app testing process by using Appium, then it is mandatory for you to know how to automate the in-build mobile features of the device. So in this Appium tutorial, we will be focusing on how to automate some of the most useful in-built features using Appium. As a leading QA company, we also provide mobile testing as a service and these features have come in handy for us when we’ve needed to toggle between screen orientations, retrieve OTP’s, and so on in our various projects. Let’s start with the basics and find out how to start a new session before we head over to the main aspects.

1. Creating a New Session

You can start a new session using the serer by defining the desired capabilities while passing the arguments. In the below code, we have defined the capabilities as per our need.

Appium

Passing the capabilities(Mobile Configuration)

2. Installing the App:

Once you have created the new session, installing the application that you want to test is pretty much a no-brainer. Let’s take a look at the 2 ways you can install the New APK file,

Appium Tutorial For Beginners

(i.) Install using “DesiredCapabilities” before launching the Android driver instance.

(ii.) Install via the ‘installApp’ method.

You can install the new app using the “installApp” command, and it is important to note that you would need to pass the APK file path.

Code:

Example: The calculator application will be installed on my real device through the Appium server.

3. Status of the Appium Server:

You can retrieve the Appium server status through the driver instance by making use of the below code.

Code:

o/p: {build={version=1.20.2}}

4. Appium Tutorial to Get & Set Orientation:

If you are testing any application, one of the basic things you would want to make sure of is if it works well on both portrait and landscape orientations. So you can control the screen orientation of the smartphone using Appium and set it as per your needs. You can get/set the mobile orientation using the below-mentioned command,

i. Get Orientation:

– You can get the mobile orientation information using this command “getOrientation()” as illustrated in the below code

Code:

– o/p: LANDSCAPE|PORTRAIT

ii. Set Orientation:

– You can set the device orientation to Landscape or Portrait by using the following codes,

Code:

5. Geo-Location Feature Usage:

Nowadays, so many applications depend on using the Geo-location feature of the smartphone for various reasons and functions. Let’s say you are testing an application that is used to make online payments, then there might come a scenario where you might have to turn on the GPS of the smartphone during sign-in to monitor any suspicious activity. So you can get/set the Geo-location using the location() command in Appium. It will return the Geo-location in the form of (Latitude, Longitude), and the code you need is listed below.

6. Appium Tutorial to Retrieve Device Settings:

You can get the Device settings using the driver instance, which will return the current device settings.

Code:

If you want to add one more capability, we can add it via the setSetting() method. (Update the current setting in the mobile device) At times the page you want may not load though you have a fast internet connection, and you wouldn’t want your automation testing to be stuck there for no good reason. So by using this option, you will be able to assign a timeout.

Code:

By making use of the above code, we have set a timeout of 500 milliseconds (5 seconds). After which, if the scenario is idle without proceeding any further, then it will be considered a failure, and the next scenario will begin testing.

7. Appium Tutorial to Start an Activity:

One of the most common scenarios where you might need to rely on another application like messages is to retrieve an OTP or send a verification message for safety purposes. You can easily start an Android activity by providing the package name and the activity name.

To initialize the New Android app using Activity and package name. If you want to launch the new app for the same execution, we can call the “startActivity” method.

For example, during the same execution, receive the OTP in the Messages app; You can call the “startActivity” method.

Example:

8. Appium Tutorial for Recording the Screen:

You might be testing an app that is specifically designed to work well with screen recorders, or if we look at a more common scenario, you might have to record the entire test execution from step A to step Z as it is easier to explain what the bug is. Or you might want to use this feature to maintain a log of all the tests that you have done. In these scenarios, you can make use of the below-mentioned code snippet to get the job done. We can record the mobile script execution using the “startRecordingScreen” method, which is provided by appium.java_client package.

The feature has more customization options to offer as we can assign time limits or size limits for the screen record. You can use the above codes for this purpose.

i. withTimeLimit(), ii. withVideoSize(), etc…

Once you stop the screen recording, you will have the option to set/write the path for the video file and define where it has to be saved.

9. Device Interactions Features:

Device Interactions are some of the basic features that every end-user would use, and a feature we would not miss covering in our Appium tutorial. Features like locking the device or unlocking the device are a couple of examples. If you are looking to test a video player application, then you might want to see what happens to the app when the device gets locked as a video is playing. Either there should be an option for background play, which will result in the audio continuing to play, or the app must stop playing once the device is locked. Now let’s find out how to accomplish this. We have listed the feature and the code that is required.

i. Lock the device

ii. Unlock the device

iii. Get DeviceLocked status

10. Controlling Keyboard Actions:

Another basic inbuilt feature every application uses is the keyboard. We ourselves would have seen the same bug in many applications where the keyboard does not hide once the OTP or pin or any data is entered. To make things worse, the button to click to go to the next stage will be hidden by the keyboard during such scenarios. So how can you open the keyboard, hide it and even check the current status of the keyboard? Easy, you can simply follow the below commands.

i. To open the Keyboard.

ii. To hide the Keyboard.

iii. You can use the below code to check whether the Device keyboard is Opened or not.

11. Appium Tutorial to Get Performance Data:

Obtaining the performance data is a very important feature that we will be seeing now in this Appium Tutorial as nobody wants to use an app that is overloading their device. You can verify if the app you are testing is optimal or not by obtaining the logs of the Mobile application performance data types such as CPU, Memory, Network traffic, and Battery. We have listed the codes you will need below.

Code:

O/P: [cpuinfo, memoryinfo, batteryinfo, networkinfo]

We can also retrieve the performance log from the Appium driver instance using this method, and we need to pass the parameters like AppPackageName, PerformanceDataTypes, and Data Read Timeout.

Code:

12. Terminate App & Remove App Features:

Once you have completed testing the app with a few test cases you would have to start over with a new combination after closing the app. Or you might have completely finished testing and would want to uninstall the application from the device itself. You can easily do both by making use of the below codes.

i. Terminate App:

– In this Method(terminateApp), We can use it to close the App from a real device using App Packages or Activity Names.

Appium mobile testing

Appium.io

Example:

Appiumpro

ii. Remove App:

– In this function(removeApp), To uninstall the Application from the real device. (It will be removed/deleted entirely from the real device which is passing the Package Name)

Example:

13. Is App Installed Feature

You might use this feature at the beginning before you start testing or use it at the end once you have uninstalled the application. It is used to check whether the application is installed or not in the real device, and we can use the ‘isAppInstalled” command to do it. It’ll return a Boolean function that is either true or false.

Example:

Conclusion:

Appium Tutorial

We hope that this blog has been an informative and enjoyable read for you. These are the basic in-built features that we thought you might use in most of your testing. If you would like to know how to automate any other in-built feature using Appium apart from what we have discussed in this Appium Tutorial, just head over to our comments section and post your question. As one of the companies that provide the best mobile device testing services, we will be able to help you out with any doubts. Also, make sure to subscribe to our blog as we will be posting more of such informative content that will help you stay on top of your game.