手机自动化测试:appium源码分析之bootstrap十二
手机自动化测试:appium源码分析之bootstrap十二
poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标。如果对课程感兴趣,请大家咨询qq:908821478。
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的对象,判断其是否存在然后返回相应结果给客户端。
手机自动化测试:appium源码分析之bootstrap十二的更多相关文章
- 手机自动化测试:appium源码分析之bootstrap十六
手机自动化测试:appium源码分析之bootstrap十六 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...
- 手机自动化测试:appium源码分析之bootstrap十五
手机自动化测试:appium源码分析之bootstrap十五 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...
- 手机自动化测试:appium源码分析之bootstrap十四
手机自动化测试:appium源码分析之bootstrap十四 poptest(www.poptest.cn)是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开 ...
- 手机自动化测试:appium源码分析之bootstrap十
手机自动化测试:appium源码分析之bootstrap十 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣, ...
- 手机自动化测试:appium源码分析之bootstrap三
手机自动化测试:appium源码分析之bootstrap三 研究bootstrap源码,我们可以通过代码的结构,可以看出来appium的扩展思路和实现方式,从中可以添加我们自己要的功能,针对app ...
- 手机自动化测试:appium源码分析之bootstrap二
手机自动化测试:appium源码分析之bootstrap二 在bootstrap项目中的io.appium.android.bootstrap.handler包中的类都是对应的指令类, priva ...
- 手机自动化测试:appium源码分析之bootstrap一
手机自动化测试:appium源码分析之bootstrap一 前言: poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.popte ...
- 手机自动化测试:appium源码分析之bootstrap十七
手机自动化测试:appium源码分析之bootstrap十七 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...
- 手机自动化测试:appium源码分析之bootstrap十三
手机自动化测试:appium源码分析之bootstrap十三 poptest(www.poptest.cn)是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开 ...
随机推荐
- C# 6 与 .NET Core 1.0 高级编程 - 40 ASP.NET Core(下)
译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 40 章 ASP.NET Core(下)),不对的地方欢迎指出与交流. 章节出自<Professiona ...
- .net是最牛逼的开发平台没有之一
.net是最牛逼的开发平台没有之一 .net是最牛逼的开发平台没有之一 .net是最牛逼的开发平台没有之一 .net是最牛逼的开发平台没有之一 .net是最牛逼的开发平台没有之一 .net是最牛逼的开 ...
- 关于boostrap的thead固定tbody滚动
原文地址:http://blog.csdn.net/bbsyi/article/details/51126041# 1 <!DOCTYPE html> 2 <html> 3 & ...
- 学习笔记——Java类和对象
今天学习了Java的类和对象的相关知识,由于Java面向对象的编程的思想和C++几乎一样,所以需要更多的关注Java的一些不同之处. 1.类 1.1 在类这一块,除了基本的成员变量,成员方法,构造函数 ...
- java从入门到卖肠粉系列
java从入门到卖肠粉系列 注:本教程只是从JAVA基础开始,绝对不会跟公司有任何利益冲突,更不会出现一行公司项目的代码 QQ群:9547527 推荐用土豆,百度去上传太慢,百度云在线播放还要转码.. ...
- java数组、泛型、集合在多态中的使用及对比
我们在使用数组,泛型集合的过程中不可避免的会碰到多态,或者说什么情况下能如何使用父数组引用子数组(集合.泛型)呢? 数组在多态中的使用 元素为父类型的数组引用可指向元素为子类型的数组对象 当数组被调用 ...
- linux 下apache2 安装
Apache安装要求 安装APR.APR-Util.PCRE,gcc-c++等包 Apache HTTP Server http://httpd.apache.org/download.cgi#ap ...
- Linux i2c子系统(三) _解决probe无法执行
如果你也遇到了填充了id_match_table,compitible怎么看都一样,但probe就是不执行(让我哭一会),你可以回头看一下上一篇的模板,我们这里虽然使用的是设备树匹配,但和platfo ...
- smarty模板做人员表信息删除,修改 里面的性别单选按钮民族下拉,另外登录进去可以显示姓名
首先登录进去可以显示姓名 smarty模板做人员表信息删除,删除的时候有提示框确定删除吗. 修改 里面的性别单选按钮,要修改谁有默认选中,用了变量调节器 民族位置做下拉,用<{foreach}& ...
- win7下使用git
1 安装git for window 2 安装tortoiseGit 3 生成public key 3.1 打开git bash 3.2 创建~/.ssh文件夹 mkdir ~/.ssh 3.3 配置 ...