手机自动化测试:appium源码分析之bootstrap十三 2
2015-12-22 16:06
609 查看
TakeScreenshotpackage 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 getSucce***esult(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 getSucce***esult(true); } else { return getErrorResult("Device failed to open notifications."); } }}打开通知栏操作,api18以后在UiDevice中添加了openNotification()方法,打开通知栏。所以该事件就是去调用该方法。相关文章推荐
- 老李性能测试分享
- 你想不到:咖啡馆里上工具课
- 移动端自动化测试开课了
- 老李分享:什么是好战略
- 性能调优案例分享:Mysql的cpu过高
- 性能测试分享:性能测试工具开发的案例分享(上)
- 性能测试分享:性能测试工具开发的案例分享(下)
- 性能测试培训:批量执行Jmeter脚本之ant调用 2
- 性能测试培训:分布式测试之jmeter1
- 老李案例分享:MAT分析应用程序服务出现内存溢出过程1
- 老李案例分享:MAT分析应用程序服务出现内存溢出过程2
- 老李案例分享:定位JAVA内存溢出 1
- 老李案例分享:定位JAVA内存溢出 2
- 性能测试培训: 建立压力模型
- 老李分享:你知道有哪些持续集成工具
- 老李分享知识:性能测试之TPS和吞吐率
- 老李分享知识:性能测试之吞吐量
- 性能测试培训:分析内训泄露的案例
- 自动化测试培训:qtp脚本获取获取汇率数据
- 性能测试培训:sql server性能测试分析局部变量的性能影响1