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

 

poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标。如果对课程感兴趣,请大家咨询qq:908821478,今天是移动端测试开发课程开课,学员们学习热情很高。我们发现测试培训一个有趣的特点,周末学习提高的女孩子多,就业培训参加的男孩子比例高,

概念:pinchIn和pinchOut

a.2个手指同时按住A和B,同时将A滑向A1,B滑向B1,称为pinchIn

b.2个手指同时按住A1和B1,同时将A1滑向A,B1滑向B,成为pinchOut.

那么Pinch类就是接受这一指令的,传入的参数有方向direction,percent代表滑到对角线百分之几停止,steps代表滑到时间,一个step代表5毫秒。根据direction来判断是调用UiObject.pinchIn和UiObject.pinchOut.

Pinch代码:

package io.appium.android.bootstrap.handler;

import com.android.uiautomator.core.UiObjectNotFoundException;

import io.appium.android.bootstrap.*;

import org.json.JSONException;

import java.util.Hashtable;

/**

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

*

* Based on the element Id, pinch in/out that element.

*

*/

public class Pinch extends CommandHandler {

/*

* @param command The {@link AndroidCommand} used for this handler.

*

* @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();

AndroidElement el;

final String direction = params.get("direction").toString();

final Integer percent = (Integer) params.get("percent");

final Integer steps = (Integer) params.get("steps");

try {

el = command.getElement();

if (el == null) {

return getErrorResult("Could not find an element with elementId: "

+ params.get("elementId"));

}

} catch (final Exception e) { // JSONException, NullPointerException, etc.

return getErrorResult("Unknown error:" + e.getMessage());

}

Logger.debug("Pinching " + direction + " " + percent.toString() + "%"

+ " with steps: " + steps.toString());

boolean res;

if (direction.equals("in")) {

try {

res = el.pinchIn(percent, steps);

} catch (final UiObjectNotFoundException e) {

return getErrorResult("Selector could not be matched to any UI element displayed");

}

} else {

try {

res = el.pinchOut(percent, steps);

} catch (final UiObjectNotFoundException e) {

return getErrorResult("Selector could not be matched to any UI element displayed");

}

}

if (res) {

return getSuccessResult(res);

} else {

return getErrorResult("Pinch did not complete successfully");

}

}

}

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

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

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

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

    手机自动化测试:appium源码分析之bootstrap二   在bootstrap项目中的io.appium.android.bootstrap.handler包中的类都是对应的指令类, priva ...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. typedef struct 是什么意思

    typedef用于定义一种新类型例如定义了如下的结构typedef struct student{int age;int score;}STUDENT;那么则有STUDENT stu1;就相当于str ...

  2. 将Error异常日志从普通日志中剥离

    开发过程中经常需要调试和线上环境查看异常日志的需求,但普通消息与异常消息混在一起实在是非常难得找,上则NM的文档够你头痛,所以就将Error级别的日志抽离出来. 本示例采用log4net来配置: 1. ...

  3. 平面上的地图搜索--Java学习笔记(四)

    版权声明: 本文由Faye_Zuo发布于http://www.cnblogs.com/zuofeiyi/, 本文可以被全部的转载或者部分使用,但请注明出处. 这一个月以来,都在学习平面上的地图搜索,主 ...

  4. 规范 : 过程 : login cookies sessionTimeOut

    规范 用户登入网站将得到一个cookies,如果用户有2个account,各别登入admin page 和 client page,是会得到2个cookies. 在reload page时,后台会得到 ...

  5. Android -- RecyclerView实现顶部吸附效果

    1,先来看一下今天实现的效果: 2,这次的效果是使用ItemDecoration来实践的,来看一看我们的实现吧 第一步:首先添加依赖,由于我们这些数据是请求网络的,所以一下我们添加网络框架依赖.Rec ...

  6. 【经验】JavaScript

    1.function closeWin(){             window.open('','_self');       window.opener=null;  //    window. ...

  7. Vue学习之路---No.1(分享心得,欢迎批评指正)

    首先为了打消大家对Vue.js存在的顾虑,先通过大家所熟知的JQ作为对比. 都知道JQ的语法相对简单.清楚.使用方便.功能齐全: 那么Vue.js呢,同样的,Vue.js与JQ在很多地方都是相同之处, ...

  8. wemall app商城源码中android按钮的三种响应事件

    wemall-mobile是基于WeMall的android app商城,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可定制修改.本文分享wemall app商城源码中android按 ...

  9. wx模块小实例

    功能介绍: 查询数据库表数据,提取数据并显示 main.py(执行文件) #coding:gbk __author__ = 'Hito' import querySmscode import wx c ...

  10. 基于ELK的数据分析实践——满满的干货送给你

    很多人刚刚接触ELK都不知道如何使用它们来做分析,经常会碰到下面的问题: 安装完ELK不知从哪下手 拿到数据样本不知道怎么分解数据 导入到elasticsearch中奇怪为什么搜不出来 搜到结果后,不 ...