#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. -bash: pod: command not found

    OS X 系统没升级之前用的 cocoapods 一点儿问题都没有,但是升级成版本10.11.4 OS X EI Capitan之后,在终端除了cd 指令可以用之外,其他任何指令输入都是提示-bash ...

  2. ASP.Net后台 实现先弹出对话框,再跳转到另一个网页的实现方法

    解决办法如下: Response.Write("<script>alert('想在对话框中显示的内容');window.navigate(‘要转到的页面的URL’)</sc ...

  3. XMPP框架下微信项目总结(3)获取点子名片信息(个人资料)更新电子名片

    思路:1 调用方法,添加点子名片模块(名片信息含电话,头像,单位个人信息)等 开启ps:APP发送请求到服务器openfire,服务器返回个人信息,app存储到数据库,app界面需要数据通过数据库获取 ...

  4. STL_advance distance prev next

    template<class InputIterator> typename iterator_traits<InputIterator>::difference_type d ...

  5. Java实现颜色渐变效果

    RGB色彩,在自然界中肉眼所能看到的任何色彩都可以由红(R).绿(G).蓝(B)这三种色彩混合叠加而成,因此我们只要递增递减的修改其特定值就能得到相应的渐变效果. 运行效果:(图1) 运行5秒后:(图 ...

  6. [转]c++ vector 遍历方式

    挺有趣的,转来记录 随着C++11标准的出现,C++标准添加了许多有用的特性,C++代码的写法也有比较多的变化.   vector是经常要使用到的std组件,对于vector的遍历,本文罗列了若干种写 ...

  7. [javascript] 使用闭包编写模块

    这是一篇[javascript the good parts]的读书笔记. 我们知道可以利用javascript 的prototype 特性为原始类型编写拓展模块.利用如下方法: Object.pro ...

  8. log4j设置日志格式为UTF-8

    想要log4j输出的日志文件的编码格式为UTF-8.正常情况下只需要添加下述的代码即可: log4j.appender.appender_name.Encoding=UTF-8 但是在spring与l ...

  9. 堆栈C实现

    标准C语言没有像C++那样可以直接调用的STL容器,所以在c语言中实现容器功能就得自己去定义堆栈结构: stack.h /************this head file defines a st ...

  10. 如何通过阅读C标准来解决C语言语法问题

    有时候必须非常专注地阅读ANSI C标准才能找到某个问题的答案.一位销售工程师把下面这段代码作为测试用例发给Sun的编译小组. foo(const char **p) {} int main(int ...