appium常用方法

1.输入中文

在capabilities中增加两项设置:

capabilities.setCapability("unicodeKeyboard", "True"); 
capabilities.setCapability("resetKeyboard", "True");

2.发送文字

driver.findElementByName("请输入姓名").sendKeys("请输入姓名");

3.截屏并保存至本地 

File screen = driver.getScreenshotAs(OutputType.FILE); 
File screenFile = new File("d:\screen.png"); 
try { 
FileUtils.copyFile(screen, screenFile); //commons-io-2.0.1.jar中的api 
} catch (IOException e) { 
e.printStackTrace(); 
}

4.获取当前界面的activity,可用于断言是否跳转到预期的activity 

driver.currentActivity();

5.//打开通知栏界面 
driver.openNotifications();

6.//获取网络状态 
int status = driver.getNetworkConnection().value;

7.//启动其他应用,跨APP 
driver.startActivity("com.android.camera", ".CameraLauncher");

备注:一定要用AndroidDriver driver,AndroidDriver是appiumDriver的子类

8.安装APK

    public void add1() throws Exception{
        File directory=new File("E://zidongmsm.apk");
        driver.installApp(directory.getAbsolutePath());
        TimeUnit.SECONDS.sleep(5);     
        }

    public void add1() throws Exception{
        driver.installApp("E:\zidongmsm.apk");
}

 9.//拖动相机图标至日历图标位置 

new TouchAction(driver).longPress(driver.findElementByName("相机")) 
.moveTo(driver.findElementByName("日历")).release().perform();

 10.启动系统命令

      Runtime.getRuntime().exec("adb shell am start -W com.aurora.market/com.aurora.market.MarketMainActivity");

 参考文章:https://www.cnblogs.com/penghong2014/p/4275480.html

原文地址:https://www.cnblogs.com/longronglang/p/10319882.html