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

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

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

    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.截屏并保存至本地

?

1

2

3

4

5

6

7

8

        //截屏并保存至本地

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文件

?

1

2

3

4

5

6

7

8

9

10

11

12

13

    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.

?

1

2

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

driver.currentActivity();

5.

?

1

2

//打开通知栏界面

driver.openNotifications();

6.

?

1

2

3

4

5

6

7

8

//获取网络状态

int status = driver.getNetworkConnection().value;

System.out.println(status);

//设置网络状态

driver.setNetworkConnection(new NetworkConnectionSetting(status));

//或者

driver.setNetworkConnection(new NetworkConnectionSetting(falsetruefalse));

7.

?

1

2

//启动其他应用,跨APP

driver.startActivity("com.android.camera"".CameraLauncher");

8.

?

1

2

3

4

//自动滑动列表

driver.scrollTo("text");

//或者

driver.scrollToExact("text");

9.

?

1

2

3

4

5

        //安装APP

driver.installApp(appPath);

//判断应用是否已安装

driver.isAppInstalled("package name");

10.

?

1

2

3

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

new TouchAction(driver).longPress(driver.findElementByName("相机"))

.moveTo(driver.findElementByName("日历")).release().perform();

11.

?

1

2

3

4

5

        //锁屏

driver.lockScreen(2);

//判断是否锁屏

driver.isLocked();

12.

?

1

2

        //发送按键事件

driver.sendKeyEvent(AndroidKeyCode.HOME);

13.

?

1

2

3

4

5

6

7

8

9

<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);</webel

getAppStrings()

默认系统语言对应的Strings.xml文件内的数据。

driver.getAppStrings(String language)

查找某一个语言环境对应的字符串文件Strings.xml内数据

sendKeyEvent(int key)

按下某个键,具体哪个键由key值决定,key值定义在AndroidKeyCode类中

sendKeyEvent(int key, Integer metastate)

按下某个键的同时按下附加键(Ctrl/Alt/Shift等),具体是哪些键,由key值(AndroidKeyCode类中定义)和metastate(AndroidKeyMetastate类中定义)决定。

currentActivity()

获取当前activity,比如(.ApiDemos)

isAppInstalled(String bundleId)

根据bundleId来判断该应用是否已经安装

installApp(String appPath)

安装app,appPath为应用的本地路径

removeApp(String bundleId)

卸载app.bundleId在android中代表的是报名,而在ios中有专门的bundleId号。

closeApp()

关闭应用,其实就是按home键把应用置于后台

launchApp()

启动应用

resetApp()

先closeApp然后在launchAPP

pushFile(String remotePath, byte[] base64Data)

将字符数组用64位格式写到远程目录的某个文件中。也可以理解为把本地文件push到设备上。

pullFile(String remotePath)

将设备上的文件pull到本地硬盘上

pullFolder(String remotePath)

将设备上的文件夹pull到本地硬盘上,一般远程文件为/data/local/tmp下的文件。

setNetworkConnection(NetworkConnectionSetting connection)

设置手机的网络连接状态,可以开关蓝牙、wifi、数据流量。通过NetworkConnectionSetting中的属性来设置各个网络连接的状态。

getNetworkConnection()

得到当前网络的状态

openNotifications()

打开通知栏

runAppInBackground(int seconds)

与resetApp类似,区别是resetApp关闭后立即启动,而这个方法是关闭后等待seconds秒后再启动。

hideKeyboard()

ios隐藏键盘

hideKeyboard(String strategy, String keyName)

隐藏键盘,只能用于ios上。

performTouchAction(TouchAction touchAction)

执行一个touch动作,该touch动作是由TouchAction封装的。

performMultiTouchAction(MultiTouchAction multiAction)

执行多步touch动作,由MultiTouchAction封装的多步操作。

tap(int fingers, WebElement element, int duration)

点击element控件中心点按下,duration*5毫秒秒后松开,如此重复fingers次。

tap(int fingers, int x, int y, int duration)

点击(x,y)点按下,duration*5毫秒后松开,如此重复fingers次。

swipe(int startx, int starty, int endx, int endy, int duration)

从(startx,starty)滑到(endx,endy),分duration步滑,每一步用时是5毫秒。

pinch(WebElement el)

2个手指操作控件,从对角线向中心点滑动。

pinch(int x, int y)

以(x,y)为基准,计算得出(x,y-100),(x,y+100)两个点,然后2个手指按住这两个点同时滑到(x,y)

zoom(WebElement el)

与pinch(el)的动作刚好相反。两个手指由控件的中心点慢慢向控件的左顶点后右底点滑动。

zoom(int x, int y)

和pinch(x,y)相反。两个手指从(x,y)点开始向(x,y-100)和(x,y+100)滑动。

getNamedTextField(String name)

一般用在ios中。根据accessibility id获得控件对象。

endTestCoverage(String intent, String path)

结束测试覆盖率的检测。(没用过,不太了解)path为.ec文件的路径。

lockScreen(int seconds)

锁屏多少秒后解锁(使用的时候提示还没实现该方法)

shake()

模拟摇晃手机(目前还没实现)

scrollTo(String text)

滚动到某个text属性为指定的字符串的控件

scrollToExact(String text)

滚动到某个text属性包含传入的字符串的控件

context(String name)

设置上下文

getContextHandles()

可用上下文

getContext()

当前上下文

rotate(ScreenOrientation orientation)

设置屏幕横屏或者竖屏

getOrientation()

获取当前屏幕的方向

findElementByIosUIAutomation(String using)

利用ios中的uiautomation中的属性来获取控件

findElementsByIosUIAutomation(String using)

和上面一样,不过获得的是多个控件

findElementByAndroidUIAutomator(String using)

利用android的uiautoamtor中的属性来获取单个控件。

findElementsByAndroidUIAutomator(String using)

和上面一样,但是该方法获得是多个控件

findElementByAccessibilityId(String using)

利用accessibility id来获取单个控件

findElementsByAccessibilityId(String using)

利用accessibility id来获得多个控件

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. HDU 2254 奥运(矩阵高速幂+二分等比序列求和)

    HDU 2254 奥运(矩阵高速幂+二分等比序列求和) ACM 题目地址:HDU 2254 奥运 题意:  中问题不解释. 分析:  依据floyd的算法,矩阵的k次方表示这个矩阵走了k步.  所以k ...

  2. 使用Navicat连接阿里云服务器上的MySQL数据库

    1.首先打开Navicat,文件>新建连接> 2,两张连接方法 1>常规中输入数据库的主机名,端口,用户名,密码 这种直接连就可以了 第2种方法: 常规中输入数据库的信息,主机名用l ...

  3. Make Docker Image On Ubuntu17.10

    1.拉取基础镜像 docker pull ubuntu 2.查看镜像 docker images 3.启动一个容器 docker run -it ubuntu 4.查找运行的容器ID docker p ...

  4. WebAPI实现移动端上传头像接口

    测试时可以直接使用PostMan模拟发送请求 /// <summary> /// 手机端上传头像接口 /// </summary> /// <param name=&qu ...

  5. 用python解析html--SGMLParser

    sgmllib.py 包含一个重要的类: SGMLParser.SGMLParser 将 HTML 分解成有用的片段, 比如开始标记和结束标记.一旦它成功地分解出某个数据为一个有用的片段,它会根据 所 ...

  6. 第9步:ASMCA创建磁盘组

    注意,创建磁盘组时需要以grid用户身份执行,在那之前可能需要以root身份执行xhost+,即命令: 代码1 [root@sgdb1~]# xhost+ [root@sgdb1~]# su – gr ...

  7. Mac 终端命令行颜色高亮显示

    一.颜色高亮显示 针对terminal采用bash模式: 编辑 ~/.bash_profile, 加入以下代码: export CLICOLOR=1 export LSCOLORS=gxfxaxdxc ...

  8. javascript 字符串进行 utf8 编码的方法(转)

    实践中碰到了一个大问题,在 javascript 中,可能有一些中文字符串,我们想将其进行二进制流编码的时候,需要将其转换为 utf8 的编码. 也就是说,输入的是一个字符串:'呆滞的慢板今天挣了10 ...

  9. NHibernate 1.0 Released 版本发布了

    NHibernate is a port of Hibernate to the .NET platform. Hibernate is the leading open-source object- ...

  10. 【BZOJ3207】花神的嘲讽计划Ⅰ Hash+主席树

    [BZOJ3207]花神的嘲讽计划Ⅰ Description 背景 花神是神,一大癖好就是嘲讽大J,举例如下: “哎你傻不傻的![hqz:大笨J]” “这道题又被J屎过了!!” “J这程序怎么跑这么快 ...