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

 

poptest(www.poptest.cn)是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标。如果对课程感兴趣,请大家咨询qq:908821478。

Wake

package io.appium.android.bootstrap.handler;

import android.os.RemoteException;

import com.android.uiautomator.core.UiDevice;

import io.appium.android.bootstrap.AndroidCommand;

import io.appium.android.bootstrap.AndroidCommandResult;

import io.appium.android.bootstrap.CommandHandler;

/**

* This handler is used to power on the device if it's not currently awake.

*

*/

public class Wake 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) {

// only makes sense on a device

try {

UiDevice.getInstance().wakeUp();

return getSuccessResult(true);

} catch (final RemoteException e) {

return getErrorResult("Error waking up device");

}

}

}

wake事件为唤醒手机,有的时候手机处于睡眠状态就需要点亮屏幕,如果此时屏幕就是亮的,那么不做任何操作。

PressBack

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;

/**

* This handler is used to press back.

*

*/

public class PressBack 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) {

UiDevice.getInstance().pressBack();

// Press back returns false even when back was successfully pressed.

// Always return true.

return getSuccessResult(true);

}

}

在手机上的返回键。

TakeScreenshot

 

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 java.io.File;

/**

* This handler is used to TakeScreenshot.

*

*/

public class TakeScreenshot 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) {

final File screenshot = new File("/data/local/tmp/screenshot.png");

try {

screenshot.getParentFile().mkdirs();

} catch (final Exception e) {

}

if (screenshot.exists()) {

screenshot.delete();

}

UiDevice.getInstance().takeScreenshot(screenshot);

return getSuccessResult(screenshot.exists());

}

}

截屏并将图片保存在/data/local/tmp路径下的screenshot.png文件中。

OpenNotification

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 static io.appium.android.bootstrap.utils.API.API_18;

/**

* This handler is used to open the notification shade on the device.

*

*/

public class OpenNotification extends CommandHandler {

/*

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

*

* @return {@link AndroidCommandResult}

*

* @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android.

* bootstrap.AndroidCommand)

*/

@Override

public AndroidCommandResult execute(final AndroidCommand command) {

// method was only introduced in API Level 18

if (!API_18) {

return getErrorResult("Unable to open notifications on device below API level 18");

}

// does not make sense on an element

if (command.isElementCommand()) {

return getErrorResult("Unable to open notifications on an element.");

}

final UiDevice device = UiDevice.getInstance();

if (device.openNotification()) {

return getSuccessResult(true);

} else {

return getErrorResult("Device failed to open notifications.");

}

}

}

打开通知栏操作,api18以后在UiDevice中添加了openNotification()方法,打开通知栏。所以该事件就是去调用该方法。

手机自动化测试: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是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...

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

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

随机推荐

  1. OSS最新进度汇报(2.25)

    OSS系列最新进度情况如下:一. OSS.Social进度 1. 客服接口升级至新客服接口 2. BaseRecMsg中RecMsg字符串类型修改为xml类型 3. 添加Redis缓存注册实现,代码见 ...

  2. 对JS关于对象创建的几种方式的整理

    最近一直在看JS高级程序设计这本书,有空来梳理一下几种创建对象的方式.话不多说,直接步入正题. 第一种:Object构造函数创建 var Person = new Object();Person.na ...

  3. JS分两种数据类型,你都知道吗?

    大牛请无视此篇! JS主要分基本数据类型和引用数据类型,这两者区别可大了,此篇看完必有长进,下面进入正题 首先我们看下什么是基本数据类型(概念我就不说了,直接上代码): var i = 10: var ...

  4. Hibernate一对一主键映射

    Hibernate一对一主键映射                        ------------------------------                            -- ...

  5. 用Javascript大批量收集网站数据

    最近为了写论文,要大批量收集慕课网的相关用户数据(因为用户个人主页是公开的),故而写了一个插件进行收集.需要在慕课网控制台输入.最后收集了3000多份数据. /* 收集项 收集标准 用户编号 慕课网用 ...

  6. UI设计需具备的几大素质

    近年来,IT产业对于高端技术人才需求加大,特别是北上广和知名企业对人才需求更为迫切,UI设计人员的正在接受UI培训的学员都赢认识到UI设计在未来要求将越来越高,交互设计越来越新颖也将对用户更加友好,兄 ...

  7. VMware下ubuntu与Windows实现文件共享的方法

    最近安装caffe需要将Windows下文件拷贝到ubuntu16.04下,就进行了共享文件夹的设置,期间遇到一些困难,记录下来,方便以后遇到此类问题不再困惑. (记录只为更好的分享) 言归正传: 1 ...

  8. 解决springmvc在单纯返回一个字符串对象时所出现的乱码情况(极速版)

    使用springmvc框架开发了这么长时间,之前都是直接返回jsp页面,乱码情况都是通过配置和手动编解码来解决,但是今天突然返回一段单纯的字符串时,发现中文乱码情况解决不了了,下面就给各位分享一下如何 ...

  9. Modbus软件开发实战指南 之 开发自己的Modbus Poll工具 - 1

    在开发Modbus程序的过程中,也可以发现经常需要使用诸如Modbus Poll和Modbus Slave等辅助调试工具, 用于验证MODBUS通讯消息是否正确.但是,Modbus Poll和Modb ...

  10. React组件开发(二)表达式

    var obj = { name:"xiaoming", age:"18" } var Hello= React.createClass({ render:fu ...