bootstrap之WaitForIdle&&Clear
2016-02-05 20:35
302 查看
(上篇文章写完才发现。说好的按顺序可是回头一看全然不是按顺序的)明明WaitForIdle才是第一个。哎,老了,后脑勺不行了。
上面的代码处理过程非常easy。首先都是获取命令里面的參数。然后初始化一个timeout私有变量,假设參数里不含时间。那么就用这个默认的时间。
然后调用uiautomator的UiDevice的对象里方法waitForIdle(),该方法就在timeout时间内界面上没有其它操作,处于空暇状态。这个就是封装了一下UiDevice的waitForIdle方法而已没啥可讲的。
Clear
Clear的方法中就看e1.clearText()方法,其它的我在click中都有涉及。
实际上调用的是uiautomator中的UiObject.clearTextField(),清楚文本框内的内容。
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); } }
上面的代码处理过程非常easy。首先都是获取命令里面的參数。然后初始化一个timeout私有变量,假设參数里不含时间。那么就用这个默认的时间。
然后调用uiautomator的UiDevice的对象里方法waitForIdle(),该方法就在timeout时间内界面上没有其它操作,处于空暇状态。这个就是封装了一下UiDevice的waitForIdle方法而已没啥可讲的。
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(),清楚文本框内的内容。
相关文章推荐
- bootstrap精简教程
- bootstraps4+flexbox
- 超棒的 15 款 Bootstrap UI 编辑器
- 3款强大的BootStrap的可视化制作工具推荐
- Bootstrap(Web前端CSS框架)
- Bootstrap_响应式网格系统
- ubuntu系统debootstrap的使用
- bootstrap3 ie8
- Bootstrap教程 之 网格系统和排版
- Bootstrap表单布局样式
- bootstrap 中popover的鼠标悬停下拉菜单效果
- bootstrap
- ASP.NET MVC使用Bootstrap系列(5)——创建ASP.NET MVC Bootstrap Helpers
- ASP.NET MVC使用Bootstrap系列(4)——使用JavaScript插件
- ASP.NET MVC使用Bootstrap系列(1)——开始使用Bootstrap
- BootStrap main 方法都做了什么?
- Bootstrap
- 让Bootstrap 3兼容IE8浏览器
- bootStrap ace tree例子 JAVA版本
- bootstrap table 整合dwr框架