Poco SDK

repository·master·Indexed 43 days ago

https://github.com/airtestproject/poco-sdk

A SDK for inspecting and interacting with the UI tree of games. It provides integration support for Unreal Engine (UE4), Unity3D (supporting ngui, ugui, and fairygui), Cocos Creator 2.2.1+, and Egret Engine. It includes a Python driver (pocoui) and a WebSocket-based server interface for UI automation and inspection via AirtestIDE.

Tokens
4.5K
Snippets
12
Records
24
Agent score
56%

What's inside Poco SDK

  1. Unity3D PocoSDK Compatibility and Requirements

    master

    PocoSDK for Unity3D has the following requirements and support constraints:

    • Unity Versions: Supports Unity3D version 4, 5, and above.
    • UI Frameworks: Supports ngui, ugui, and fairygui.
    • Language Support: Currently supports C# only. Lua calls are not supported at this time.
  2. Use the base SDK to implement a new engine support

    master
    If you need to implement poco-sdk for a game engine not currently supported, use the contents of the sdk directory. This directory contains the unimplemented language-specific base SDK which serves as the foundation for engine-specific implementations.
  3. Integrate PocoSDK with Unity3D

    master

    To integrate PocoSDK into a Unity3D project, follow these steps:

    1. Clone the Repository: Clone the source code from the poco-sdk repository.
    2. Import Files: Copy the Unity3D folder from the repository into your Unity project's Scripts folder.
    3. Clean up UI Framework Folders: To avoid conflicts, delete the subfolders for the UI frameworks you are not using:
      • If using ngui: Delete Unity3D/ugui and Unity3D/fairygui.
      • If using ugui: Delete Unity3D/ngui and Unity3D/fairygui.
      • If using fairygui: Refer to the specific fairygui guide.
    4. Initialize the SDK: Add the Unity3D/PocoManager.cs script as a component to any GameObject in your scene. It is recommended to attach it to the Main Camera or a dedicated empty GameObject.
  4. Install Poco SDK for Egret Engine

    master

    To integrate Poco SDK into an Egret project, follow these steps:

    1. Download Poco SDK: Obtain the SDK files.
    2. Configure egretProperties.json: Add the SDK to the modules property. The name attribute must be set to poco.
      "modules": [
        {
          "name": "poco",
          "path": "path/to/poco-sdk"
        }
      ]
      The path can be relative or absolute.
    3. Build the project: Open a terminal (Ctrl + `) and run:
      egret build -e
    4. Initialize PocoManager: In your entry file main.ts, create a new PocoManager instance inside the rungame function and pass this.stage to it.
    5. Start the Broker: Run the proxy server in your terminal:
      python -m poco.utils.net.stdbroker ws://*:5003 tcp://*:15004
      Note: The default websocket port is 5003. If you change this port, you must pass the new port parameter when initializing PocoManager in your code.
    // In main.ts
    function rungame() {
        // ...
        const pocoManager = new PocoManager(this.stage);
    }
  5. Connect AirtestIDE to Mobile Browsers (Android/iOS)

    master

    To inspect UI hierarchies on mobile devices running Egret pages (or WeChat mini-programs/games), follow these steps:

    1. Map Ports (Android only): Connect your Android device via USB and ensure adb devices recognizes it. Run the following command to map the mobile port 5003 to your computer's port 5003:
      adb reverse tcp:5003 tcp:5003
    2. Start the Broker: On your computer, start the proxy server:
      python -m poco.utils.net.stdbroker "ws://*:5003" "tcp://*:15004"
    3. Access the Page: Open the Egret page on the mobile device. It is recommended to use full-screen mode to ensure accurate coordinate positioning. The broker terminal will log connections when successful.
    4. Connect in AirtestIDE:
      • Open AirtestIDE.
      • Select the poco Std-broker connection mode.
      • Once connected, you can view the UI hierarchy and run scripts.
    # Map ports for Android
    adb reverse tcp:5003 tcp:5003
    
    # Start the broker
    python -m poco.utils.net.stdbroker "ws://*:5003" "tcp://*:15004"
  6. Connect AirtestIDE to Desktop Browsers (Windows)

    master

    AirtestIDE supports connecting to Windows browser windows for UI inspection. Note that MacOS window support is currently unavailable.

    1. Run Project and Broker: Run your Egret project in a browser and start the broker proxy on your computer:
      python -m poco.utils.net.stdbroker ws://*:5003 tcp://*:15004
    2. Configure AirtestIDE: Set the connection mode to embedded mode (使用嵌入模式) in the IDE settings.
    3. Connect Window: Use the Select Window (选定窗口) feature in AirtestIDE to connect to the browser window. The browser window will then appear within the IDE.
    4. Select Game Area: Use the poco window area select setting to draw a bounding box around the specific game/application area within the browser.
    5. Inspect UI: Once the area is defined, you can use the Inspector feature to view and interact with the UI hierarchy.
    # Start the broker for desktop connection
    python -m poco.utils.net.stdbroker ws://*:5003 tcp://*:15004
  7. Use UE4Poco to automate Unreal Engine UI

    master

    You can use the UE4Poco driver to connect to a running Unreal Engine game and interact with its UI tree via Python scripts.

    Standard Connection

    To connect to a running game process:

    from poco.drivers.ue4 import UE4Poco
    
    # Initialize the driver
    poco = UE4Poco()
    
    # Interact with a widget
    # Example: clicking a button named 'StartButton'
    poco("StartButton").click()

    Editor Mode Connection

    To connect while running in the Unreal Editor (PIE mode), pass ue4_editor=True. Note: The Unreal Editor language must be set to English for this to work.

    from poco.drivers.ue4 import UE4Poco
    
    # Initialize for editor mode
    poco = UE4Poco(ue4_editor=True)

    Custom Window Connection

    If the automatic connection fails, you can manually specify the device handle in poco/drivers/ue4/device.py. For example, to connect to a specific Unreal window using a regular expression for its title:

    # Example for older UE4 versions (pre-4.26) targeting 'Game Preview Standalone'
    dev = connect_device("Windows:///?class_name=UnrealWindow&title_re=.*Game Preview Standalone.*")
    
    # For UE4 versions 4.26 and above, the window name is typically 'Preview [NetMode: Standalone]'
    from poco.drivers.ue4 import UE4Poco
    
    poco = UE4Poco()
    # example
    poco("StartButton").click()
  8. Integrate poco-sdk into your game engine

    master

    The poco-sdk repository provides implementations for various popular game engines. To use the SDK in your project:

    1. Identify the directory corresponding to your game engine.
    2. Copy that engine-specific directory into your project.
    3. Initialize the provided module or class from your game scripts.

    For a more detailed step-by-step process, refer to the official Integration Guide.

  9. Install Poco SDK for Unreal Engine

    master

    To integrate Poco SDK into your Unreal Engine project, follow these steps:

    1. Clone the PocoSDK directory from the UE4 Poco SDK repository.
    2. Place the PocoSDK folder into your project's Plugins directory. Create the Plugins directory if it does not exist.
    3. Recompile your project.
    4. In the Unreal Editor, navigate to Edit > Plugins and verify that Poco SDK is visible and the Enabled checkbox is checked. If it is not checked, enable it and restart the editor or Visual Studio as prompted.