android test framework using adb connection and template matching in opencv


License
MIT
Install
pip install androidautotest==0.0.2.33

Documentation

AndroidTest

The package is for android auto test, based on Python enviroment.

Basic thought is using ADB (Android Debug Bridge) to send command to Android test Phone connected with the PC and match picture by match template algorithm in opencv-python.

Installation

  1. Install ADB (Android Debug Bridge), and add it to path.

  2. Use ASM (Android Screen Monitor) to capture partial picture, and you need to install JDK in your computer first to run it.

    • Simple to use:
    java -jar asm.jar
    • Then adjust zoom to 50%, you also can set to other size, but need to add some code in your case source file after your create your case file:
    # if adjust asm zoom to 25% 
    ASM.ZOOM_SIZE = 25
  3. Install androidautotest

pip install androidautotest 
  1. Install dependency before run your case file, Use tools\install.py
python install.py
  1. Use tools\newCase.py to create a new case to start your test task with Android Phone.
python newCase.py <caseName> <savePath>

Documentation

You can find the complete AndroidTest documentation on readthedocs.

Examples

# -*- coding: UTF-8 -*-
from androidtest.api import *

# to home
keyevent(HOME)
keyevent(HOME,device='HMKNW17421063974')

# to FileBrowser
while not exists(Template(r'pic\20191215121636.png')):
	flick((400,400),DIR_LEFT,step=2)
touch(Template(r'pic\20191215121636.png'))
touch(Template(r'pic\20191215134814.png'))

# not in top screen of FileBrowser
if exists(Template(r'pic\20191215143440.png')):
	touch(Template(r'pic\20191215142057.png'))
	text('15045120')
else:
	touch([530,142])
	text('15045120')

# 15045120 is in screen
assert_exists(Template(r'pic\20191215142425.png'))

end()

Once you finish your code writing, you can run your case(for example: you create a case named 'case001'):

cd case001.air
python case001.py

And there are three log files you can use to analyze your test plan after run your case.

  • case001.air\case001.log.20191222010717_540637\log_case001_20191222010717_540637.txt
  • case001.air\case001.log.20191222010717_540637\serial_log_case001_20191222010717_540637.txt
  • case001.air\case001.log.20191222010717_540637\report_case001_20191222010717_540637.html

log_case001_XXX: all log output serial_log_case001_XXX: adb log output serial_log_case001_XXX: report of case run