手机自动化测试:appium源码分析之bootstrap二

 

在bootstrap项目中的io.appium.android.bootstrap.handler包中的类都是对应的指令类,

private static HashMap<String, CommandHandler> map = new HashMap<String, CommandHandler>();

static {
map.put("waitForIdle", new WaitForIdle());
map.put("clear", new Clear());
map.put("orientation", new Orientation());
map.put("swipe", new Swipe());
map.put("flick", new Flick());
map.put("drag", new Drag());
map.put("pinch", new Pinch());
map.put("click", new Click());
map.put("touchLongClick", new TouchLongClick());
map.put("touchDown", new TouchDown());
map.put("touchUp", new TouchUp());
map.put("touchMove", new TouchMove());
map.put("getText", new GetText());
map.put("setText", new SetText());
map.put("getName", new GetName());
map.put("getAttribute", new GetAttribute());
map.put("getDeviceSize", new GetDeviceSize());
map.put("scrollTo", new ScrollTo());
map.put("find", new Find());
map.put("getLocation", new GetLocation());
map.put("getSize", new GetSize());
map.put("wake", new Wake());
map.put("pressBack", new PressBack());
map.put("dumpWindowHierarchy", new DumpWindowHierarchy());
map.put("pressKeyCode", new PressKeyCode());
map.put("longPressKeyCode", new LongPressKeyCode());
map.put("takeScreenshot", new TakeScreenshot());
map.put("updateStrings", new UpdateStrings());
map.put("getDataDir", new GetDataDir());
map.put("performMultiPointerGesture", new MultiPointerGesture());
map.put("openNotification", new OpenNotification());
}

我们来看WaitForIdle:

package io.appium.android.bootstrap.handler;

import com.android.uiautomator.core.UiDevice;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import org.json.JSONException;

import java.util.Hashtable;

/**
* This handler is used to clear elements in the Android UI.

* Based on the element Id, clear that element.

*/
public class WaitForIdle extends CommandHandler {

/*
* @param command The {@link AndroidCommand}

* @return {@link AndroidCommandResult}

* @throws JSONException

* @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android.
* bootstrap.AndroidCommand)
*/
@Override
public AndroidCommandResult execute(final AndroidCommand command)
throws JSONException {
final Hashtable<String, Object> params = command.params();
long timeout = 10;
if (params.containsKey("timeout")) {
timeout = (Integer) params.get("timeout");
}

UiDevice d = UiDevice.getInstance();
d.waitForIdle(timeout);
return getSuccessResult(true);
}
}

首先是获取命令里面参数,然后初始化一个timeout私有变量,如果参数里不含时间,那么就用这个默认的时间。然后调用uiautomator的UiDevice的对象里方法waitForIdle(),该方法就在timeout时间内界面上没有其他操作,处于空闲状态。

Clear:

package io.appium.android.bootstrap.handler;

import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import org.json.JSONException;

/**
* This handler is used to clear elements in the Android UI.

* Based on the element Id, clear that element.

*/
public class Clear extends CommandHandler {

/*
* @param command The {@link AndroidCommand}

* @return {@link AndroidCommandResult}

* @throws JSONException

* @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android.
* bootstrap.AndroidCommand)
*/
@Override
public AndroidCommandResult execute(final AndroidCommand command)
throws JSONException {
if (command.isElementCommand()) {
try {
final AndroidElement el = command.getElement();
el.clearText();
return getSuccessResult(true);
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
e.getMessage());
} catch (final Exception e) { // handle NullPointerException
return getErrorResult("Unknown error clearing text");
}
}
return getErrorResult("Unknown error");
}
}

Clear的方法中就看e1.clearText()方法,其他的我在click中都有涉及。
private final UiObject el;
public void clearText() throws UiObjectNotFoundException {
el.clearTextField();
}
实际上调用的是uiautomator中的UiObject.clearTextField(),清除文本框内的内容。

手机自动化测试:appium源码分析之bootstrap二的更多相关文章

  1. 手机自动化测试:appium源码分析之bootstrap三

    手机自动化测试:appium源码分析之bootstrap三   研究bootstrap源码,我们可以通过代码的结构,可以看出来appium的扩展思路和实现方式,从中可以添加我们自己要的功能,针对app ...

  2. 手机自动化测试:appium源码分析之bootstrap一

    手机自动化测试:appium源码分析之bootstrap一   前言: poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.popte ...

  3. 手机自动化测试:appium源码分析之bootstrap十七

    手机自动化测试:appium源码分析之bootstrap十七   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...

  4. 手机自动化测试:appium源码分析之bootstrap十六

    手机自动化测试:appium源码分析之bootstrap十六   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...

  5. 手机自动化测试:appium源码分析之bootstrap十五

    手机自动化测试:appium源码分析之bootstrap十五   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...

  6. 手机自动化测试:appium源码分析之bootstrap十四

    手机自动化测试:appium源码分析之bootstrap十四   poptest(www.poptest.cn)是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开 ...

  7. 手机自动化测试:appium源码分析之bootstrap十三

    手机自动化测试:appium源码分析之bootstrap十三   poptest(www.poptest.cn)是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开 ...

  8. 手机自动化测试:appium源码分析之bootstrap十一

    手机自动化测试:appium源码分析之bootstrap十一   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...

  9. 手机自动化测试:appium源码分析之bootstrap十二

    手机自动化测试:appium源码分析之bootstrap十二   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...

随机推荐

  1. 如何用Visual Studio 2008 写汇编程序?

    如何用Visual Studio 2008写汇编程序? 最近在上夏季小学期,在学汇编语言,关于用什么编辑环境一直很纠结.很想找到一个比较好的IDE,但是试了几个像RadASM之类的,发现还不是很满意. ...

  2. Ant学习总结1

    一.Ant简介 Ant是用来编译/运行/测试java程序,构建.包装和发布过程中几乎每一件事都可以由Ant的任务来处理. 二.Ant管理项目    当开始一个新的项目时,首先应该编写Ant的构建文件, ...

  3. css3瀑布流

    css3虽然可以实现,不过要是真的运用到项目中还是老老实实写js吧 .container{ /*列的宽度*/ column-width:160px; -webkit-column-width:160p ...

  4. oracle系列笔记(2)---多表查询

    多表查询     这篇文章主要讲四点: (1)oracle多表查询    (2)SQL99标准的连接查询   (3)子查询     (4)分级查询 oracle多表查询有两种方式,一种是oracle所 ...

  5. bootstrap select2 参数详解

    Select2使用示例地址: https://select2.github.io/examples.html Select2参数文档说明: https://select2.github.io/opti ...

  6. angular : direative :comunication 指令之间的通讯

    在网络上可以找到多种指令之间的通讯 · $on,$emit,$boardcast (向上或向下冒泡) · 指令return的required (^)向上一个scope通讯,前提要先给scope一个na ...

  7. HTML文档中使用JavaScript和css

    HTML文档中使用JavaScript和css 引入css 内嵌式引入:将css代码写在HTML中的style标签里面 <!DOCTYPE html> <html> <h ...

  8. 解决clipboard手机端无法复制的一种思路

    最近,做了一个切图的小项目 主要内容是微信号的推广页面,上面会有精美的图片和微信号:) 点击按钮,会复制到粘贴板上,自己去微信里面粘贴搜索:),懒人会进行一系列复杂操作么,不看好 首先,百度了一下,看 ...

  9. FaceNet---深度学习与人脸识别的二次结合

    今天我给大家带来一篇来自谷歌的文章,众所周知,谷歌是全世界最有情怀,最讲究技术的公司,比我们天朝的莆田广告商良心多了.还有就是前段时间的最强大脑,莆田广告商的那个小机器,也就忽悠忽悠行外人了,懂的人深 ...

  10. MegaCli 安装过程

    首先说下自己遇到的坑: 百度搜索了一篇关于安装 MegaCli 的文章,于是乎就开始安装,装完之后获取不到 raid 的信息,后来发现是版本问题,就又搜索了一堆文章,最后搞定了 [root@web-0 ...