Appium – Setting up various mobile platforms for automation

Hey Folks,

This post will take you through how to setup various mobile platforms (Android Native, Android Web, IOS Native and IOS web) using DesiredCapabilities, virtual devices and Appium server.

Though numerous information is already available on this over the internet but this post will try to segregate it in one place and will see how can we run native and web apps on virtual devices (Android Emulator and IOS Simulator).

Lets get started without wasting any time.

You will need following softwares (Versions may vary) to setup the platforms. I am using following versions. You may use other versions as well ensuring the best compatibility.

Appium 1.65

Genymotion 2.10.0 (for Android Emulator)

–You can also use the default emulators that comes along with the Android Studio.

Xcode 8.2.1 (for IOS Simulator)

Setting up Desired Capabilities for Android Native platform:

Following capabilities will be used to launch any Android native app on the Android virtual device (Emulator)

DesiredCapabilities capabilities = new DesiredCapabilities();

File app = new File(“<path to the android app apk file>”);

capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “6.0”);

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);

capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());

capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,“Emulator”);

URL url = new URL(“http://0.0.0.0:4723/wd/hub“);

AppiumDriver driver = new AndroidDriver(url,capabilities);

Explanation:

First we are creating the object of DesiredCapabilities, this object will be used to carry all desired capabilities.

Next we are creating a File object and assigning the apk file path to it along with the apk name.

Then will setup various capabilities in the capabilities object.

  • PLATFORM_VERSION – – should be your virtual device version.
  • PLATFORM_NAME – – should be Android for Android platforms (irrespective of native and web).
  • APP – should be absolute path to apk file so that appium can find and install it on the device.
  • DEVICE_NAME – – can be Emulator or the device name (eg Nexus 5 etc) which was assigned while creating the virtual device.

Now we are creating the URL object and providing the address where appium server is running. By default it runs on 0.0.0.0:4723 as you can see below

You can run appium on different ports using the command appium -p <port number>

Finally we are launching the AndroidDriver using the URL and DesiredCapabilities that we created. If everything is setup correctly, appium server is up and virtual device is running then it should launch your apk file on the virtual device.

Setting up Desired Capabilities for Android Web platform:

Its pretty much similar as setting up environment for Android Native except few things that we will cover here.

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “6.0”);

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);

capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,“Emulator”);

capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, “Chrome”);

URL url = new URL(“http://0.0.0.0:4723/wd/hub“);

AppiumDriver driver = new AndroidDriver(url,capabilities);

Explanation:

Since it is Web platform we do not need any apk file and hence no capability to mention the app path. Instead, we will mention the browser name that we want to launch. Here it is Chrome in our case.

Start the appium server and the virtual device (Emulator). Now run the code where these capabilities are written. It should launch the chrome browser on the virtual device successfully.

Now you can write test cases to open any url and test various scenarios.

Note – Chrome should be installed in the virtual device where we want to simulate our test. If you do not have chrome already installed then follow any post from internet to install it on virtual device or refer this post

Install Google Play Store and Chrome on Genymotion Virtual Device

Setting up Desired Capabilities for IOS Native platform:

DesiredCapabilities capabilities = new DesiredCapabilities();

File app = new File(“<path to the ios .app or .ipa file>”);

capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “10.2”);

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “IOS”);

capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());

capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,“iPhone 6”);

URL url = new URL(“http://0.0.0.0:4723/wd/hub“);

AppiumDriver driver = new IOSDriver(url,capabilities);

Note – The platform version and the device name should be as per the devices configured in the Xcode. I have taken the platform version and device name from the device configured in the Xcode, as shown below.

These capabilities should launch the IOS simulator and install your IOS native app. You can further automate your test cases for the native app.

Setting up Desired Capabilities for IOS Web platform:

Now we will see how to launch Safari in IOS Simulator to automate web apps.

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “10.2”);

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “IOS”);

capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,“iPhone 6”);

capabilities.setCapability(MobileCapabilityType.BROWSER_NAME,”Safari”);

URL url = new URL(“http://0.0.0.0:4723/wd/hub“);

AppiumDriver driver = new IOSDriver(url,capabilities);

Explanation:

For the web platform we do not need any app, so removing the related capability and adding the capability for browser name.

Start the appium server executes code that has all the capabilities mentioned above. IOS simulator should launch with safari.

You can further write your test cases to automate any web app.

Note – IOS simulators comes by default with Safari installed, no need to install it explicitly.

Thank you! In the coming posts we will see how to execute mobile test cases on Sauce labs.

Any feedback is most welcome 🙂

I am Nitin Goyal working as Sr. QA Consultant in Automation with Xebia. I am passionate about automation, learning new technologies and sharing my knowledge. Being an Xebian, its our religion to learn and make others learn.

Leave a Reply

Your email address will not be published. Required fields are marked *