Skip to main content
# Tonzh 基于HATT 二次开发

原理:基于android uiautomator跟adb

环境:python2.7.x+android sdk

功能:支持功能、性能、稳定性

优点:无需安装任何apk或其他插件,支持跨应用,无签名烦恼

缺点:不支持webview、动态页面、中文输入及查找

以下是demo

```python
__author__ = 'Tonzh'
#coding=utf-8
#import moudles
from Core.Utils.surface_collector import SurfaceStatsCollector
from Core.Action.action import Action
from Core.Info.element import Element
from Core.Info.performance import PerformanceInfo
from Core.Action.Monkey.monkey import Monkey
import Core.Info.keycode as key
s=SurfaceStatsCollector()
a=Action()Tonzh
e=Element()
p=PerformanceInfo()
m=Monkey()
"""
Performance Test
"""
#Fps Test
s.DisableWarningAboutEmptyData()
s.Start()
#steps
for x in range(3):
a.swipeToUp()
s.Stop()
#print result
for x in s.GetResults():
if "avg_surface_fps" in x.name:
print x.name,x.value,x.unit

#Cpu Test
#steps
for x in range(3):
a.swipeToUp()
#print result
cpunInfo=p.getCpuFromDump("com.android.launch")
#or
cpunInfo=p.getCpuFromTop("com.android.launch")


# Mem Test
#steps
for x in range(3):
a.swipeToUp()
#print result
memInfo=p.getMemFromDump("com.android.launch")
#or if you install procrank
menInfo=p.getMemFromProcrank("com.android.launch")


#LaunchTime Test
#steps
for x in range(3):
a.swipeToUp()
#print result
startInfo=p.getAppStartTotalTime("com.android.launch/.LaunchActivity")


#Flow Test
#steps
flowInfoBefore=p.getCurFlowFromProc("com.android.launch")
#do something
for x in range(3):
a.swipeToUp()
flowInfoAfter=p.getCurFlowFromProc("com.android.launch")
#print result
flowInfo=flowInfoAfter-flowInfoBefore

#Battery Test
#steps
batteryInfoBefore=p.getBatteryLevel()
#do something
for x in range(3):
a.swipeToUp()
batteryInfoAfter=p.getBatteryLevel()
#batteryInfo=(batteryInfoBefore-batteryInfoAfter)*batteryCount


"""
Function Test
"""
#click element
#1.get by class
elm=e.findElementByClass("TextView")
#or by id
elm=e.findElementById("dd")
#or by text
elm=e.findElementByName("tt")
#or by content-desc
elm=e.findElementByContent("tt")
#2.then do something
#click
a.touch(elm)
a.touchByElement(elm)
a.touchByRatio(0.5,0.2)
a.touch(300,400)
#long click
a.longPress(elm)
#send text
a.sendText("dd")
#send keyevent
a.sendKeyEvent(key.BACK)
#swipe
a.swipeToDown()
a.swipeToLeft()
a.swipeToRight()
a.swipeToUp()
a.swipe(elm,elm)
a.swipe(100,100,100,100)

#check currentview hava element
#by class
e.searchForByClass("TextView")
#by name
e.searchForByName("dd")
#by id
e.searchForById("dd")
#by content-desc
e.searchForByContent("dd")


"""
Monkey Test
"""
#steps
m.StartOne("com.android.browser",1000,1000,1000)
#wait for monkey stop or new script and run m.Stop()
#if you see monkey stop you can run
m.Stop()


```

Release files for HATT-add-on 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for HATT-add-on 1.0.2
File Size Uploaded
HATT-add-on-1.0.2.tar.gz 17.5 kB Details

Release files / HATT-add-on-1.0.2.tar.gz

Download URL HATT-add-on-1.0.2.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f83a0c1298949bb7a0a95d3f5933473f6ebef03666180654841ca0c254730917
BLAKE2b-256 checksum
How to use checksums
d41e73dd43860215e6434a9fbd737cb9fc6141367bf461be86f67de8ce13006a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.2 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page