坐标系与局部定位

poco里的坐标的取值范围是相对于屏幕的,屏幕的宽和高都为单位1,因此也叫百分比坐标。当你需要和某个UI控件附近的UI控件交互或者要点击某个按钮的边缘而不是中间时,那可以用 局部定位

总的来说,和UI控件交互最终都是和坐标交互,例如点击一个按钮实际上就是点击某个坐标。 局部定位 就可以基于某个UI的左上角进行偏移,然后可以实现点击到这个UI控件内的各个坐标甚至UI外面的其他坐标。

../../../_images/hunter-poco-coordinate-system1.png

Internal offset

The following examples will show how to click different point inside selected UI. Please pay attention on the red dot on the GIF underneath.

../../../_images/local_positioning1.gif
# coding=utf-8

import time
from poco.drivers.unity3d import UnityPoco

poco = UnityPoco()

image = poco('fish').child(type='Image')
image.focus('center').long_click()
time.sleep(0.2)
image.focus([0.1, 0.1]).long_click()
time.sleep(0.2)
image.focus([0.9, 0.9]).long_click()
time.sleep(0.2)
image.focus([0.5, 0.9]).long_click()
time.sleep(0.2)

External offset

Can also click outside the selected UI. It is very useful to click some models by its name tag. Please pay attention on the red dot on the GIF underneath.

../../../_images/local_positioning2.gif
# coding=utf-8

from poco.drivers.unity3d import UnityPoco

poco = UnityPoco()

balloonfish_image = poco(text='balloonfish').focus([0.5, -3])
balloonfish_image.long_click()

Immutability

The following examples show that focus is an immutable method that will not impact the origin UI. Please pay attention on the red dot on the GIF underneath.

../../../_images/local_positioning3.gif
# coding=utf-8

from poco.drivers.unity3d import UnityPoco

poco = UnityPoco()

# focus is immutable
fish = poco('fish').child(type='Image')
fish_right_edge = fish.focus([1, 0.5])
fish.long_click()  # still click the center
time.sleep(0.2)
fish_right_edge.long_click()  # will click the right edge
time.sleep(0.2)

Gracefully scroll

The following example show how to scroll a list by using drag.

../../../_images/scroll2.gif
# coding=utf-8

import time
from poco.drivers.unity3d import UnityPoco

poco = UnityPoco()

listView = poco('Scroll View')
listView.focus([0.5, 0.8]).drag_to(listView.focus([0.5, 0.2]))
time.sleep(1)

更多示例: