代码如下:
public static void main(String[] args) {
try {
AndroidDriver driver;
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability("automationName", "Appium");//appium做自动化
// // cap.setCapability("app", "C:\\software\\jrtt.apk");//安装apk
//cap.setCapability("browserName", "chrome");//设置HTML5的自动化,打开谷歌浏览器
cap.setCapability("deviceName", "S4");//设备名称
cap.setCapability("platformName", "Android"); //安卓自动化还是IOS自动化
cap.setCapability("platformVersion", "4.4"); //安卓操作系统版本
cap.setCapability("udid", "192.168.2.101:5555"); //设备的udid (adb devices 查看到的)
cap.setCapability("appPackage", "com.android.chrome");//被测app的包名
cap.setCapability("appActivity", "com.google.android.apps.chrome.ChromeTabbedActivity");//被测app的入口Activity名称
cap.setCapability("unicodeKeyboard", "True"); //支持中文输入
cap.setCapability("resetKeyboard", "True"); //支持中文输入,必须两条都配置
cap.setCapability("noSign", "True"); //不重新签名apk
cap.setCapability("newCommandTimeout", "40"); //没有新命令,appium30秒退出
driver= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap);//把以上配置传到appium服务端并连接手机
//隐式等待
Thread.sleep(10000);
driver.get("https://www.baidu.com");
Thread.sleep(10000);
driver.findElementById("index-kw").sendKeys("新梦想软件测试");
driver.findElementById("index-bn").click();
} catch (Exception e) {
// TODO: handle exception
}
}
原文:http://www.cnblogs.com/beitha/p/6527206.html