here is my code :
package vishnu;
import java.io.File;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;
public class Automation {
static Dimension size;
@SuppressWarnings("rawtypes")
private static AndroidDriver driver;
public static void main(String[] args) throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/apk/");
File app = new File(appDir, "sample.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "Dell");
capabilities.setCapability("platformVersion", "4.4.4");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.vishnu.sample");
capabilities.setCapability("appActivity","com.vishnu.sample.activities.ClientLoginActivity");
driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(17000);
swipe();
ClientLogin();
quit();
}
@Test
public static void swipe() throws Exception {
//Get the size of screen.
size = driver.manage().window().getSize();
System.out.println(size);
int startx = (int) (size.width * 0.90);
int endx = (int) (size.width * 0.10);
int starty = size.height / 2;
System.out.println("startx = " + startx + " ,endx = " + endx + " , starty = " + starty);
//Swipe from Right to Left.
driver.swipe(startx, starty, endx, starty, 1000);
Thread.sleep(3000);
}
@Test
public static void ClientLogin() throws Exception
{
WebElement User = driver.findElement(By.id("com.sample.ngo:id/etUserName"));
User.click();
User.sendKeys("xxxx");
driver.hideKeyboard();
WebElement Pass = driver.findElement(By.id("com.sample.ngo:id/etPassword"));
Pass.click();
Pass.sendKeys("xxxx");
driver.hideKeyboard();
WebElement signin = driver.findElementById("com.sample.ngo:id/btnSignIn");
signin.click();
Thread.sleep(3000);
}
@AfterTest
public static void quit() throws Exception {
driver.quit();
Thread.sleep(1000);
}
}
Thanks in Advance