Poco drivers (engine specific poco implementation)

不同的游戏引擎或app平台需要使用对应的driver去实例化poco对象。对应的API参考如下。

下面例子展示如何实例化poco对象来控制Unity3D游戏的UI对象。记得先连上一个android手机并打开 ADB调试模式

# import unity poco driver from this path
from poco.drivers.unity3d import UnityPoco

# then initialize the poco instance in the following way
poco = UnityPoco()

# for windows
# poco = UnityPoco(('localhost', 5001), unity_editor=True)

# now you can play with poco
ui = poco('...')
ui.click()

For cocos2dx-lua games are similar as Unity3d drivers.

# import standard poco driver
from poco.drivers.std import StdPoco
from airtest.core.api import connect_device

# connect a device first, then initialize poco object
device = connect_device('Android:///')
poco = StdPoco(10054, device)

# now you can play with poco
ui = poco('...')
ui.click()

如果连接了多个手机,调用airtest API里的 connect_device 函数来选其中一个。

from poco.drivers.unity3d import UnityPoco
from airtest.core.api import connect_device

connect_device('Android:///014E05DE0F02000E')  # connect device by serialno
poco = UnityPoco()

除了以上列出的引擎driver,其他的请参见 Integration guide

Device object

Device 是Airtest中的抽象对象,也是游戏或app运行的载体。在poco中,和UI交互(例如点击)就是通过Device对象的。见 Airtest device abstraction 查看Device相关的API。

两种方式与设备进行连接