Road to capture list all attached android devices with machine

While running Appium test suite, some time we need to execute test parallel on all attached devices, So the question is here that how we can capture all devices udid and pass devices id in appium desire capabilities. I created a function which return list of udid of all attached devices with machine.

public static List getAttachedDevicesList() {

            List devicesID = new ArrayList();
            try {
                    Process process = Runtime.getRuntime().exec(getAndroidPath() + "//platform-tools//adb devices");
                    BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                   String s;
                   while ((s = reader.readLine()) != null) {

                          if (s.contains("device") && !s.contains("attached")) {
                                      String[] device = s.split("\t");

          } catch (IOException e) {
                        logger.debug("adb command not executed to capture devices");
          return devicesID;

Note:  getAndroidPath() function defined in link Android_Home

No comments:

Post a Comment

Leave your comments, queries, suggestion I will try to provide solution