#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的更多相关文章

  1. [uiautomator篇][python调用java][1]应用下载的插件需要很长时间问题解决

    1第一次打开应用,可能会要求下载插件,我们先在/sdcard/Android/data/<packageName>  或者/data/data/<pakeageName>找到插 ...

  2. [uiautomator篇][python] wifi接口学习网址

    https://wifi.readthedocs.io/en/latest/wifi_command.html#usage

  3. 【0728 | 预习】第三篇 Python基础

    第三篇 Python基础预习 Part 1 变量 一.什么是变量? 二.为什么要有变量? 三.定义变量 四.变量的组成 五.变量名的命名规范 六.变量名的两种风格 Part 2 常量 Part 3 P ...

  4. 第二篇 python进阶

    目录 第二篇 python进阶 一 数字类型内置方法 二 字符串类型内置方法 三 列表类型内置方法(list) 四 元组类型内置方法(tuple) 五 字典内置方法 六 集合类型内置方法(self) ...

  5. 看完100篇Python技术精华文章,平均涨薪30%!

    一个以技术为立身根基的教育机构做出来的微信号,干货程度会有多高? 马哥Linux运维公众号运营五年,从一开始的定位就是给技术人分享加薪干货的地方.这五年里,公众号运营最重的任务就是做内容.内容并不好做 ...

  6. 第五篇python进阶之深浅拷贝

    目录 第五篇python进阶之深浅拷贝 一.引言 1.1可变 和不可变 二.拷贝(只针对可变数据类型) 三.浅拷贝 四.深拷贝 第五篇python进阶之深浅拷贝 一.引言 1.1可变 和不可变 id不 ...

  7. 第五篇.python进阶

    目录 第五篇.python进阶 1. 异常处理 2. 数字类型内置方法 2.定义: 3.常用操作+内置方法: 4.存一个值or多个值: 5.有序or无序: 6.可变和不可变 1.用途: 2.定义: 3 ...

  8. 第四篇.python的基础

    目录 第四篇.python基础01 1. 变量 2. 常量 3. python变量内存管理 4. 变量的三个特征 5. 花式赋值 6. 注释 7. 数据类型基础 8. 数字类型 9. 字符串类型 10 ...

  9. [转帖]虚拟内存探究 -- 第二篇:Python 字节

    虚拟内存探究 -- 第二篇:Python 字节 http://blog.coderhuo.tech/2017/10/15/Virtual_Memory_python_bytes/ 是真看不懂哦     ...

随机推荐

  1. C++面试中的singleton类

    引子 “请写一个Singleton.”面试官微笑着和我说. “这可真简单.”我心里想着,并在白板上写下了下面的Singleton实现: 1 class Singleton 2 { 3 public: ...

  2. java面试题(基础部分)

    1.一个".java"源文件中是否可以包括多个类(不是内部类)?有什么限制? 可以有多个类,但只能有一个public的类,并且public的类名必须与文件名相一致. 2.Java有 ...

  3. 【javascript】操作给定的二叉树,将其变换为源二叉树的镜像。

    操作给定的二叉树,将其变换为源二叉树的镜像. 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ 11 9 ...

  4. TitleBar(标题栏)的使用

    github地址:https://github.com/buhuiming/BHMAndroid 使用compile 'com.bhm.sdk.bhmlibrary:BHMLibrary:1.1.2' ...

  5. sqlite总结1

    I Shell下命令行程序CLP I .help II 命令的简写 .e = .quit .s .h = .help II 数据库管理 A 创建数据库 1 CREATE TABLE id_name(i ...

  6. (WWWWWWWWWW)codevs 3305 水果姐逛水果街Ⅱ

    写这么长了不A有点舍不得.. 想A又调不出来.. 于是乎就存一下.. 屠龙宝刀点击就送 #include <cstdio> #include <vector> #define ...

  7. hdu 1181 深搜

    中文题 深搜 许久没写鸟,卡在输入问题上... #include <iostream> #include <string> using namespace std; bool ...

  8. bfs染色法判定二分图

    #include<iostream> #include<queue> #include<cstring> #include<cstdio> using ...

  9. OpenCV2:直方图

    一.简介 在一个单通道的灰度图像中,每个像素的值介于0(黑色)~255(白色)之间,灰色图像的直方图有256个条目(或称为容器)

  10. Hibernate 中批量处理数据

    一.批量处理操作 批量处理数据是指在一个事务场景中处理大量数据.在应用程序中难以避免进行批量操作,Hibernate提供了以下方式进行批量处理数据: (1)使用HQL进行批量操作     数据库层面 ...