bootstrap之ScrollTo
ScrollTo
package io.appium.android.bootstrap.handler; import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiScrollable;
import com.android.uiautomator.core.UiSelector;
import io.appium.android.bootstrap.*;
import org.json.JSONException; import java.util.Hashtable; /**
* This handler is used to scroll to elements in the Android UI.
*
* Based on the element Id of the scrollable, scroll to the object with the
* text.
*
*/
public class ScrollTo 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()) {
return getErrorResult("A scrollable view is required for this command.");
} try {
Boolean result;
final Hashtable<String, Object> params = command.params();
final String text = params.get("text").toString();
final String direction = params.get("direction").toString(); final AndroidElement el = command.getElement(); if (!el.getUiObject().isScrollable()) {
return getErrorResult("The provided view is not scrollable.");
} final UiScrollable view = new UiScrollable(el.getUiObject().getSelector()); if (direction.toLowerCase().contentEquals("horizontal")
|| view.getClassName().contentEquals(
"android.widget.HorizontalScrollView")) {
view.setAsHorizontalList();
}
view.scrollToBeginning(100);
view.setMaxSearchSwipes(100);
result = view.scrollTextIntoView(text);
view.waitForExists(5000); // make sure we can get to the item
UiObject listViewItem = view.getChildByInstance(
new UiSelector().text(text), 0); // We need to make sure that the item exists (visible)
if (!(result && listViewItem.exists())) {
return getErrorResult("Could not scroll element into view: " + text);
}
return getSuccessResult(result);
} catch (final UiObjectNotFoundException e) {
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
} catch (final NullPointerException e) { // el is null
return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
} catch (final Exception e) {
return new AndroidCommandResult(WDStatus.UNKNOWN_ERROR, e.getMessage());
}
}
}
在uiautomator中有时候须要在一个滚动的list中找到某一个item。而这个item的位置又不定,这个时候我们能够通过UiScrollable的scrollTo来找到特定text的控件。而bootstrap的这个ScrollTo就是封装这样一种需求的。
首先推断控件是否是能够滚动的,然后创建UiScrollable对象,由于默认的滚动方式是垂直方向的,假设须要的是水平方向的的话。还要设置方向为水平。
view.setAsHorizontalList();
然后将滚动控件滚到最開始的地方,然后设置最大的搜索范围为100次。由于不可能永远搜索下去。
然后開始调用
view.scrollTextIntoView(text);
開始滚动,最后确认是否滚动到制定目标:
view.waitForExists(5000);
由于有可能有刷新到时间,所以调用方法到时候传入了时间5秒钟。
UiObject listViewItem = view.getChildByInstance(
new UiSelector().text(text), 0);
最后检查结果,获取制定text的对象,推断其是否存在然后返回对应结果给client。
bootstrap之ScrollTo的更多相关文章
- html template
https://wrapbootstrap.com/tag/single-page http://themeforest.net/ https://wrapbootstrap.com/themes h ...
- angularjs requeirjs配置相关
尝试了网上的yeoman generator 生成的脚手架项目不甚理想 npm install -g generator-angular-require yo angular-require 就不用那 ...
- Bootstrap结合BootstrapTable的使用,分为两种模试显示列表。 自适应表格
引用的css: <link href="@Url.Content("~/Css/bootstrap.min.css")" rel="styles ...
- bootstrap之Click大事
上一篇文章中谈到了bootstrap流程,本文开始把目光bootstrap它可以接受指令(从源代码视图的透视.因为appium该项目现在还处于不断更新,因此,一些指令已经实现.也许未来会实现一些.从视 ...
- Appium Android Bootstrap源码分析之命令解析执行
通过上一篇文章<Appium Android Bootstrap源码分析之控件AndroidElement>我们知道了Appium从pc端发送过来的命令如果是控件相关的话,最终目标控件在b ...
- Appuim源码剖析(Bootstrap)
Appuim源码剖析(Bootstrap) SkySeraph Jan. 26th 2017 Email:skyseraph00@163.com 更多精彩请直接访问SkySeraph个人站点:www. ...
- 手机自动化测试:appium源码分析之bootstrap三
手机自动化测试:appium源码分析之bootstrap三 研究bootstrap源码,我们可以通过代码的结构,可以看出来appium的扩展思路和实现方式,从中可以添加我们自己要的功能,针对app ...
- 手机自动化测试:appium源码分析之bootstrap二
手机自动化测试:appium源码分析之bootstrap二 在bootstrap项目中的io.appium.android.bootstrap.handler包中的类都是对应的指令类, priva ...
- 手机自动化测试:appium源码分析之bootstrap一
手机自动化测试:appium源码分析之bootstrap一 前言: poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.popte ...
随机推荐
- MPEG-4视频编码核心思想
1 引言 当今时代,信息技术和计算机互联网飞速发展,在此背景下,多媒体信息已成为人类获取信息的最主要载体,同时也成为电子信息领域技术开发和研究的热点.多媒体信息经数字化处理后具有易于加密.抗干扰能 ...
- 常见slave 延迟原因以及解决方法
一 序言在运维线上M-M 架构的MySQL数据库时,接收的比较多关于主备延时的报警: 点击(此处)折叠或打开 check_ins_slave_lag (err_cnt:1)critical-slav ...
- android-csv-variants
android-csv-variants https://github.com/zawn/android-csv-variants/ 目的 用于在Android Gradle构建时通过CSV文件配置V ...
- JSP标签:jsp内置标签、jstl标签、自定义标签
一.jsp标签的分类: 1)内置标签(动作标签): 不需要在jsp页面导入标签 2)jstl标签: 需要在jsp页面中导入标签 3)自定义标签 : 开发者自行定义,需要在jsp页面导入标签 1 ...
- C++枚举类型enum
为啥需要枚举类型 编程语言中的所有特性都是为了满足某种需求,达到某个目的还出现.不会莫名其妙的出现在那. 枚举可以用来保存一组属性的值.enum的全称是enumeration意思是列举 看着这句话可能 ...
- linux下ln命令
转自:http://www.cnblogs.com/peida/archive/2012/12/11/2812294.html ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位 ...
- POJ——2449Remmarguts' Date(A*+SPFA)
Remmarguts' Date Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 26504 Accepted: 7203 ...
- [BZOJ2523][Ctsc2001]聪明的学生
[BZOJ2523][Ctsc2001]聪明的学生 试题描述 一位教授逻辑学的教授有三名非常善于推理且精于心算的学生A,B和C.有一天,教授给他们三人出了一道题:教授在每个人脑门上贴了一张纸条并告诉他 ...
- 刷题总结——瞭望塔(bzoj1038)
题目: Description 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 我们可以用一条山的上方轮廓折线 ...
- Python脚本实现单据体首行过滤
编写的Python脚本 可以看到,实际代码只有3句,即实现单据体首行过滤代码(其实最最主要的是无需写组件动态即时注册),并有注册到[采购订单]"表单构建插件"上.界面运行时,实际效 ...