Skip to content
This repository has been archived by the owner on Mar 1, 2019. It is now read-only.

Commit

Permalink
add desc how to install minicap to phone
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Mar 15, 2016
1 parent 3ce5885 commit 9b71809
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,39 @@ d.stop_app(package_name)

海马玩监听的端口是本机的26944,如果需要测试脚本运行在远程,用tcp转发到0.0.0.0就好了。方法有很多,微软自带的[netsh](https://technet.microsoft.com/en-us/library/cc776297(WS.10).aspx#BKMK_1) 或者直接参考目录下的 [scripts/simple-tcp-proxy.py](scripts/simple-tcp-proxy.py) 用代码实现

4. minicap是什么, 如何安装?

minicap是[openstf](https://github.com/openstf)开源项目中的一个子项目,用于手机快速的截图. 连接手机到电脑上之后,运行文件 [scripts/install-minicap.py](scripts/install-minicap.py)


5. 批量运行脚本

python有一个很好的测试框架 unittest (其他出色的也有nose, pytest) 等等,这里这是说下unittest 毕竟官方库, 直接上代码,一个简单的例子如下

```
# coding: utf-8

import unittest
import atx

d = atx.connect()

class SimpleTestCase(unittest.TestCase):
def setUp(self):
name = 'com.netease.txx'
d.stop_app(name).start_app(name)

def test_login(self):
d.click_image("confirm.png")
d.click_image("enter-game.png")
with d.watch('Enter game', 20) as w:
w.on("user.png").quit()


if __name__ == '__main__':
unittest.main()
```

## 代码导读
`connect` 函数负责根据平台返回相应的类(AndroidDevice or IOSDevice)

Expand Down
92 changes: 92 additions & 0 deletions scripts/install-minicap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Description: minicap setup scripts,
# Usage: python minicap_setup.py -s serialno -H host -P port
# Author: ydbn2153
# Created: 2016-03-15 ydbn2153

import argparse
import os
import sys
import shutil
import subprocess
import tempfile
import urllib
import functools


def log(msg):
print '>>> ' + msg


def check_output(cmdstr, shell=True):
output = subprocess.check_output(cmdstr, stderr=subprocess.STDOUT, shell=shell)
return output


def run_adb(*args, **kwargs):
cmds = ['adb']
serialno = kwargs.get('serialno', None)
if serialno:
cmds.extend(['-s', serialno])
host = kwargs.get('host')
if host:
cmds.extend(['-H', host])
port = kwargs.get('port')
if port:
cmds.extend(['-P', str(port)])
cmds.extend(args)
cmds = map(str, cmds)
cmdline = subprocess.list2cmdline(cmds)
return check_output(cmdline, shell=False)


def minicap_setup(serialno=None, host=None, port=None):
log("Minicap install started!")

adb = functools.partial(run_adb, serialno=serialno, host=host, port=port)

# Figure out which ABI and SDK
log("Get device basic information ...")
abi = adb('shell', 'getprop', 'ro.product.cpu.abi').strip()
sdk = adb('shell', 'getprop', 'ro.build.version.sdk').strip()
tmpdir = tempfile.mkdtemp(prefix='ins-minicap-')
log("Make temp dir ...")
print tmpdir
try:
log("Downloading minicap.so ....")
url = "https://github.com/openstf/stf/raw/master/vendor/minicap/shared/android-"+sdk+"/"+abi+"/minicap.so"
target_path = os.path.join(tmpdir, 'minicap.so')
download(url, target_path)
log("Push data to device ....")
adb('push', target_path, '/data/local/tmp')

log("Downloading minicap ....")
url = "https://github.com/openstf/stf/raw/master/vendor/minicap/bin/"+abi+"/minicap"
target_path = os.path.join(tmpdir, 'minicap')
download(url, target_path)
log("Push data to device ....")
adb('push', target_path, '/data/local/tmp')
adb('shell', 'chmod', '0755', '/data/local/tmp/minicap')

log("Checking [dump device info] ...")
print adb('shell', 'LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -i')
log("Minicap install finished !")
finally:
if tmpdir:
log("Cleaning temp dir")
shutil.rmtree(tmpdir)


def download(url, target_path):
return urllib.urlretrieve(url, target_path)


if __name__ == "__main__":
parser = argparse.ArgumentParser("cli")
parser.add_argument("-s", "--serialno", help="serialno of device", default=None)
parser.add_argument("-H", "--host", help="host of remote device", default=None)
parser.add_argument("-P", "--port", help="port of remote device", default=None)
args = parser.parse_args(sys.argv[1:])
minicap_setup(serialno=args.serialno, host=args.host, port=args.port)

0 comments on commit 9b71809

Please sign in to comment.