How to keep all the desired capabilities in framework

Hi Everyone.
I am working on framework creation.My Application supports many devices.where and how to keep all the desired capabilities for all the devices for andriod and iOS,So that i can just call them in my driver page and initialize the capabilities.Please guide me .Waiting for reply.Its bit urgent.

Just an advice

  1. You can create String array for storing different capability with hardcoded values

e.g. String[] deviceName={“74dnfgg45”,”XT48545”,”SMGOI5658”};

  1. You can add capability data in JAVA properties file and read from there

  2. You can pass this data from testNG.xml file

Thanks alot Amit for the reply.
Could you please explain it in bit detail.
what should i put in the array and what will the properties file contain.

Properties File Example

http://www.mkyong.com/java/java-properties-file-examples/
see example : [2. Load a properties file]

create a properties file and just put data in key value pair like below. Here # means entry is commented

Let file name be appiumSession.properties File

device1Name=XT1110
device2Name=SAM1110
automationName1=Appium
automationName2=Selendroid
platformNameI=iOS
platformNameA=Android
platformVersion=5.1

	public void setUp() {

	Properties prop = new Properties();
	InputStream input = null;

	try {
		input = new FileInputStream("path of appiumSession.properties file");
		// load a properties file
		prop.load(input);	
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability("automationName", prop.getProperty("automationName1"));
		capabilities.setCapability("platformName", prop.getProperty("platformNameA"));
		capabilities.setCapability("platformVersion", prop.getProperty("platformVersion"));
		capabilities.setCapability("deviceName", prop.getProperty("device1Name"));
		capabilities.setCapability("newCommandTimeout", "-1"); 
		driver = new AndroidDriver(new URL("http://localhost:4725/wd/hub"), capabilities);
	}catch (IOException io) {
		io.printStackTrace();
	}

}
2 Likes

Hard Coded Arrays Example

public class AppiumSetUP {
public String[] deviceName={“74dnfgg45”,”XT48545”,”SMGOI5658”};
public String[] automationName={“Appium”};
public String[] platformName={“iOS”,"Android"};
public String[] platformVersion={“4.4”,"5.0","5.2"};
public String[] newCommandTimeout ={“-1”,"3000","5000","10000"};
public String baseURL = "http://localhost:4725/wd/hub";
	
 public void setUp() {

		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability("automationName",automationName[0]);
		capabilities.setCapability("platformName", platformName[1]));
		capabilities.setCapability("platformVersion", platformVersion[0]));
		capabilities.setCapability("deviceName", device1Name[0]);
		capabilities.setCapability("newCommandTimeout",newCommandTimeout[2]);
		driver = new AndroidDriver(new URL(baseURL), capabilities);
	}catch (IOException io) {
		io.printStackTrace();
	}
}
}
1 Like

Thanks alot Amit.
Will check both techniques .
Thanks once again.
In the first technique,can i pass the property to pick up from the java file from where i am running the test.

yes u can read property from properties file in any class where u create Properties file obj and load the file and then using this object you can read any property using it’s name

data is stored in form of key value pair here key is name of property and value is its value

key - device1Name
value - XT1110

System.out.println(prop.getProperty(“device1Name”)); // this will show output as “XT1110”

There is one more way, rather than having the device list hard coded or having it on property file. Get them on runtime (preferably @ beforesuite ) dynamically. Unless you want the test to be executed on specific devices.

Steps,

  1. Get all connected device Android (and iOS if AUT is on both platform) by executing adb devices and instruments -s devices
  2. Start the server according to devices you have.
  3. Create thread running tests on each device.

In this way you can Just plug the devices and script will take care of the rest.

2 Likes

Hi pr4bh4sh
thanks for the reply.
in this how will i pass the rest capabilities required for running the test.
i have to hard code the capabilities and keep it somewhere.
please correct me .

Thanks Amit .i will try it.

just pass the device name as UDID parameter to the setup method or wherever you are setting it.

Ok.I will try this technique as well
Thanks pr4bh4sh

Create a a function to initialize driver.
In function create a switch case for required OS of device [Eg: Android,iOS etc]. Put all the required capabilities in case’s. And finally return driver from function.

Thanks Nikhil.
will definitively try this as well.

Hi Amita,

Can you share what you ended up going with and why you chose one style over the other. I’d very much appreciate it.

how to do this? snippet of the code with switch case would be useful

This question is a basic programming skills question and totally depends on the engineer knowing how to read data from a database. Hardcoding should never be an option, and is an anti-pattern. If you find yourself hard coding things, you are probably under time pressure. Time pressure that will kill your project at some future date. Sorry to get all philosophical here, but the code examples given by amitjaincoer are really the clearest answer you are going to get.