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

Commit

Permalink
add todo
Browse files Browse the repository at this point in the history
  • Loading branch information
shengxiang committed Mar 16, 2016
1 parent b628eb6 commit 9bc6d3c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 35 deletions.
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,34 @@ d.stop_app(package_name)
如何点击UI元素请直接看 <https://github.com/codeskyblue/airtest-uiautomator>
里面的API是直接通过继承的方式支持的。

## 批量运行脚本

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()
```

## FAQ
1. 如果连接远程机器上的安卓设备

Expand Down Expand Up @@ -264,34 +292,6 @@ d.stop_app(package_name)
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
9 changes: 9 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## TODO
1. Region

- bounds
- region(left, right, top, bottom)
2. Patten

- filename
- offset
2 changes: 1 addition & 1 deletion atx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from atx.consts import *
from atx.errors import *
from atx.device import Watcher
from atx.device import Patten
from atx import imutils


Expand Down
17 changes: 11 additions & 6 deletions atx/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
'.*DisplayViewport{valid=true, .*orientation=(?P<orientation>\d+), .*deviceWidth=(?P<width>\d+), deviceHeight=(?P<height>\d+).*')


class ImageSelector(object):
class Patten(object):
def __init__(self, image, offset=(0, 0), anchor=0):
self._name = None
self._image = imutils.open(image)
Expand Down Expand Up @@ -90,7 +90,7 @@ def on(self, image=None, actions=None, text=None):
None
"""
if isinstance(image, basestring):
self._stored_selector = ImageSelector(image)
self._stored_selector = Patten(image)
elif text:
self._stored_selector = self._dev(text=text)

Expand All @@ -117,7 +117,7 @@ def __exit__(self, type, value, traceback):

def _match(self, selector, screen):
''' returns position(x, y) or None'''
if isinstance(selector, ImageSelector):
if isinstance(selector, Patten):
ret = self._dev.match(selector.image, screen=screen)
if ret is None:
return None
Expand Down Expand Up @@ -180,6 +180,7 @@ class DeviceMixin(object):
def __init__(self):
self.image_match_method = consts.IMAGE_MATCH_METHOD_TMPL
self.resolution = None
self._bounds = None

def sleep(self, secs):
"""Sleep some seconds
Expand Down Expand Up @@ -218,8 +219,8 @@ def match(self, img, screen=None):
Raises:
SyntaxError: when image_match_method is invalid
"""
if not isinstance(img, ImageSelector):
selector = ImageSelector(img)
if not isinstance(img, Patten):
selector = Patten(img)
# search_img = imutils.open(img)
search_img = selector.image
if screen is None:
Expand Down Expand Up @@ -252,6 +253,10 @@ def match(self, img, screen=None):
confidence = ret['confidence']
return FindPoint(position, confidence, self.image_match_method)

def region(self):
"""TODO"""
return self

def touch_image(self, *args, **kwargs):
"""ALias for click_image"""
self.click_image(*args, **kwargs)
Expand Down Expand Up @@ -289,7 +294,7 @@ def click_image(self, img, timeout=20.0, wait_change=False):
start_time = time.time()
while time.time()-start_time < timeout:
screen_img = self.screenshot()
ret = ac.find_template(screen_img, search_img)
ret = self.match(search_img)
if ret is None:
break

Expand Down

0 comments on commit 9bc6d3c

Please sign in to comment.