[uiautomator篇] python uiautomatorDemo
#coding=utf-8
""" @version: 1.0 @author: @prerequisite:
based on Python 2.7 @usage:
1) this is the handler for testcase @Others:
No @description: 3DMark性能跑分 @module: performance @caselevel: A @timeout: 1800 """ from uiautomator import Device
import time
from util import CylixUtilTestCase
import subprocess
import os
import zipfile
import shutil
import traceback
import re class AI030002Mark3D(CylixUtilTestCase): PRE_INSTALL_APK = [
# ('apk\\3DMark.apk','com.futuremark.dmandroid.application')
# ('apk\\pad-debug.apk','com.softwinner.performance.frameratetest'),
# ('apk\\pad-debug-androidTest.apk','com.softwinner.performance.frameratetest.test')
] def testMark3d(self): self.installPlugIn()
self.UiautomatorMark3D() def installPlugIn(self): resourcedir = os.path.normpath(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'resource'))
zipFilePath = os.path.normpath(os.path.join(resourcedir, r'mark3d\Android.zip'))
unzipToPath = os.path.dirname(zipFilePath)
tempfile = os.path.join(unzipToPath, r'Android')
self.logger.info("step1: unzip " + zipFilePath + " to " + unzipToPath)
if os.path.exists(tempfile):
self.logger.info(tempfile + ' exist ,delete it')
self.deleteDirectory(tempfile)
self.unzip_file(zipFilePath, unzipToPath) self.logger.info("step2: push data to device")
localDataPath = resourcedir + r'\mark3d\Android\data'
remoteDataPath = '/sdcard/Android'
self.device.adb.push(localDataPath, remoteDataPath)
self.deleteDirectory(tempfile) def UiautomatorMark3D(self):
assert self.Recent(), 'recent fail'
self.enterApplist()
self.openApplication('3DMark')
self.runMark3d()
self.parserXml()
assert self.Recent(), 'recent fail' def enterApplist(self):
d = Device(self.dut_adb_num)
d.press.home()
d.screen.on() if d(description = "Apps list", index = 3).wait.exists(timeout=2000):
self.logger.info("Find App list successfully")
d(description = "Apps list", index = 3).click()
else:
print "Can not find App list"
assert False, 'Can not find App list'
if d(resourceId = "com.android.launcher3:id/main_content").wait.exists(timeout=2000):
self.logger.info("Enter APP list successfully")
return True
else:
self.logger.info("Fail to enter APP list")
assert False, 'Fail to enter APP list' def openApplication(self, packageName):
d = Device(self.dut_adb_num)
d.screen.on()
if d(text = packageName).wait.exists(timeout = 2000):
self.logger.info("Find %s successfully" % packageName)
d(description = packageName).click()
else:
self.logger.info("Can not find %s" % packageName)
assert False, "Can not find %s" % packageName def runMark3d(self):
d = Device(self.dut_adb_num)
d.screen.on()
time.sleep(10)
if d(textContains = "3DMARK").wait.exists(timeout = 20000):
self.logger.info("Enter 3DMARK successfully")
else:
self.logger.info("Fail to enter 3DMARK")
assert False, 'fail to enter 3DMARK' if d(description = "RUN").wait.exists(timeout = 20000):
self.logger.info("Find RUN successfully")
d(description = "RUN").click()
else:
self.logger.info("Find RUN Failure")
assert False, 'find Run Failure' for i in range(1,15):
time.sleep(30)
self.logger.info("3DMark run time :%s s" % str(i * 30))
if i%2 == 0:
if d(description = "SHARE").wait.exists(timeout = 2000):
self.logger.info("Find SHARE successfully")
self.logger.info("********************3DMark DONE********************")
return True xml_path = self.tcr_fd + os.sep + "3DMarkLiu.xml"
self.logger.info('xml_path = %s' % xml_path)
d.dump(xml_path)
self.logger.info("Finish downloading %s file " % xml_path)
f = file(xml_path)
lines = f.readlines()
status = False
for line in lines:
if "SHARE" in line:
self.logger.info("Find SHARE successfully")
self.logger.info("********************3DMark DONE********************")
status = True
break;
f.close()
assert status, 'mark3d test fail' def parserXml(self): d = Device(self.dut_adb_num)
d.screen.on()
iceStormExtremeXML = os.path.normpath(os.path.join(self.tcr_fd, 'iceStormExtreme.xml'))
self.logger.info('iceStormExtremeXML = %s' % iceStormExtremeXML )
d.dump(iceStormExtremeXML)
f = file(iceStormExtremeXML)
lines = f.readlines()
for line in lines:
# content-desc="Ice Storm Extreme 1891"
iceStormExtreme_score = re.findall(r'Ice Storm Extreme\s+(\d+)', line, re.M)[0]
self.logger.info(iceStormExtreme_score)
if not iceStormExtreme_score:
assert False, 'recompile fail'
assert int(iceStormExtreme_score) > 1500, 'iceStormExtreme_score below 1500'
f.close() def unzip_file(self,zipfilename,unziptodir): # if not os.path.exists(unziptodir):
# os.mkdir(unziptodir,0777)
assert os.path.exists(unziptodir), unziptodir + "not exist" zfobj = zipfile.ZipFile(zipfilename)
for name in zfobj.namelist():
name = name.replace('\\','/')
if name.endswith('/'):
# print "include folder: " + name
os.mkdir(os.path.join(unziptodir,name))
else:
# print "include file: " + name
ext_filename = os.path.join(unziptodir,name)
ext_dir = os.path.dirname(ext_filename)
if not os.path.exists(ext_dir):
os.mkdir(ext_dir,0777)
outfile = open(ext_filename,'wb')
outfile.write(zfobj.read(name))
outfile.close() def deleteDirectory(self,current_path):
if not os.path.exists(current_path):
self.logger.info(current_path + " not exist")
return
current_filelist = os.listdir(current_path)
for f in current_filelist:
real_path = os.path.join(current_path,f)
if os.path.isdir(real_path):
real_folder_path = real_path
try:
for root,dirs,files in os.walk(real_folder_path):
for name in files:
del_file = os.path.join(root,name)
os.remove(del_file)
shutil.rmtree(real_folder_path)
except Exception,e:traceback.print_exc()
if os.path.isfile(real_path):
os.remove(real_path)
os.rmdir(current_path) def Recent(self):
d = Device(self.dut_adb_num)
displayWidth = int(d.info.get("displayWidth"))
displayHeight = int(d.info.get("displayHeight"))
d.press.recent()
if d(text="No recent items").wait.exists(timeout=2000):
print "Cleared recent items"
return True
if d(descriptionContains="Dismiss").wait.exists(timeout=2000):
for i in range(50):
if d(text="CLEAR ALL").wait.exists(timeout=2000):
d(text="CLEAR ALL").click()
if d(description="Apps list",index=3).wait.exists(timeout=2000):
print "Cleared recent items"
return True
else:
print "Fail to clear recent items"
return False
else:
d.swipe(displayWidth/2,displayHeight/4,displayWidth/2,3*displayHeight/4,steps=30)
i+=1
else:
print "Fail to find CLEAR ALL "
return False
else:
print "EXCEPTION CLEAR RECENT ITEMS"
return True
[uiautomator篇] python uiautomatorDemo的更多相关文章
- [uiautomator篇][python调用java][1]应用下载的插件需要很长时间问题解决
1第一次打开应用,可能会要求下载插件,我们先在/sdcard/Android/data/<packageName> 或者/data/data/<pakeageName>找到插 ...
- [uiautomator篇][python] wifi接口学习网址
https://wifi.readthedocs.io/en/latest/wifi_command.html#usage
- 【0728 | 预习】第三篇 Python基础
第三篇 Python基础预习 Part 1 变量 一.什么是变量? 二.为什么要有变量? 三.定义变量 四.变量的组成 五.变量名的命名规范 六.变量名的两种风格 Part 2 常量 Part 3 P ...
- 第二篇 python进阶
目录 第二篇 python进阶 一 数字类型内置方法 二 字符串类型内置方法 三 列表类型内置方法(list) 四 元组类型内置方法(tuple) 五 字典内置方法 六 集合类型内置方法(self) ...
- 看完100篇Python技术精华文章,平均涨薪30%!
一个以技术为立身根基的教育机构做出来的微信号,干货程度会有多高? 马哥Linux运维公众号运营五年,从一开始的定位就是给技术人分享加薪干货的地方.这五年里,公众号运营最重的任务就是做内容.内容并不好做 ...
- 第五篇python进阶之深浅拷贝
目录 第五篇python进阶之深浅拷贝 一.引言 1.1可变 和不可变 二.拷贝(只针对可变数据类型) 三.浅拷贝 四.深拷贝 第五篇python进阶之深浅拷贝 一.引言 1.1可变 和不可变 id不 ...
- 第五篇.python进阶
目录 第五篇.python进阶 1. 异常处理 2. 数字类型内置方法 2.定义: 3.常用操作+内置方法: 4.存一个值or多个值: 5.有序or无序: 6.可变和不可变 1.用途: 2.定义: 3 ...
- 第四篇.python的基础
目录 第四篇.python基础01 1. 变量 2. 常量 3. python变量内存管理 4. 变量的三个特征 5. 花式赋值 6. 注释 7. 数据类型基础 8. 数字类型 9. 字符串类型 10 ...
- [转帖]虚拟内存探究 -- 第二篇:Python 字节
虚拟内存探究 -- 第二篇:Python 字节 http://blog.coderhuo.tech/2017/10/15/Virtual_Memory_python_bytes/ 是真看不懂哦 ...
随机推荐
- 一些JS基本小内容
获取select选中内容: 1.获取select表单内容 <select id="sel"> <option value="v1">1& ...
- javascript for/forEach
基本用法 for:for(var i=0;i<arr.length;i++) forEach:arr.forEach(function(value,index,arr){},),其中functi ...
- imageview加载本地和网络图片
ImageView是Android程序中经常用到的组件,它将一个图片显示到屏幕上. 在UI xml定义一个ImageView如下: public void onCreate(Bundle savedI ...
- ios自定义日期、时间、城市选择器
选择器,我想大家都不陌生,当需要用户去选择某些范围值内的一个固定值时,我们会采用选择器的方式.选择器可以直观的提示用户选择的值范围.统一信息的填写格式,同时也方便用户快速的进行选择,比如对于性别,正常 ...
- uvm_subscriber——告诉她我们来过
Subscribers are basically listeners of an analysis port. They subscribe to a broadcaster and receive ...
- Android学习总结(十)———— Intent的使用
一.Intent的基本概念 我们已经学习完了Android的四大组件了,在四大组件中我们用得最多的是Intent-Filter.Intent含义就是你想利用它调用哪个组件实现相关的功能,比如调用相机组 ...
- ObjectiveC中的赋值,对象拷贝,浅拷贝与深拷贝
在开发过程中我们经常会遇到对象拷贝的问题,下面我们分别讨论赋值操作.对象拷贝.以及浅拷贝(Shallow copy)与深拷贝(Deep copy)的区别与各自的实现方式. 一.不同对象的赋值操作 Ob ...
- shell 复合条件测试 if [ $1 == "1" -o $1 == "0" ] ------==和-eq怎么用
想要实现: ”,或者$1等于“” ];then 输出一些东西 ”,或者$1等于“” ];then 输出一些东西 fi 这里比较难操作的是等于和或者: 等于: -eq 或者 == 或者: -o 见: ...
- MIPS简单入门
What ‘s the MIPS? 汇编语言 汇编语言是一类语言的总称,因处理器不同,而对应的不同机器的指令集也不同,产生了很多种汇编语言. 目前最流行的是ARM,MIPS,x86.ARM用于大量的移 ...
- jsc 解码窥探
先使用 JS_DecodeScript反编译jsc 得到AST树 AST树词法解析 http://esprima.org/ AST还原成源码: npm install escodegen AST树遍 ...