转自:http://www.aichengxu.com/view/41510

使用的语言是java,appium的版本是1.3.4,java-client的版本是java-client-2.1.0,建议多参考java-client-2.1.0-javadoc。

1.使用AndroidDriver,其已经继承了AppiumDriver

        private AndroidDriver driver;

	@Before
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.android.settings");
capabilities.setCapability("appActivity", ".Settings"); driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
} @After
public void tearDown() throws Exception {
driver.quit();
}

2.截屏并保存至本地

                //截屏并保存至本地
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();
}

3.push文件、pull文件

        	File file = new File("d:\\test.txt"); //test.txt内容为"test"
String content = null;
try {
content = FileUtils.readFileToString(file);
} catch (IOException e) {
e.printStackTrace();
} byte[] data = Base64.encodeBase64(content.getBytes());
driver.pushFile("sdcard/test.txt", data); byte[] resultDate = driver.pullFile("sdcard/test.txt");
System.out.println(new String(Base64.decodeBase64(resultDate))); //打印结果为"test"

4.

        //获取当前界面的activity,可用于断言是否跳转到预期的activity
driver.currentActivity();

5.

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

6.

        //获取网络状态
int status = driver.getNetworkConnection().value;
System.out.println(status); //设置网络状态
driver.setNetworkConnection(new NetworkConnectionSetting(status));
//或者
driver.setNetworkConnection(new NetworkConnectionSetting(false, true, false));

7.

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

8.

        //自动滑动列表
driver.scrollTo("text");
//或者
driver.scrollToExact("text");

9.

                //安装APP
driver.installApp(appPath); //判断应用是否已安装
driver.isAppInstalled("package name");

10.

        //拖动相机图标至日历图标位置
new TouchAction(driver).longPress(driver.findElementByName("相机"))
.moveTo(driver.findElementByName("日历")).release().perform();

11.

                //锁屏
driver.lockScreen(2); //判断是否锁屏
driver.isLocked();

12.

                //发送按键事件
driver.sendKeyEvent(AndroidKeyCode.HOME);

13.

<span style="color:#ff0000;"> </span>
//通过uiautomator定位clickable属性为true的元素并点击
driver.findElementByAndroidUIAutomator("new UiSelector().clickable(true)").click(); //相同属性的元素使用List存放
List<WebElement> elements = driver.findElementsByClassName("class name");
elements.get(0).click(); //点击List中的第一个元素
//tap,点击元素位置
driver.tap(1, driver.findElementByName("日期和时间"), 0);

appium部分api的更多相关文章

  1. Appium python API 总结

    Appium python api 根据testerhome的文章,再补充一些文章里面没有提及的API [TOC] [1]find element driver 的方法 注意:这几个方法只能通过sel ...

  2. appium+python自动化☞appium python api大全

    整理了一些常用的appium python api,供学习使用...

  3. Appium===Appium+Python API(转)

    Appium+python自动化8-Appium Python API 前言: Appium Python API全集,不知道哪个大神整理的,这里贴出来分享给大家. 1.contexts contex ...

  4. 7、Appium常用API

    嗯,官网已经介绍的很全了.会选几个常用API后期整理. Appium常用API地址:http://appium.io/docs/cn/writing-running-appium/appium-bin ...

  5. appium 常用API

    ''.appium api第二弹 锋利的python,这是初稿,2015/1/5 如有错误的地方,请同学们进行留言,我会及时予以修改,尽量整合一份ok的api 作者:Mads Spiral QQ:79 ...

  6. appium 常用api介绍(2)

    前言:接着上一篇继续讲常用的一些api 参考博文:http://blog.csdn.net/bear_w/article/details/50330565 1.send_keys send_keys( ...

  7. appium python api收集

    1.contexts contexts(self): Returns the contexts within the current session. 返回当前会话中的上下文,使用后可以识别H5页面的 ...

  8. appium 常用API使用总结!

    将常用函数进行适用总结,后期在使用的过程中直接查找调用即可 获取界面属性.控件属性 1.current_activity:获取activity名称 device.current_activity 2. ...

  9. Appium Python API 中文版

    Appium_Python_Api文档 1.contextscontexts(self): Returns the contexts within the current session. 返回当前会 ...

  10. Appium Python API

    1.contexts contexts(self): Returns the contexts within the current session. 返回当前会话中的上下文,使用后可以识别H5页面的 ...

随机推荐

  1. Consecutive Subsequence (DP+map)

    You are given an integer array of length nn. You have to choose some subsequence of this array of ma ...

  2. 爆炸几何之 CCPC网络赛 I - The Designer (笛卡尔定理)

    本文版权归BobHuang和博客园共有,不得转载.如想转载,请联系作者,并注明出处.   Nowadays, little hahahaha got a problem from his teache ...

  3. 08-为数组和arguments

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  4. 【Luogu】P2324骑士精神(IDA*)

    题目链接 当guess>limit-deep的时候return就好了. guess是估价函数,值为不在自己地盘上的骑士个数.limit是本次迭代阈值.deep是已经走了多少步. 这个优化是显然的 ...

  5. POJ 3693 Maximum repetition substring ——后缀数组

    重复次数最多的字串,我们可以枚举循环节的长度. 然后正反两次LCP,然后发现如果长度%L有剩余的情况时,答案是在一个区间内的. 所以需要找到区间内最小的rk值. 两个后缀数组,四个ST表,$\Thet ...

  6. TeraTerm设定(解决日文乱码问题)

    首先,字体Font的MS Gothic是有Japanese的,设置为这个比较保险. 其次,在General Setup里将Language设为:English. 原理是什么我也不清楚,试了几个选择,就 ...

  7. 【图论】bnuoj 52810 Splitting the Empire

    acm.bnu.edu.cn/v3/contest_show.php?cid=9208#problem/G [题意] 给定一个无向图,要求把这个无向图的点划分到不同的集合里,使得每个集合的点之间两两没 ...

  8. Java的反射机制和动态代理

    介绍Java注解的时候,多次提到了Java的反射API.与javax.lang.model不同的是,通过反射API可以获取程序在运行时刻的内部结构.反射API中提供的动态代理也是非常强大的功能,可以原 ...

  9. POJ3345 Bribing FIPA

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5021   Accepted: 1574 Description There ...

  10. maven自动导入包失败

    pom.xml文件依赖添加后,让maven自动导入包,老是失败,文件夹中有其他文件,就是缺少jar文件 解决: // 进入pom.xml所在的文件夹,执行下面的命令,下载jar包 mvn -f pom ...