This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
1 / 15
Feb 2016

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.

  • created

    Feb '16
  • last reply

    Apr '17
  • 14

    replies

  • 3.3k

    views

  • 5

    users

  • 1

    like

  • 1

    link

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/90
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();
	}

}

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();
	}
}
}

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.

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 .

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.

1 year later

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.