Road to Setup Protractor and Selenium Webdriver

Protractor is web based end to end automation testing framework for Angular based application. It is most popular open source testing framework for Angular based application.
Protractor framework is node.js based program and written in java scripts. Protractor uses Webdriver to simulate and control web application.

Setup Protractor: Below installation is for windows machine.
1.    Download node js form link : Nodejs after downloading install exe in your machine.
2.    After clicking on ex you should get below screen:
Blogger Tricks

Road to capture Android Home path from system env

Use below code to read Android_Home path which you have setup in your System.

    public static String getAndroidPath() {
        String androidHome = null;
        Map env = System.getenv();
        for (String envName : env.keySet()) {
            if (envName.equals("ANDROID_HOME"))

                androidHome = env.get(envName);
        }
        if (androidHome.equals(null))
            throw new NullPointerException(
                    "Android Home path not set in machine");
        return androidHome;
    }




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");
                                     devicesID.add(device[0]);
                              }
                   }

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


Note:  getAndroidPath() function defined in link Android_Home

Road to scroll mobile application using Appium

Some time we need to scroll (swap ) screen to scroll application, it can be left, right up and down. You can use following function to achieve this.


public void scrollFormCenter(String direction) {

                         Dimension size = driver.manage().window().getSize();
                         switch (direction) {

                         case "up":
                                             int x = size.width / 2;
                                             int endy = (int) (size.height * 0.75);
                                             int starty = (int) (size.height * 0.20);
                                             driver.swipe(x, starty, x, endy, 1000);
                                             break;

                         case "down":
                                             x = size.width / 2;
                                             starty = (int) (size.height * 0.75);
                                             endy = (int) (size.height * 0.20);
                                             driver.swipe(x, starty, x, endy, 1000);
                                             break;

                         case "left":
                                             int y = (int) size.height / 2;
                                             int startx= (int) (size.width * 0.15);
                                             int endx  = (int) (size.width * 0.75);
                                             driver.swipe(startx, y, endx, y, 1000);
                                             break;

                         case "right":
                                             y = (int) size.height / 2;
                                             endx = (int) (size.width * 0.15);
                                             startx = (int) (size.width * 0.85);
                                             driver.swipe(startx, y, endx, y, 1000);
                                             break;
                         }
    }


Call this function in your code like below:


scrollFormCenter(down)               //for scrolling down
scrollFormCenter(left)                    //for scrolling down
scrollFormCenter(right)                  //for scrolling down
scrollFormCenter(up)                      //for scrolling down