Set Desired Capabilities in Appium

Let’s see, How can you Set Desired Capabilities in Appium. In previous tutorials, You have seen How can you set up the Appium on your local machine.  It’s recommended to go through with Appium Setup Tutorial first.

 

In this tutorial we will see, How can you set the Desired capabilities for Appium Test Script. For Appium Test Script we require Desired Capabilities.

Now the question, Why Desired Capabilities Required?
Basically, the DesiredCapabilities help to set properties for the Selenium WebDriver.

A typical use-case would be to set the path for the FirefoxDriver if your local installation doesn’t correspond to the default settings. Desired Capabilities is a class in org.openqa.selenium.remote.DesiredCapabilities package.

Mostly DesiredCapabilities class used when do we use Selenium Grid & Appium.

 

Desired Capabilities in Appium

You will see what desired capabilities are required for Appium setup. First, we will create sample Java Project in Eclipse. Setup the Eclipse for Appium .

 

Let’s understand this with the help of below-mentioned code.

Now let’s understand the above code line by line.

 

To test the app on an actual device Desired Capabilities need to be set. Desired Capabilities a set of keys and values sent to the Appium server to tell the server what kind of automation session we’re interested in starting up.

DesiredCapabilities capabilities = new DesiredCapabilities();

To Create the Object of DesiredCapabilities Class.

 

capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);

Name of a mobile web browser to automate. It should be an empty string as we are automation an app. We will set it once we will launch the Web App.

 

capabilities.setCapability(“deviceName”, “Micromax A310”);

Enter your device name here. I am using Micromax A310. Please make sure, this field is case sensitive.

 

capabilities.setCapability(“platformVersion”, “4.4.2”);

Enter your Device Android version here. You can find it on your device. Setting -> About Phone.

 

capabilities.setCapability(“platformName”, “Android”);

Name of the OS: Android, iOS or FirefoxOS

 

capabilities.setCapability(“app”,”Provide your app APK absolute path here”);

Provide your App APK file absolute path here. I mean APK file local path. We will discuss this in coming tutorials. What is APK and how can you get the Application APK.

 

capabilities.setCapability(“appPackage”, “Enter You App package here”);

Enter the Java package of the tested Android app. Every application has their appPackage. We will discuss it later, How can you get the appPackage and how can you use it.

 

capabilities.setCapability(“appActivity”,”Enter Your App Activity Here”);

Enter the activity name for the Android activity you want to run from your package. We will discuss it later.

 

WebDriver driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);

Initialize the Andriod Driver with new Url and Capabilities. We need to provide the URL and port on which Appium is running. You can get it from Appium. Open Appium Server and click on general setting, here you will find the URL and Port number.

 

The purpose of above code to explain the Desired Capabilities, this code is not executable. So, Please don’t try to copy and execute the above code on your local machine. We will see further how can you execute the Test Script.

1 Comment
  1. Jessica Ivan 1:06 PM / May 30, 2017 - Reply

    Nice, easy to understand and comprehensive tutorial….

Leave a Reply