appium部分api
转自: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的更多相关文章
- Appium python API 总结
Appium python api 根据testerhome的文章,再补充一些文章里面没有提及的API [TOC] [1]find element driver 的方法 注意:这几个方法只能通过sel ...
- appium+python自动化☞appium python api大全
整理了一些常用的appium python api,供学习使用...
- Appium===Appium+Python API(转)
Appium+python自动化8-Appium Python API 前言: Appium Python API全集,不知道哪个大神整理的,这里贴出来分享给大家. 1.contexts contex ...
- 7、Appium常用API
嗯,官网已经介绍的很全了.会选几个常用API后期整理. Appium常用API地址:http://appium.io/docs/cn/writing-running-appium/appium-bin ...
- appium 常用API
''.appium api第二弹 锋利的python,这是初稿,2015/1/5 如有错误的地方,请同学们进行留言,我会及时予以修改,尽量整合一份ok的api 作者:Mads Spiral QQ:79 ...
- appium 常用api介绍(2)
前言:接着上一篇继续讲常用的一些api 参考博文:http://blog.csdn.net/bear_w/article/details/50330565 1.send_keys send_keys( ...
- appium python api收集
1.contexts contexts(self): Returns the contexts within the current session. 返回当前会话中的上下文,使用后可以识别H5页面的 ...
- appium 常用API使用总结!
将常用函数进行适用总结,后期在使用的过程中直接查找调用即可 获取界面属性.控件属性 1.current_activity:获取activity名称 device.current_activity 2. ...
- Appium Python API 中文版
Appium_Python_Api文档 1.contextscontexts(self): Returns the contexts within the current session. 返回当前会 ...
- Appium Python API
1.contexts contexts(self): Returns the contexts within the current session. 返回当前会话中的上下文,使用后可以识别H5页面的 ...
随机推荐
- Python标准库之csv(1)
Python标准库之csv(1) 1.Python处理csv文件之csv.writer() import csv def csv_write(path,data): with open(path,'w ...
- CodeForces contest/776 A+B+C题解
ICM Technex 2017 and Codeforces Round #400 (Div. 1 +Div.2,combined) A. A Serial Killer 谜一样的题意:每天从两个人 ...
- n&(n-1)的用途
最近做LeetCode上面的题目,发现很多题目都用到了n&(n-1).感觉真是神通广大,下面就目前所看到的一些用途总结一下: 1,求一个int类型数是否为2的幂 当n=4时,二进制为:0100 ...
- rabbitmq php 学习
参考文档:http://www.cnblogs.com/phpinfo/p/4104551...http://blog.csdn.net/historyasamirror/ar... 依赖包安装 yu ...
- 【Luogu】P2051中国象棋(DP)
题目链接 去看STDCALL的题解吧 #include<cstdio> #include<cctype> #define mod 9999973 inline long lon ...
- 源码分析 脱壳神器ZjDroid工作原理
0. 神器ZjDroid Xposed框架的另外一个功能就是实现应用的简单脱壳,其实说是Xposed的作用其实也不是,主要是模块编写的好就可以了,主要是利用Xposed的牛逼Hook技术实现的,下面就 ...
- oracle禁止插入、延迟插入方法
DATE_ADD(DATE_ADD(curdate(),INTERVAL +6 HOUR),INTERVAL +6 DAY) mysql取当前日期后6天,截止到6点钟的方法 --直接报错 CREATE ...
- STL中heap用法
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; ]={,, ...
- linux-起步
学习网站: linux中国开源社区 Vmware下载与安装 https://blog.csdn.net/Ywaken/article/details/78839005 https://blog.csd ...
- Codeforces 271D - Good Substrings [字典树]
传送门 D. Good Substrings time limit per test 2 seconds memory limit per test 512 megabytes input stand ...