[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/ 是真看不懂哦 ...
随机推荐
- Jenkins在Windows上部署
下载解压安装即可.(注意:不要安装在系统盘) 下载地址:http://mirrors.jenkins-ci.org/war-stable/(官方镜像地址) 去相应目录复制管理员密码粘贴到输入框 选择安 ...
- IDEA 启用/禁用 Run Dashboard
一.启用 方式一: 创建/打开一个SpringBoot项目[或者点击Run --> Edit Configurations 添加 Spring Boot 类型的项目配置:或者如图在红框处添加配置 ...
- sysdig安装和使用介绍
安装步骤1)安装资源库rpm --import https://s3.amazonaws.com/download.draios.com/DRAIOS-GPG-KEY.publiccurl -s -o ...
- 查看Windows激活信息
使用 Windows + R组合快捷键打开运行命令框 1.运行: slmgr.vbs -dlv 可以查询到Win10的激活信息,包括:激活ID.安装ID.激活截止日期等信息. 2.运行: slmgr. ...
- SQLite连接
SQLite -连接 SQLite的联接子句用于从数据库中的两个或多个表合并的记录.JOIN是用于通过使用共同的每个值从两个表结合域的装置. SQL定义了三个主要类型的连接: CROSS JOIN I ...
- iTOP-IMX6UL 实战项目:ssh 服务器移植到 arm 开发板
实验环境:迅为提供的Ubuntu12.04.2 以及虚拟机 编译器:arm-2009q3 编译器 开发板系统:QT系统 开发板使用手册中给Windows 系统安装了 ssh 客户端,给 Ubunt ...
- 远程文件拷贝(fastcopy为例)
远程地址格式如下:\\IP地址\磁盘符号$\文件夹名称(如:127.0.0.1\\c$\\image)拷贝了image文件夹下面的所有文件,但是如果远程机器有密码的话要先在本机先输入远程的目标地址然后 ...
- (转)MyBatis框架的学习(四)——Mapper.xml文件中的输入和输出映射以及动态sql
http://blog.csdn.net/yerenyuan_pku/article/details/71893689 前面对MyBatis框架的学习中,我们对Mapper.xml映射文件多少有些了解 ...
- ansible 调优
1.设置ssh长链接ssh_args = -C -o ControlMaster=auto -o ControlPersist=5d 2.开启pipelining开启pipelining 需要被控制机 ...
- .net MVC下跨域Ajax请求(CORS)
二.CROS (Cross-origin Resource Sharing) CROS相当于一种协议,由浏览器.服务端共同完成安全验证,进行安全的跨域资源共享.对于开发人员来说就跟在本站AJAX请求一 ...