Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Appium Essentials

You're reading from  Appium Essentials

Product type Book
Published in Apr 2015
Publisher
ISBN-13 9781784392482
Pages 188 pages
Edition 1st Edition
Languages

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

Important initial points


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...

Automating native apps


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.

Native Android apps

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:

  1. Update the desired capabilities in the setup() method to launch the calculator app:

    caps.setCapability("avd","AVD_Nexus_4");// Mention the created AVD name
    caps.setCapability(MobileCapabilityType.APP_PACKAGE, "com.android.calculator2");
    caps.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.calculator2.Calculator");
  2. Now, we need to find the numbers; we are going to find them by name:

    WebElement five=driver.findElement(By.name("5"));
    WebElement four=driver.findElement(By.name(...

Working with web-apps


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.

Web apps on Android

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:

  1. Update the desired capabilities in the setup() method to launch the native browser:

    caps.setCapability("avd","AVD_Nexus_4");// Mention the created AVD name
    caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");
  2. Now, we need to navigate to https://www.google.com using the following command:

    driver.get("https://www...

Hybrid apps' automation


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.

Android hybrid apps

Here, we are going to take an example of testApp; you can get it from https://github.com/manojhans/Appium/blob/master/Application/Android/testApp.zip?raw=true.

If you are working with an Android version less than 4.4, then you have to use Selendroid (in that case, you have to set the capability as caps.setCapability (MobileCapabilityType.AUTOMATION_NAME,"Selendroid")), otherwise Appium has a built-in support through ChromeDriver.

While working with hybrid apps, you need to make the changes defined at https://developer.chrome.com/devtools/docs/remote-debugging#configure-webview. We have already made the changes in testApp. Initially, we will get the testApp as shown in following screenshot...

Summary


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.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Appium Essentials
Published in: Apr 2015 Publisher: ISBN-13: 9781784392482
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}