# -*- coding: utf-8 -*-
import os
import time
import datetime
import threading
import re
from wsgiref.validate import validator
from conf.config import config
class AppShell(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.thread_stop = False
def __raise_error(self, msg=None):
# Raise Exception with self-defined message.
raise Exception(msg)
def kill_adb_process(self):
"""
Kill ADB Process.
Examples:
| Kill Adb Process |
"""
try:
status = os.system('taskkill /f /im adb.exe')
if status == 0:
print 'Pass! Killed ADB Process.'
else:
self.__raise_error('Fail! Could NOT kill ADB Process.')
except Exception as e:
print str(e)
def start_adb_service(self):
"""
Start ADB Service.
Examples:
| Start Adb Service |
"""
try:
text = os.popen('adb start-server')
content = text.read()
print content
if '5037' not in content:
self.__raise_error('Error: start ADB server failed. %s' % content)
else:
print 'Pass! ADB server started.'
except Exception, e:
print str(e)
def get_device_name(self):
"""
Get Devices Name through ADB command.
Examples:
| ${device_name} | Get Adb Devices |
"""
device_name = ''
adb_devices = "adb devices"
try:
text = os.popen(adb_devices)
content = text.read().strip()
print content
res = content.splitlines()
if 'device' not in content:
self.__raise_error('Error: Could Not get device -> {}'.format(res[-1].split()[1]))
device_name = res[-1].split()[0]
except Exception, e:
if str(e) == 'list index out of range':
self.__raise_error('Error: Could NOT find device! Please check the phone has been attached to TestBed.')
else:
print str(e)
return device_name
def set_device_name(self, name=None):
"""
Set Devices Name after get its name through ADB command.
Examples:
| Set Device Name |
"""
if name == None:
device_name = self.get_device_name()
else:
device_name = name
if config['G_APP_DEVICE_NAME'] != '' and config['G_APP_DEVICE_NAME'] == device_name:
print '-'*30
print 'Pass! Set device name!'
print 'Device Name:' + config['G_APP_DEVICE_NAME']
print '-'*30
elif device_name == '':
self.__raise_error('FAIL: Could NOT get device name!')
else:
config['G_APP_DEVICE_NAME'] = str(device_name)
print '-'*30
print 'Pass! Set device name!'
print 'Device Name: ' + config['G_APP_DEVICE_NAME']
print '-'*30
def get_phone_info(self, dev=None):
if dev is None:
dev = config['G_APP_DEVICE_NAME']
cmd = "adb -s {} shell cat /system/build.prop".format(dev)
print cmd
lines = os.popen(cmd).readlines()
for line in lines:
if 'version.release' in line:
config['G_APP_DEVICE_VERSION'] = line.strip().split('=')[1] # Android 系统
elif 'ro.product.model' in line:
config['G_APP_DEVICE_MODEL'] = line.strip().split('=')[1] # 手机名
elif 'ro.product.brand' in line:
config['G_APP_DEVICE_BRAND'] = line.strip().split('=')[1] # 手机品牌
elif 'vm.heapsize' in line:
config['G_APP_DEVICE_HEAPSIZE'] = line.strip().split('=')[1] # 单个虚拟机最大内存
elif 'vm.heapgrowthlimit' in line:
config['G_APP_DEVICE_HEAPGROWTHLIMIT'] = line.strip().split('=')[1] # 每个APP最大内存
def get_total_mem(self, dev=None):
# 获取手机内存
if dev is None:
dev = config['G_APP_DEVICE_NAME']
try:
cmd = 'adb -s {} shell cat /proc/meminfo'.format(dev)
print cmd
res = os.popen(cmd)
for line in res.readlines():
if 'MemTotal:' in line:
config['G_APP_DEVICE_MEMORY'] = line.split('MemTotal:')[1].strip()
break
except Exception, e:
print str(e)
def get_cpu_kernels(self, dev=None):
# 获取手机CPU内核数
if dev is None:
dev = config['G_APP_DEVICE_NAME']
try:
cmd = 'adb -s {} shell cat /proc/cpuinfo |findstr processor'.format(dev)
print cmd
content = os.popen(cmd)
res = content.readlines()
if 'processor' in res[0]:
config['G_APP_DEVICE_CPU_KERNELS'] = len(res)
else:
print 'Could NOT get CPU kenels!'
except Exception, e:
print str(e)
def adb_install_package(self, apk=None, package_name=None):
"""
Install packages through ADB command.
Examples:
| Adb Install Package | ${apk_name} | ${package_name} |
"""
if apk is None:
apk = config['G_APP_PACKAGE_NAME']
# else:
# apk = os.path.join(config['G_APP_PACKAGE_NAME'], apk)
if package_name is None:
package_name = config['G_APP_PACKAGE_NAME']
if self.is_package_installed(package_name):
self.adb_uninstall_package(package_name)
try:
cmd = 'adb -s {} install -r {}'.format(config['G_APP_DEVICE_NAME'], apk)
print cmd
text = os.popen(cmd)
content = text.read()
print content
if 'Success' in content:
print 'Pass: Install {} succeeded. Version: {}'.format(package_name, apk)
else:
self.__raise_error('Fail: Could NOT install {}'.format(package_name))
except Exception, e:
print str(e)
def adb_uninstall_package(self, package_name=None):
"""
Uninstall packages through ADB command.
Examples:
| Adb Uninstall Package | ${package_name} |
"""
if package_name is None:
package_name = config['G_APP_PACKAGE_NAME']
if not self.is_package_installed(package_name):
self.__raise_error('Fail: APP {} is not installed.'.format(package_name))
try:
cmd = 'adb -s {} uninstall {}'.format(config['G_APP_DEVICE_NAME'], package_name)
print cmd
text = os.popen(cmd)
content = text.read()
print content
if 'Success' in content:
print 'Pass: Uninstall {} succeeded.'.format(package_name)
else:
self.__raise_error('Fail: Could NOT uninstall {}'.format(package_name))
except Exception as e:
print str(e)
def is_package_installed(self, package_name):
"""
Check target package is installed through ADB command.
Examples:
| ${status} | Is Package Installed |
"""
packages = self.get_third_party_packages()
if package_name in packages:
return True
else:
return False
def get_third_party_packages(self):
"""
Get Third-party packages through ADB command.
Examples:
| ${apk_name} | Get Third Party Packages |
"""
apks = []
try:
f = os.popen('adb shell pm list package -3')
for x in f.readlines():
没有合适的资源?快使用搜索试试~ 我知道了~
autoMonkey框架源代码
共15个文件
py:8个
pyc:7个
5星 · 超过95%的资源 需积分: 9 33 下载量 129 浏览量
2017-11-21
09:25:27
上传
评论
收藏 24KB RAR 举报
温馨提示
当前移动互联网已经过了草创时期,各家公司都在抢占市场和用户;那么,就看哪一家做的更精致(交互做的更好,崩溃出现的更少)。 Android用户也许会经常碰到以下的问题: 1.稳定性问题 —— ANR /Crash等问题;ANR是指当Android系统监测到应用程序在5秒内没有响应输入的事件或广播在10秒内没有执行完毕时抛出无响应提示。Crash是指当应用程序出现错误时导致程序异常停止或退出的情况。 2.性能问题 —— 应用启动慢(首次/非首次启动应用,进入应用特别慢),CPU不足/内存泄露(应用使用过程中,越来越卡),应用耗电快(应用后台开着,手机很快没电)等问题。 注:卡顿与ARN的问题。卡顿简单的来说,就是手机没有及时响应、页面延迟,出现丢帧的现象,或者点击无响应。绝大多数的卡顿,稍等片刻系统就会恢复正常,但假如超过5S,就可能会引发手机ANR警告。 APP测试涉及各个方面,而稳定性和性能测试一般在功能测试完成后开展。
资源推荐
资源详情
资源评论
收起资源包目录
autoMonkey.rar (15个子文件)
autoMonkey
conf
config.py 2KB
__init__.pyc 134B
config.pyc 1KB
__init__.py 18B
setCondition.py 906B
setCondition.pyc 1KB
start.pyc 2KB
core
appShell.pyc 20KB
util.py 11KB
util.pyc 10KB
__init__.pyc 134B
__init__.py 18B
appShell.py 24KB
__init__.py 18B
start.py 3KB
testLogs
共 15 条
- 1
资源评论
- qq_399278312018-12-18只想说寻寻觅觅终于找到了我想找的这只猴子
- qq_382653542018-12-07下载了,文件在哪?
- morrisxu2018-02-05看不到东西,评论啥
Allan_shore_ma
- 粉丝: 285
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 技术面试最后反问面试官的话 校招面试非技术问题有哪些 非技术问题如何回答.png
- NB-IOT-BC26全网通模块Altium+ CADENCE +PADS三种格式(原理图SCH+PCB封装库)文件.zip
- 基于微信小程序开发的校园失物招领系统源码毕业设计(优质项目源码).zip
- 词向量是一种将自然语言中的单词转换为数值向量的技术,它能够捕捉词义和上下文信息
- nmap与masscan的简单使用
- MyBatis动态SQL.pdf
- 基于stm32单片机protues仿真的温湿度控制系统设计(仿真图、源代码)
- 词向量:自然语言处理的基石
- mybatis动态sql
- 40G微信小程序开发教程(工具插件+视频教程)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功