Getting desired capabilities at run time

I have two android devices

  1. Android 4.4.2
  2. Android 4.2.2

Can by code where appium server can detect which desired capability it has to used.

ex i have two capabilities method for 4.4.2 and 4.2.2 now when i run appium will get the current android OS version and then trigger the suitable capabilities method

It will help in making test cases more generic and more dynamic

You can get all capabilities thought method driver.getCapabilities()
As all capabilities are a Map (key and value) get the capabilities asMap()
The desired capabilities are a map inside the capabilities map, so you need to get that (desired is the key) and put in another Map
After that get the capability you want

To show the platform version see this code snippet in Java:

Capabilities cap = driver.getCapabilities();
Map<String, ?> desired = (Map<String, ?>) cap.getCapability("desired");
1 Like

thanks for reply

but i want to set desired capabilities before executing the code like when i run the code. code should itself detect the android version after that it set the desired capabilities

In this case if you want to set the desired capabilities (like the android version) and rout to appropriate devices you need to use Selenium Grid.

It is not working in latest appium, i tried same code