Selenium With Java and Python For Mobile Apps & Web Apps......!

Thursday, 2 June 2016

How to Automate ios Application using Appium.

package com.flipkart;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;

public class IosE2e {

public static void main(String args[]) throws MalformedURLException, InterruptedException {
DesiredCapabilities cap=new DesiredCapabilities();
IOSDriver dr;
String appPath = "Users/pardeep.k//Documents//Flipkart.app";
File f = new File("//Users//pardeep.k//Documents//", "Flipkart.app");
cap.setCapability("deviceName", "iPhone 5s");
cap.setCapability("PlatformVersion", "8.1");
cap.setCapability("PlatformName", "iOS");
cap.setCapability("app", f);
dr=new IOSDriver(new  URL("http://127.0.0.1:4723/wd/hub"), cap);
Thread.sleep(7000);
dr.findElement(By.name("Log in")).click();
Thread.sleep(5000);
dr.findElement(By.name("emailTextField")).sendKeys("*********");
dr.findElement(By.name("passwordTextField")).sendKeys("**********");
dr.findElement(By.name("Log in")).click();

//dr.findElement(By.name("mobileTextField")).sendKeys("*********");
Thread.sleep(5000);

}

}

How to Start Appium Server using Coding in MAC.

package com.flipkart;

import java.io.IOException;

public class AppiumLaunch {
public static String APPIUMSERVERSTART = "/Users/pardeep.k/local/bin/appium";
  public static void startAppiumServer() throws IOException, InterruptedException {
       
            ProcessBuilder pb = new ProcessBuilder(APPIUMSERVERSTART);
            pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
            pb.redirectError(ProcessBuilder.Redirect.INHERIT);
            Process process = pb.start();
          Runtime runtime = Runtime.getRuntime();
            process = runtime.exec(APPIUMSERVERSTART);
            Thread.sleep(5000);
            if (process != null) {
                System.out.println("Appium server started");
            }
       
    }
public static void main(String[] args) throws IOException, InterruptedException {
AppiumLaunch.startAppiumServer();
}

}

How to launch Hike Android App using Selenium and Appium .

package com.flipkart;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;

public class HikeMessanger {
static WebDriver wd;
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability("deviceName", "Moto G(2nd Generation)");
cap.setCapability("PlatformVersion", "5.1.1");
cap.setCapability("PlatformName", "Android");
cap.setCapability("appPackage", "com.bsb.hike");
cap.setCapability("appActivity", "com.bsb.hike.ui.HomeActivity");

wd=new AndroidDriver(new  URL("http://127.0.0.1:4723/wd/hub"), cap);

wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

wd.findElement(By.xpath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.support.v7.widget.LinearLayoutCompat[1]/android.widget.TextView[1]")).click();

wd.findElement(By.xpath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.EditText[1]")).sendKeys("abc");

wd.findElement(By.xpath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.widget.FrameLayout[2]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.ListView[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.ImageView[1]")).click();

wd.findElement(By.xpath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.EditText[1]")).sendKeys("Hello");

wd.findElement(By.xpath("/")).sendKeys("hi");

wd.findElement(By.xpath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]/android.widget.RelativeLayout[1]/android.widget.ImageButton[2]")).click();

wd.close();
}


}

Translate

Popular Posts

Total Pageviews