手机自动化测试: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. GAME(A)性能测试过程模型

  2. Javascript 闭包与高阶函数 ( 二 )

    在上一篇 Javascript 闭包与高阶函数 ( 一 )中介绍了两个闭包的作用. 两位大佬留言指点,下来我会再研究闭包的实现原理和Javascript 函数式编程 . 今天接到头条 HR 的邮件,真 ...

  3. JAVA试练塔之试炼技能图

    1.计算机基础: 1.1数据机构基础: 主要学习: 1.向量,链表,栈,队列和堆,词典.熟悉 2.树,二叉搜索树.熟悉 3.图,有向图,无向图,基本概念 4.二叉搜索A,B,C类熟练,9大排序熟悉. ...

  4. win8配置JDK

    有很多新手朋友对win7 和win8里的环境变量不是很熟悉,下面我整理了一下: 首先要说一下,win7里和win8配置方法是相同的,配置之前先去百度一下 JDK 然后找到自己电脑系统对应的jdk版本下 ...

  5. Alamofire源码解读系列(一)之概述和使用

    尽管Alamofire的github文档已经做了很详细的说明,我还是想重新梳理一遍它的各种用法,以及这些方法的一些设计思想 前言 因为之前写过一个AFNetworking的源码解读,所以就已经比较了解 ...

  6. eclipse下进行spark开发(已实践)

    开发准备: jdk1.8.45 spark-2.0.0-bin-hadoop2.7(windows下和linux个留一份) Linux系统(centos或其它) spark安装环境 hadoop-2. ...

  7. Redis【第二篇】集群搭建

    第一步:准备 1.安装包 ruby-2.4.0.tar.gz rubygems-2.6.10.tgz zlib-1.2.11.tar.gz redis-3.3.2.gem 2. 架构: 名称 IP 端 ...

  8. AR入门系列-04-vuforia识别多个图片及同屏展示

    首先,我们需要在官网中识别数据库添加多张图片,并将数据库下载下来覆盖原来的数据库 在 Hierarchy视图中需要多个ImageTarget 将新建的ImageTarget(1) 选择数据库中的识别图 ...

  9. TypeScript设计模式之策略、模板方法

    看看用TypeScript怎样实现常见的设计模式,顺便复习一下. 学模式最重要的不是记UML,而是知道什么模式可以解决什么样的问题,在做项目时碰到问题可以想到用哪个模式可以解决,UML忘了可以查,思想 ...

  10. 【Unity优化】构建一个拒绝GC的List

    版权声明:本文为博主原创文章,欢迎转载.请保留博主链接:http://blog.csdn.net/andrewfan 上篇文章<[Unity优化]Unity中究竟能不能使用foreach?> ...