Introduction of Poco¶
Earlier we introduced Airtest, a test framework based on image recognition. With image recognition, we can already write most test scripts.However, in some special cases, such as for dynamic elements in games or apps, it is more difficult to locate them through image recognition. Therefore, our Airtest Project solution also provides Poco, another automation framework based on UI control search. Let's take an example to see how Poco is used.
For native applications (including system interface) on Android and iOS platforms, you can use Poco directly.
Preparation: Download Airtest IDE, unzip and run it.
Android native applications¶
- Prepare an Android phone, turn on the USB debugging function, and then connect the computer. Under normal circumstances, you can see the phone list in Airtest IDE:
connectand you will see the device screen in Airtest IDE. Now enter the Android main interface, click the Poco auxiliary window on the left, select the
Androidmode, and you can see the UI tree structure of the current interface:
- Select the
Poco Inspectorbutton in the Poco auxiliary window to position the UI controls on the page:
- Similar to the way Airtest is used, we can use the methods provided by Poco to operate the elements on the interface:
# Initialization statement automatically inserted by Airtest IDE from poco.drivers.android.uiautomation import AndroidUiautomationPoco poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) # Click on the settings icon poco(desc="settings").click()
As shown in the code above, you can locate elements and perform operations through UI properties.
For more details on using Poco to test Android native applications, you can refer to the tutorial (How to Automate Testing on Android Phones）.
iOS native app¶
For iOS native applications, Poco can also get the UI hierarchy. In addition to downloading and running the Airtest IDE, we also need to run the ios-Tagent project to get the UI information of the iOS interface. Specific steps are as follows:
- Connect an iOS phone, start the ios-Tagent project, and run it on the phone in Test mode.
- Use the
iproxycommand to start the proxy
bash iproxy 8100 8100If you want to connect your iOS phone to another computer, you can install wdaproxy
- Start Airtest IDE and enter the proxy address to connect to iOS phone
- Select the
iOSmode in the Poco auxiliary window, and you can see the UI tree structure of the current interface:
- After getting the UI level relationship of the interface, we can use the API provided by Poco to write automation scripts ~
Because the game interface is rendered by the game engine, and the game interface does not have the system's native control information. So for games, we need to access poco-sdk to get the control information in the game interface. The following uses the mobile game developed by Unity as an example to introduce how to connect on Android and iOS platforms.
- Refer to Engine Access Guide to access Poco-sdk. The following is the access method in Unity:
- Start the Airtest IDE and start the corresponding game. Select the
Unitymode in the Poco auxiliary window to see the UI tree structure of the current interface:
- After selecting Unity mode, Airtest IDE will automatically insert poco's initialization code:
from poco.drivers.unity3d import UnityPoco poco = UnityPoco()
After that, we can write scripts to use the API provided by Poco to operate the elements on the game interface.
- Similarly, you need to connect to the engine SDK first, and then connect to the iOS phone through the Airtest IDE.
- Different from Android, the connection of iOS Unity Poco requires starting two proxy. 8100 port is used to connect iOS mobile phone, and 5001 port is used to connect to rpc port of poco-sdk.
iproxy 8100 8100 iproxy 5001 5001Iproxy here is equivalent to forward in adb.
- After connecting the iOS phone, select the
Unitymode in the Poco auxiliary window, and you can see the UI tree structure of the current interface:
- Then you can write automated test scripts for games on iOS through the API provided by Poco.
Poco's platform support¶
Poco needs to be connected to Poco-SDK before it can be used normally on most platforms. However, on a few platforms (such as Android and iOS native apps), Poco can be used directly. The currently supported platforms are as follows:
|Cocos2dx-js, Cocos2dx-lua||√||Access document|
|Android native APP||√||use directly|
|Other engines||√||Access by yourself|
|WeChat Applet&webview||√||Reference documents may become invalid with WeChat update|
|Windows, MacOS||√||Stay tuned|
|Netease||√||Engine help documentation for NetEase internal|
In the document Poco Support Platform, you can get the latest updated platform support.
More details reference¶
Please check the Poco official documentation for more tutorials and API information, here are some of the more concerned content: