Metadata-Version: 2.1
Name: androidautotest
Version: 0.0.2.33
Summary: android test framework using adb connection and template matching in opencv
Home-page: https://github.com/15045120/AndroidTest
Author: 15045120
Author-email: 1337078409@qq.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.5
Description-Content-Type: text/markdown
Requires-Dist: psutil
Requires-Dist: pillow
Requires-Dist: numpy
Requires-Dist: opencv-python

# 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.
## Requirement
 1.ADB ([Android Debug Bridge](https://github.com/15045120/AndroidTest/tree/master/dependency/adb))


2.ASM ([Android Screen Monitor](https://github.com/15045120/AndroidTest/blob/master/dependency/asm.jar))

 Use to capture partial picture, and you need to install JDK in your computer before running it.

 Then adjust zoom to 50%, you can also set zoom to other size, but need to add some code in your case source file after your create your case file:
```python
# adjust asm zoom to other size, 25% 
ASM.ZOOM_SIZE = 25
```

3.Tesseract ([Tesseract-OCR](https://github.com/tesseract-ocr/tesseract))

 If you want to use the mechod 'image_to_string' in the 'androidautotest.api' which can recognize text in pictures, you need to install Tesseract and install testdata necessary like chinese 'chi_sim'.

## Installation & Usage

 1.Install androidautotest
```bash
pip install androidautotest 
```
Follow information indicate you have installed androidautotest successfully.
```bash
> python -m androidautotest
usage:
  androidautotest --installdep
  androidautotest --startasm
  androidautotest --newcase <NEWCASE> --savedir <SAVEDIR>
  androidautotest --casedir <CASEDIR> --device <DEVICE> --times <TIMES>

A framework to run test case for android automated test

optional arguments:
  -V, --version        Print version and exit
  -h, --help           Print this help message and exit

install dependency:
  --installdep         install dependency of androidautotest

start asm:
  --startasm           start Android Screen Monitor

create case:
  --newcase <NEWCASE>  New case name to create
  --savedir <SAVEDIR>  Path to save new case

run case:
  --casedir <CASEDIR>  Case path to run
  --device <DEVICE>    Device to switch
  --times <TIMES>      Times of case running
```
 2.install requirements 

```bash
python -m androidautotest --installdep
```
 3.start Android Screen Monitor(First, connect your Android Phone with PC, and open adb debug mode), then run follow command:

```bash
python -m androidautotest --startasm
```
 4.create a new case to start your test task with Android Phone(For example: to create a new case named 'case001').

```bash
python -m androidautotest --newcase case001 --savedir E:\AndroidTest\workspace
```
## Documentation
You can find the complete AndroidTest API documentation on  [readthedocs](http://androidtest.readthedocs.io/).
## Examples
```python
# -*- coding: UTF-8 -*-
from androidautotest.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.
1.If you connect one Android Phone with your PC, and run for once time, simple wirte as following
```bash
python -m androidautotest --casedir E:\AndroidTest\workspace\case001.air --device HMKNW17421063974 --times 5
```
2.If you connect more than one Android Phone with your PC, run case with Android Phone which's serial number is 'HMKNW17421063974' for 5 times, you can write as following.
```bash
python -m androidautotest --casedir E:\AndroidTest\workspace\case001.air --device HMKNW17421063974 --times 5
```

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

In case001.air\log\case001.log.XXX
<table>
<thead>
<tr><th>File Name</th><th>Description</th></tr>
</thead></tr>
</thead>
<tbody>
<tr><td>log_case001_XXX.txt</td><td>all log output</td></tr>
<tr><td>serial_log_case001_XXX.txt</td><td>adb log output </td></tr>
<tr><td>report_case001_XXX.html</td><td>report of case run</td></tr>
</tbody>
</table>







