Chapter 5. Working with Appium
Now, we are going to start working with Appium on different mobile apps. We will be acquainted with emulators/simulators to automate mobile apps by Appium. We will take a look at how to install apps from a computer to an emulator, moving on to calling the Chrome browser in an Android emulator to set up the desired capabilities and test web applications. Then, we will learn how to start the Safari browser in a simulator and set up the desired capabilities to test web applications. We will also take a look at how to write automation scripts for native mobile apps. Lastly, we will automate the hybrid apps and switch from native to web view.
In this chapter, we will learn the following topics:
The automation of native apps
The automation of hybrid apps
Working with web apps and a native browser
Working with web apps and Safari
Before starting with Appium, let's make sure that we have all the necessary software installed.
The prerequisites for Android are as follows:
Java (version 7 or later)
The Android SDK API (version 17 or later)
An emulator
Eclipse
TestNG
The Appium server
The Appium client library (Java)
The Selenium Server and WebDriver Java library
The APK Info app
The prerequisites for iOS are as follows:
Mac OS 10.7 or later
Xcode (version 4.6.3 or later; 5.1 is recommended)
Simulator
Safari on simulator
Java Version 7
Eclipse
TestNG
The Appium Server
The Appium client library (Java)
The Selenium Server and WebDriver Java library
When working with Appium, we need to set the desired capabilities and initiate an Android/iOS driver. First, we need to understand them one by one.
Necessary desired capabilities for Android and initiating the Android driver
There are two ways to set the desired capabilities, one with the Appium GUI and another by initiating the desired capabilities object. Desired capabilities...
Native apps are basically developed for a particular platform, and they can take an advantage of the device's features. They can work offline. You can install a native app directly on to the device or through an application store, such as Google Play or Apple App Store.
Here, we are going to take an example of the Android calculator app, and in this section, we will take a look at the addition of two numbers.
Perform the following steps to automate the calculator app:
Update the desired capabilities in the setup()
method to launch the calculator app:
Now, we need to find the numbers; we are going to find them by name
:
Web apps can be run on any device or platform; the only requirement is a web browser and an Internet connection. The best part is that you don't need to install web-apps on the device. They are generally designed with cross-browser compatibility in mind.
We are going to take an example of the Google search page.
In this section, we are going to take a look at how to load the native browser on an emulator and then type data in the Google search box. Initially, we will get the native browser as shown in following screenshot:
Perform the following steps to load the native browser on an emulator and then type data in the Google search box:
Update the desired capabilities in the setup()
method to launch the native browser:
Now, we need to navigate to https://www.google.com using the following command:
Hybrid apps are a combination of native and web apps; similar to native apps, you can get hybrid apps through an application store. Nowadays, hybrid apps are very popular because they give us a cross-platform solution and display the content they get from the Web.
In this chapter, we looked at how to execute test scripts of native, hybrid, and mobile web apps on an iOS simulator and Android emulator. We learned how easily we can perform actions on native mobile apps and also learned about the desired capabilities that are required. We learned how to load the native browser in an Android emulator and the necessary capabilities to start with.
We saw how we can start the Safari browser in a simulator and set up the desired capabilities to test web applications. Lastly, we looked at how easily we can automate hybrid apps and switch from native to web view.
In the next chapter, we will take a look at Appium drivers on real devices.