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 ...
随机推荐
- 小数据池 is 和 ==的区别
小数据池 一.小数据池 1)代码块 python程序是由代码块构成的,一个代码块的文本作为pythont程序执行的单元 官方文档: A Python program is constructed fr ...
- Repo command reference
Repo command reference In this document init sync upload diff download forall prune start status Rep ...
- gg mirror
https://gufen.ga/ (无广告,原guso.ml,ggso.ga,guge.ga) https://a.aiguso.tk (无广告,体验良好) https://a.freedo.gq/ ...
- 00031_ArrayList集合中常用的方法
1.ArrayList集合提供的一些常用方法 import java.util.ArrayList; public class ArrayListDemo01 { public static void ...
- Java-转换Unicode和utf-8
package com.tj; import java.io.UnsupportedEncodingException; public class MyClass implements Cloneab ...
- python算法-快速排序
快速排序: 学习快速排序,要先复习下递归: 递归的2个条件: 1. 函数自己调用自己 2.有一个退出的条件 练习:基于递归下一个函数,计算n!并且求出当n等于10的值. n!=n * n-1*…..* ...
- Leetcode 373.查找和最小的k对数字
查找和最小的k对数字 给定两个以升序排列的整形数组 nums1 和 nums2, 以及一个整数 k. 定义一对值 (u,v),其中第一个元素来自 nums1,第二个元素来自 nums2. 找到和最小的 ...
- VS2010SP1修复补丁&Microsoft Visual Studio 2010 Service Pack 1
网上比较难找,官网找也容易找错,现在贴出来 补丁包下载地址:链接:https://pan.baidu.com/s/1_tFzXL6PaHiWk3JeRBw0ww 密码:z38k
- [Kubernetes]容器健康检查和恢复机制
在Kubernetes中,可以为Pod里的容器定义一个健康检查探针(Probe),这样Kubernetes会根据这个Probe的返回值决定这个容器的状态,而不是直接以容器是否允许(来自Docker返回 ...
- tab栏切换效果
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...