In this tutorial we will focus on How to Use Desired Capabilities in Appium correctly before execution of Appium Test Case. Desired Capabilities are nothing but the detailed information about the device and its environment on which we are going to execute our test cases.Let us gather the required info before doing setup. We will cover the following steps:
- Step 1: Gather Desired Capabilities
- Step 2: Launch And Start Appium Node Server
- Step 3: Create Appium Test Script In Eclipse
Step 1: Gather Desired Capabilities
Before creating Appium test cases for your android application, You need bellow given parameters of android device and app to set webdriver capabilities in test script.
Device Name : Connect your android device with PC and get device name by running adb devices command in command prompt.
Software App Package Name : Find your app package name from setting ->app details section.
Activity Name :Find your app package name from setting ->app details section .
Find Android OS Version : In your android device, Open settings -> About phone -> Android version. My device’s Android version Is : 4.4.2.
Step 2: Launch And Start Appium Node Server
Download Appium Server for Windows from here and install and then launch the server by double clicking on the Appium icon. Then Server window opens up as shown in the below figure. Click on play icon to start the serve. Server starts ip address is 127.0.0.1 and Port Number is 4723 by default.
Step 3: Create Appium Test Script In Eclipse
Prerequisite for writing test scripts :
deviceName – Name of device which is connected with PC.
CapabilityType.VERSION – OS version of your android device.
appPackage – Calculator app’s Package name.
appActivity – Calculator app’s Activity name.
Below is sample Java Code to understand how to set up desired capabilities
@Before
public void setUp() throws MalformedURLException {
// Created object of DesiredCapabilities class.
DesiredCapabilities capabilities = new DesiredCapabilities();
// Set android deviceName desired capability. Set your device name.
capabilities.setCapability(“deviceName”, “DEIVICEABDC”);
// Set BROWSER_NAME desired capability. It’s Android in our case here.
capabilities.setCapability(CapabilityType.BROWSER_NAME, “Android”);
// Set android VERSION desired capability. Set your mobile device’s OS version.
capabilities.setCapability(CapabilityType.VERSION, “6.0.1”);
// Set android platformName desired capability. It’s Android in our case here.
capabilities.setCapability(“platformName”, “Android”);
// Set your application’s appPackage if you are using any other app.
capabilities.setCapability(“appPackage”, “com.android.collagemaker”);
capabilities.setCapability(“appActivity”, “com.android.collagemake.MainActivity”);
// It will launch app in android device.
driver = new RemoteWebDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
Desired Capabilities in Appium
So that should be everything. Try that out and comment below if you have any questions or comments about it.