Play with coordinate system and local positioning

In poco, coordinates are always normalized from 0 to 1. You can simply think of it the percentage size and positions. In case that you need to interact with UI nearby or just want to click the button’s edge rather than the center, you can use local positioning by specifying a offset.

In general, to interact with UI always starts with a point, such as click or drag from the point. Local positioning allows you to make any offset from the selected UI without selecting another UI.

../../../_images/hunter-poco-coordinate-system.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)

See also: