手机自动化测试: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. [Android] "Failed to find Java version for 'C:\Windows\system32\java.exe"

    Impossible to install SDK r17 on win 7 x64 "Failed to find Java version for 'C:\Windows\system3 ...

  2. JAVA设计模式:单例设计

    1.单例设计Singleton的引出 单例设计,从名字上首先可以看出单---即只有一个,例---只的是实例化对象:那么单例也就是说一个类,只产生了一个实例化对象.但是我们都知道,一个类要产生实例化对象 ...

  3. Java包装类缓存

    1.基本概念 在jdk1.5及之后的版本中,Java在5大包装类中(Byte,Charactor,Short,Integer,Long)增加了相应的私有静态成员内部类为相应包装类对象提供缓存机制,In ...

  4. VS2010 MSDN的介绍

    5     cout << temp; 博客园第一篇文章的开始. VS2010 MSDN的文档介绍 https://msdn.microsoft.com/zh-cn/library/dd8 ...

  5. Pascal's Triangle II leetcode

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  6. 2272: [Usaco2011 Feb]Cowlphabet 奶牛文字

    2272: [Usaco2011 Feb]Cowlphabet 奶牛文字 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 138  Solved: 97 ...

  7. maven项目无法查看方法

    问题如图: 解决:

  8. python 中的input()和raw_input()功能与使用区别

    在python中raw_input()和input()都是提示并获取用户输入的函数,然后将用户的输入数据存入变量中.但二者在处理返回数据类型上有差别. input()函数是raw_intput()和e ...

  9. java中String s = new String("abc")创建了几个对象?

    答案是两个,现在我们具体的说一下: String s = new String("abc");一.我们要明白两个概念,引用变量和对象,对象一般通过new在堆中创建,s只是一个引用变 ...

  10. linux系统和Windows系统共存

    最近接触了linux系统,因为对linux系统一直存在一种敬畏之心,所以决定研究研究 那么今天我在这里呢是要和大家分享一下在Windows存在的情况下安装双系统linux 那么第一步呢,就是斤BIOS ...