Hi Friends, below is the sample code written for opening chrome browser in your Android device.
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import io.appium.java_client.AppiumDriver;
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class Appiumweb {
private WebDriver driver;
@BeforeMethod
public void setup() throws MalformedURLException
{
//File classpathroute= new File(System.getProperty("user.dir"));
//File appdir=new File (classpathroute,"D://automation//AppiumTest//Application");
//File appDir = new File(classpathroute, "Application");
//File app=new File(appDir, "ApiDemos-debug.apk");
//capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4.4");
capabilities.setCapability("browserName", "Chrome");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
//Note Below code is for opening any Android application in Android device.
/* capabilities.setCapability("deviceName","Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity", ".ApiDemos");
driver=new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);*/
}
@Test
public void apiDemo() throws InterruptedException{
driver.get("http://jaingourav999.blogspot.com");
String pagetitle=driver.getCurrentUrl();
System.out.println("The current page title is"+ pagetitle);
Thread.sleep(10000l);
}
@AfterMethod
public void tearDown() throws Exception {
driver.quit();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import io.appium.java_client.AppiumDriver;
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class Appiumweb {
private WebDriver driver;
@BeforeMethod
public void setup() throws MalformedURLException
{
//File classpathroute= new File(System.getProperty("user.dir"));
//File appdir=new File (classpathroute,"D://automation//AppiumTest//Application");
//File appDir = new File(classpathroute, "Application");
//File app=new File(appDir, "ApiDemos-debug.apk");
//capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4.4");
capabilities.setCapability("browserName", "Chrome");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
//Note Below code is for opening any Android application in Android device.
/* capabilities.setCapability("deviceName","Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity", ".ApiDemos");
driver=new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);*/
}
@Test
public void apiDemo() throws InterruptedException{
driver.get("http://jaingourav999.blogspot.com");
String pagetitle=driver.getCurrentUrl();
System.out.println("The current page title is"+ pagetitle);
Thread.sleep(10000l);
}
@AfterMethod
public void tearDown() throws Exception {
driver.quit();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
No comments:
Post a Comment