[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/ 是真看不懂哦 ...
随机推荐
- ItemsControl Grouping分组
ItemsControl属性GroupStyle Grouping再ItemsControl源代码 public class ItemsControl : Control, IAddChild, IG ...
- C# (Cookie)基本操作
在Common中新建一个CookieHelper,全局调用 using System; using System.Collections.Generic; using System.Linq; usi ...
- VS2015 VB.Net利用QrCodeNet生成QR Code
Step by step Create QR Code with QrCodeNet Step.1 新建項目 Step.2 下載QrCodeNet代碼,解壓\QrCodeNet\sourceCode\ ...
- 将Object转换成Dictionary方法
如果Object是Dictionary类型,直接返回 如果Object是NameValueCollection类型,则添加到Dictionary里 如果Object是Hashtable类型,添加到Di ...
- 关于React的赋值与调用方法
#关于React的赋值与调用方法 比如调用方法的时候我们可以这样来使用closeFrm() <div className = "infoFrm_close" onMouseO ...
- andorid 向上滑动控制标题栏显示
要实现这样的功能,原理不难,监听滑动距离再设置标题栏的透明度 下面是监听一个带头view的list实现核心代码: mbar是标题栏 mListView.setOnScrollListener(new ...
- eclipse的hadoop插件对集群操作提示org.apache.hadoop.security.AccessControlException:Permission denied
eclipse的hadoop插件对集群操作提示org.apache.hadoop.security.AccessControlException:Permission denied: user = z ...
- 用python格式化小说txt
下载了<无人生还>的txt版.传到手机,发现阅读器识别得不够好. 原文格式如下: 第一章 一 沃格雷夫法官先生新近离任退休,现在正在头等车厢的吸烟室里,倚角而坐,一 边喷着雪茄烟,一边兴致 ...
- codevs 3026 恶心的扑克
时间限制: 1 s 空间限制: 64000 KB 题目等级 : 白银 Silver 题目描述 Description 有一副恶心的扑克,从小到大依次是3 , 4 , 5 , 6 , 7 , 8 , ...
- IOS7 Text View 截断的问题解决
- (void)textViewDidChange:(UITextView *)textView { CGRect line = [textView caretRectForPosition: tex ...