#coding=utf-8
import os
import time #import MonkeyRunner three module
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
runComponent = "com.dest.mr/.ui.home.HomeLauncherNew" path = 'd:/pic/'
logpath = 'd:/log/' #new log file.txt
log = open(logpath + 'dest' + ".txt",'w') #connection device
device = MonkeyRunner.waitForConnection() if not device:
log.write('connection failed \n' )
sys.exit(1)
else:
log.write('connection passed \n') device.startActivity(component = runComponent)
time.sleep(5) #device.shell("logcat | grep 'com.dest.mr' > sdcard/destlog.txt")
#os.system('''adb logcat | findstr "com.dest.mr" >> d:/log/logcat.txt''') for i in range(3):
#save log to file.txt
log.write('start app....' + str(i) + '\n')
desthome = device.takeSnapshot()
desthome.writeToFile(path + 'desthome' + str(i) + '.png','png')
#import home pictures for comparing the results
homeTure = MonkeyRunner.loadImageFromFile('d:/pic/Tdesthome.png') if(desthome.sameAs(homeTure,0.9)):
print 'desthome pic is the same \n'
log.write ('test passed \n')
else:
print 'test byebye \n'
log.write ('test failed \n') #open userinfo
device.touch(850,68,'DOWN_AND_UP')
time.sleep(2)
userinfo = device.takeSnapshot()
userinfo.writeToFile(path + 'userinfo' + str(i) + '.png','png') ufoTure = MonkeyRunner.loadImageFromFile('d:/pic/Tuserinfo.png') if(userinfo.sameAs(ufoTure,0.75)):
print 'userinfo pic is the same \n'
log.write ('userinfo test passed \n')
else:
print 'userinfo pic is not the same'
log.write ('userinfo test failed \n') #click mobile, into myinfo page
device.touch(550,200,'DOWN_AND_UP')
time.sleep(2)
myinfo = device.takeSnapshot()
myinfo.writeToFile(path + 'myinfo' + str(i) + '.png','png')
device.drag((500,550),(300,250),0.5)
time.sleep(2) device.press('KEYCODE_BACK','DOWN_AND_UP')
time.sleep(2)
device.touch(60,80,'DOWN_AND_UP')
time.sleep(2)

Android自动化测试 - MonkeyRunner(三) 随手练习测试脚本的更多相关文章

  1. Android自动化测试 - MonkeyRunner(二) 锤子便签测试脚本

    来源于:http://testerhome.com/topics/878 # encoding=utf-8 #导入python中自带的time模块和sys模块,脚本中都要用到它们. import ti ...

  2. Android自动化测试 - MonkeyRunner(一)介绍

    MonkeyRunner介绍: MonkeyRunner是Google提供的一个基于坐标点的Android黑盒自动化测试工具. Monkeyrunner工具提供了一套API让用户/测试人员来调用,调用 ...

  3. Android 自动化测试及性能数据采集的 Python 脚本

    文主要介绍一个基于 uiautomator2 封装的一个 Python 库 android-catcher ,该库的功能主要有对 Android 设备进行 UI 自动化测试 和 采集手机性能数据 ,适 ...

  4. Appium环境的安装与配置,Python测试脚本测试

    Appium自动化测试系列1 - Appium环境的安装与配置 发表于4个月前(2015-01-27 14:34)   阅读(803) | 评论(0) 0人收藏此文章, 我要收藏 赞0 寻找 会’偷懒 ...

  5. Android 自动化测试——Monkey测试

    Android自带了很多方便的测试工具和方法,包括我们常用的单元测试.Robotium测试.Monkey测试.MonkeyRunner测试.senevent模拟等.这些方法对于我们编写高质量的APP十 ...

  6. Android自己的自动化测试Monkeyrunner和用法示例

    眼下android SDK在配有现成的测试工具monkey 和 monkeyrunner两. 也许我们不看一样的兄弟名字.但事实是完全跑了两个完全不同的工具.在测试的不同区域的应用程序.总体,monk ...

  7. 锤子便签的 monkeyrunner 测试脚本(转)

    https://testerhome.com/topics/878 MonkeyRunner可能大家已经听过无数次了,大家在网上也看过了各种关于的它的资料了,我这里就不再过多的啰嗦它的用途了,它可以对 ...

  8. Android自动化测试中Monkeyrunner详解

    之前有写过monkey测试详细说明,几天就说说monkeyrunner. monkeyrunner工具提供了一个API,使用此API写出的程序可以在Android代码之外控制Android设备和模拟器 ...

  9. HTML脚本配置Android自动化测试

    说明   在项目配置完基于robotium框架下的自动化测试用例后发现虽然用代码配置测试用例虽然较为灵活,但是如果编写较为全面的测试用例则必然会消耗大量开人员的精力,并且对于用例的后期维护也是很大一部 ...

随机推荐

  1. Hibernate类中集合的映射

    1 pojo类集合属性的映射 在pojo类中定义集合属性. 1.1  List集合属性的映射 package org.guangsoft.pojo; import java.util.List; pu ...

  2. ios截取号码

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationTy ...

  3. ajaxFileUpload上传文件没反应

    调用jquery的ajaxFileUpload异步上传文件,IE浏览器不进入success问题 原因:json转换异常,ie浏览器处理后的返回json没有<pre>标签,直接是完整的jso ...

  4. Java观察者模式(Observer模式)

    Java深入到一定程度,就不可避免的碰到设计模式(design pattern)这一概念,了解设计模式,将使自己对java中的接口或抽象类应用有更深的理解.设计模式在java的中型系统中应用广泛,遵循 ...

  5. 浅析 - iOS应用程序的生命周期

    1.应用程序的状态 状态如下: Not running  未运行  程序没启动 Inactive          未激活        程序在前台运行,不过没有接收到事件.在没有事件处理情况下程序通 ...

  6. iOS - 日期的时间差(某年某月某日的某一天。。。)

    //首先创建格式化对象 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateF ...

  7. C++杂记

    变量就是一个地址,同进程内可以直接访问,要做好线程之间的同步就是了.——摘自CSDN 2015-06-18 16:58:10(注:注意变量的生命周期(作用域就可以不在意))

  8. Android 注解工具 ButterKnife

    Butter Knife 是 Android 视图字段和方法绑定,使用注解处理来生成样板代码. 主要特性: 在字段使用 @FindView消除findViewById调用 使用 @FindViews在 ...

  9. 使用Jmeter进行http接口性能测试

    在进行网页或应用程序后台接口开发时,一般要及时测试开发的接口能否正确接收和返回数据,对于单次测试,Postman插件是个不错的Http请求模拟工具. 但是Postman只能模拟单客户端的单次请求,而对 ...

  10. C 和 C++ 混合代码 cmath编译出错

    最近在网上下载了 Triangle 库,准备在程序中调用来三角化生成网格,但出现了很多错误,如下: 1>  triangle.c1>d:\program files\visualstudi ...