### Poco Script Examples: Initialization and Operations Source: https://airtest.doc.io.netease.com/tutorial/3_Poco_introduction This comprehensive example demonstrates Poco script structure, including initialization for Android, and common control operations such as clicking, swiping, checking for existence, waiting for appearance, getting text, and drag-and-drop actions. ```python # -*- encoding=utf8 -*- __author__ = "AirtestProject" from airtest.core.api import * auto_setup(__file__) # Android poco的初始化脚本 from poco.drivers.android.uiautomation import AndroidUiautomationPoco poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False) # 控件点击操作 poco("网易云音乐").click() # 控件滑动操作 poco(text="我好像在哪见过你 (电影《精灵王座》主题曲)").swipe([0.0492, -0.3799]) # 如果存在控件,则进行控件点击 if poco("star_single").exists(): poco("pos_input").child("Text").click() # 等待控件出现 poco("basic").wait_for_appearance() # 获取控件文本属性 score = poco("scoreVal").get_text() # 遍历控件和拖动控件 for star in poco("playDragAndDrop").child("star"): star.drag_to(poco("shell")) ``` -------------------------------- ### Connecting Windows Window/Desktop: Examples Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/2_connect_device Provides examples of connecting to Windows windows or the desktop using `auto_setup`, `connect_device`, and `init_device`. ```APIDOC ## Connecting Windows Window/Desktop: Examples ### Description Demonstrates connecting to Windows windows or the desktop using different Airtest functions. ### Examples * **Using `auto_setup`**: ```python auto_setup(__file__, devices=["Windows:///" ] ) ``` * **Using `connect_device`**: ```python connect_device("Windows:///?title_re=Unity.*") ``` * **Using `init_device`**: ```python init_device(platform="Windows", uuid="123456") ``` ``` -------------------------------- ### Connecting iOS Devices: Examples Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/2_connect_device Shows examples of connecting to iOS devices using `auto_setup`, `connect_device`, and `init_device`. ```APIDOC ## Connecting iOS Devices: Examples ### Description Demonstrates connecting to iOS devices using different Airtest functions. ### Examples * **Using `auto_setup`**: ```python auto_setup(__file__, devices=["iOS:///http://127.0.0.1:8100"]) ``` * **Using `connect_device`**: ```python connect_device("iOS:///http://127.0.0.1:8100") ``` * **Using `init_device`**: ```python init_device(platform="IOS", uuid="http://127.0.0.1:8100") ``` ``` -------------------------------- ### Install Airtest Framework Source: https://airtest.doc.io.netease.com/IDEdocs/3.4run_script/0_run_script Install the Airtest framework using pip. For users in China, append '-i https://pypi.tuna.tsinghua.edu.cn/simple' to the pip install command if it fails. ```bash pip install airtest ``` -------------------------------- ### Executing Setup and Teardown Sub-scripts Source: https://airtest.doc.io.netease.com/IDEdocs/3.6settings/3_script_record_features Shows how to execute separate Airtest scripts for setup and teardown within the custom launcher's setUp and tearDown methods using `exec_other_script`. ```python class CustomAirtestCase(AirtestCase): PROJECT_ROOT = "子脚本存放公共路径" # 可以将子脚本放置在某个公共目录下 def setUp(self): # exec setup script self.exec_other_script("setup.air") # 假设该setup.air脚本存放在PROJECT_ROOT目录下,调用时无需填写绝对路径,可以直接写相对路径 super(CustomAirtestCase, self).setUp() def tearDown(self): # exec teardown script self.exec_other_script("teardown.air") super(CustomAirtestCase, self).setUp() ``` -------------------------------- ### Install Airtest-Selenium Library Source: https://airtest.doc.io.netease.com/tutorial/13_Selenium Install the airtest-selenium library using pip. If 'pynput' is missing, install it first. ```bash pip install airtest-selenium ``` ```bash pip install pynput pip install airtest-selenium ``` -------------------------------- ### Custom Launcher Example Source: https://airtest.doc.io.netease.com/IDEdocs/3.6settings/3_script_record_features A custom launcher script that extends AirtestCase to add custom setup and teardown logic. This can be used to initialize custom environments before running actual test cases. ```python from airtest.cli.runner import AirtestCase, run_script from airtest.cli.parser import runner_parser class CustomAirtestCase(AirtestCase): def setUp(self): print("custom setup") # add var/function/class/.. to globals # self.scope["hunter"] = "i am hunter" # self.scope["add"] = lambda x: x+1 # exec setup script # self.exec_other_script("setup.owl") super(CustomAirtestCase, self).setUp() def tearDown(self): print("custom tearDown") # exec teardown script # self.exec_other_script("teardown.owl") super(CustomAirtestCase, self).setUp() if __name__ == '__main__': ap = runner_parser() args = ap.parse_args() run_script(args, CustomAirtestCase) ``` -------------------------------- ### Connect iOS Devices Examples Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/2_connect_device Demonstrates connecting iOS devices using auto_setup, connect_device, and init_device. ```python # 使用auto_serup auto_setup(__file__,devices=["iOS:///http://127.0.0.1:8100"]) # 使用connect_device connect_device("iOS:///http://127.0.0.1:8100") # 使用init_device init_device(platform="IOS",uuid="http://127.0.0.1:8100") ``` -------------------------------- ### Click Button Example in UE4 Source: https://airtest.doc.io.netease.com/IDEdocs/poco_framework/6_poco_sdk A simple example demonstrating how to click a UI element identified by its name, such as a 'StartButton', using the UE4 POCO driver. ```python # example poco("StartButton").click() ``` -------------------------------- ### Connect Windows Devices Examples Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/2_connect_device Demonstrates connecting to Windows devices (windows or desktop) using auto_setup, connect_device, and init_device. ```python # 使用auto_serup auto_setup(__file__,devices=["Windows:///" ] ) # 使用connect_device connect_device("Windows:///?title_re=Unity.*") # 使用init_device init_device(platform="Windows",uuid="123456") ``` -------------------------------- ### Install Airtest-Selenium Framework Source: https://airtest.doc.io.netease.com/IDEdocs/3.4run_script/0_run_script Install the airtest-selenium framework using pip. This is only necessary for web testing. ```bash pip install airtest-selenium ``` -------------------------------- ### Connect Android Devices Examples Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/2_connect_device Demonstrates connecting Android devices using auto_setup, connect_device, and init_device with specific parameters. ```python # 使用auto_serup auto_setup(__file__, devices=["Android://127.0.0.1:5037/SJE5T17B17"]) # 使用connect_device connect_device("Android:///SJE5T17B17?cap_method=javacap&touch_method=adb") # 使用init_device init_device(platform="Android",uuid="SJE5T17B17", cap_method="JAVACAP") ``` -------------------------------- ### POCO Broker Output Log Example Source: https://airtest.doc.io.netease.com/IDEdocs/poco_framework/6_poco_sdk This is an example of the log output when the POCO broker starts successfully for Egret projects, indicating the ports it is listening on and that it is ready to accept connections. ```log ~ python -m poco.utils.net.stdbroker "ws://*:5003" "tcp://*:15004" server listens on ("0.0.0.0", 5003) transport websocket server listens on ("0.0.0.0", 15004) transport socket StdBroker on. server on accept. ``` -------------------------------- ### Connecting Android Devices: Examples Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/2_connect_device Illustrates how to connect to Android devices using `auto_setup`, `connect_device`, and `init_device` with specific parameters. ```APIDOC ## Connecting Android Devices: Examples ### Description Demonstrates connecting to Android devices using different Airtest functions with various parameters. ### Examples * **Using `auto_setup`**: ```python auto_setup(__file__, devices=["Android://127.0.0.1:5037/SJE5T17B17"]) ``` * **Using `connect_device`**: ```python connect_device("Android:///SJE5T17B17?cap_method=javacap&touch_method=adb") ``` * **Using `init_device`**: ```python init_device(platform="Android", uuid="SJE5T17B17", cap_method="JAVACAP") ``` ``` -------------------------------- ### Install Poco Framework Source: https://airtest.doc.io.netease.com/IDEdocs/3.4run_script/0_run_script Install the Poco framework using pip. Ensure only 'pocoui' is installed to avoid conflicts with 'poco'. ```bash pip install pocoui ``` -------------------------------- ### Windows Device URI Examples Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/2_connect_device Examples of URI strings for connecting to Windows windows or the desktop, using window handles or title regular expressions. ```python # 连接一个窗口句柄为123456的Windows窗口 Windows:///123456 # 连接一个Windows窗口,窗口名称匹配某个正则表达式 Windows:///?title_re=Unity.* # 连接windows桌面,不指定任何窗口 Windows:/// ``` -------------------------------- ### Install and Uninstall Apps with Airtest Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/4_airtest_ADB Use `install()` to install an APK and `uninstall()` to remove an application by its package name. ```python install(r"D:\demo\tutorial-blackjack-release-signed.apk") # 卸载应用:uninstall_app() uninstall("org.cocos2dx.javascript") ``` -------------------------------- ### Windows Window String Formats Source: https://airtest.doc.io.netease.com/IDEdocs/3.4run_script/1_useCommand_runScript Examples of device strings for connecting to Windows windows by handle or title, including connecting to the desktop. ```bash # 连接一个Windows窗口,窗口句柄为123456 Windows:///123456 # 连接一个Windows窗口,窗口名称匹配某个正则表达式 Windows:///?title_re=Unity.* # 连接windows桌面,不指定任何窗口 Windows:/// ``` -------------------------------- ### Install APK with ADB Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/4_airtest_ADB Use `adb install` to deploy an APK file from your computer to the connected Android device. ```bash adb install "D:/demo/tutorial-blackjack-release-signed.apk" ``` -------------------------------- ### Install Airtest and Related Frameworks Source: https://airtest.doc.io.netease.com/IDEdocs/faq/0_no_airtestide Install the necessary Airtest frameworks using pip. Ensure your Python version is compatible (Python 3 to 3.9). Use a domestic mirror like Tsinghua if installation fails. ```shell # Install Airtest framework pip install airtest # Install Poco framework; needed if Poco statements are used pip install pocoui # Install airtest-selenium framework; needed if airtest-selenium statements are used pip install airtest-selenium ``` ```shell pip install -i https://pypi.tuna.tsinghua.edu.cn/simple airtest ``` -------------------------------- ### Install iOS application on simulator Source: https://airtest.doc.io.netease.com/tutorial/6_IOS_automated_testing Install an iOS application (.app file) onto a simulator using the simctl command. Note that .ipa files must be converted to .app first. ```bash xcrun simctl install booted xx.app ``` -------------------------------- ### Install iproxy using Homebrew Source: https://airtest.doc.io.netease.com/IDEdocs/3.2device_connection/4_ios_connection Install the iproxy tool, which is used to map iPhone ports to your computer's ports, enabling connection to the Agent. ```bash $ brew install libimobiledevice ``` -------------------------------- ### Install Poco with pip Source: https://airtest.doc.io.netease.com/IDEdocs/poco_framework/1_poco_info Install the Poco framework in a local Python environment using pip. Ensure you install 'pocoui' and avoid installing 'poco' and 'pocoui' simultaneously to prevent conflicts. ```bash pip install pocoui ``` -------------------------------- ### Start and Stop Application Source: https://airtest.doc.io.netease.com/tutorial/2_Airtest_introduction Basic commands to start and stop a specified application during script execution. ```python start_app("org.cocos2d.blackjack") stop_app("org.cocos2d.blackjack") ``` -------------------------------- ### Download iOS-Tagent Project Source: https://airtest.doc.io.netease.com/IDEdocs/3.2device_connection/4_ios_connection Clone the iOS-Tagent project repository to your local machine to begin the setup process. ```bash git clone git@github.com:AirtestProject/iOS-Tagent.git ``` -------------------------------- ### Install Airtest Library Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/0_airtest_info Install the Airtest library in your Python environment before writing and running scripts in other editors. ```bash pip install airtest ``` -------------------------------- ### Install usbmuxd for port mapping Source: https://airtest.doc.io.netease.com/tutorial/6_IOS_automated_testing Use Homebrew to install usbmuxd, a tool that includes iproxy for mapping device ports to your computer. ```bash brew install usbmuxd ``` -------------------------------- ### Starting an Application with start_app Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/3_airtest_image Use the start_app function to launch applications on Android and iOS devices. This is more concise and compatible than using screenshot scripts for app startup. ```Python # Open Netease Cloud Music start_app("com.netease.cloudmusic") ``` -------------------------------- ### Start Application by Package Name Source: https://airtest.doc.io.netease.com/tutorial/9_Improved_compatibility Launch an application directly using its package name with the start_app function. This method is more concise and compatible than using touch to tap an application icon. ```python # Open NetEase Cloud Music start_app("com.netease.cloudmusic") ``` -------------------------------- ### iOS Device URI Examples Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/2_connect_device Examples of URI strings for connecting to iOS devices, including local real devices and those connected via tidevice. ```python # 连接本机部署的iOS真机 iOS:///http://127.0.0.1:8100 # 使用tidevice连接的iOS设备,DeviceIdentifier可以在启动的信息中查看 http+usbmux://DeviceIdentifier ``` -------------------------------- ### Install Airtest Using Tsinghua Mirror Source: https://airtest.doc.io.netease.com/IDEdocs/faq/2_common%20problems To resolve infinite timeout issues during Airtest installation, configure a domestic mirror like Tsinghua's. ```bash pip install -i https://pypi.tuna.tsinghua.edu.cn/simple airtest ``` -------------------------------- ### Android Device URI Examples Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/2_connect_device Examples of URI strings for connecting to Android devices, including default, specific, remote, and emulator connections. ```python # 什么都不填写,默认取当前连接中的第一台手机 Android:/// # 连接本机默认端口连的一台设备号为79d03fa的手机 Android://127.0.0.1:5037/79d03fa # 用本机的adb连接一台adb connect过的远程设备,注意10.254.60.1:5555其实是serialno Android://127.0.0.1:5037/10.254.60.1:5555 # 连接夜神模拟器(127.0.0.1:62001为夜神模拟器的端口号) Android://127.0.0.1:5037/127.0.0.1:62001?cap_method=JAVACAP ``` -------------------------------- ### iOS Device String Format Source: https://airtest.doc.io.netease.com/IDEdocs/3.4run_script/1_useCommand_runScript Example of a device string for connecting to an iOS device via command line. ```bash # 连接iOS手机 iOS:///127.0.0.1:8100 ``` -------------------------------- ### Install wdaproxy for remote IP mapping Source: https://airtest.doc.io.netease.com/tutorial/6_IOS_automated_testing Install wdaproxy using Homebrew for remote IP mapping, allowing Windows machines to connect to iOS devices managed by a Mac. ```bash brew install openatx/tap/wdaproxy ``` -------------------------------- ### Instantiating Poco Objects on Different Platforms Source: https://airtest.doc.io.netease.com/IDEdocs/poco_framework/2_API_word Provides examples of how to instantiate Poco objects for various platforms like Unity and Android. ```APIDOC ## Instantiating Poco Objects on Different Platforms ### Description This section provides code examples for initializing Poco objects across different development platforms. ### Unity Project Initialization ```python # Import the Unity Poco driver from poco.drivers.unity3d import UnityPoco # Initialize the Poco instance poco = UnityPoco() ``` ### Android Project Initialization ```python from poco.drivers.android.uiautomation import AndroidUiautomationPoco poco = AndroidUiautomationPoco() ``` ### Multi-Device Initialization Examples for initializing Poco with multiple devices are also available in this section for detailed review. ``` -------------------------------- ### ADB Devices Output Example Source: https://airtest.doc.io.netease.com/IDEdocs/3.2device_connection/3_android_faq This is the expected output when ADB successfully detects a connected device. If your output differs, check drivers, USB ports, and phone settings. ```bash >adb.exe devices List of devices attached JTJ4C15A30048654(手机的设备号) device ``` -------------------------------- ### Xcode Build and Test Steps Source: https://airtest.doc.io.netease.com/IDEdocs/3.2device_connection/4_ios_connection Instructions for building and running the WebDriverAgentRunner scheme in Xcode to start the iOS-Tagent service. ```plaintext Test Suite 'All tests' started at 2017-01-23 15:49:12.585 Test Suite 'WebDriverAgentRunner.xctest' started at 2017-01-23 15:49:12.586 Test Suite 'UITestingUITests' started at 2017-01-23 15:49:12.587 Test Case '-[UITestingUITests testRunner]' started. t = 0.00s Start Test at 2017-01-23 15:49:12.588 t = 0.00s Set Up ``` -------------------------------- ### Incorrect iOS Poco Initialization (Error Example) Source: https://airtest.doc.io.netease.com/IDEdocs/poco_framework/5_poco_example Demonstrates an incorrect way to initialize iOS Poco by attempting to initialize before connecting the device. This will result in an error. ```python # -*- encoding=utf8 -*- __author__ = "AirtestProject" from airtest.core.api import * auto_setup(__file__) # 错误示范!!! from poco.drivers.ios import iosPoco poco = iosPoco() connect_device("iOS:///http://127.0.0.1:8100") ``` -------------------------------- ### Call Windows-Specific API Functions Source: https://airtest.doc.io.netease.com/tutorial/7_Windows_automated_testing Access Windows-specific functionalities not covered by Airtest's cross-platform API. This example shows how to get the window title and move the window. ```python # 调用Windows专属的接口,例如获取当前窗口的标题内容 print(dev.get_title()) # 把窗口移动到某个坐标位置 dev.move((100, 200)) ``` -------------------------------- ### Verify Poco SDK Plugin Configuration in UE4 Source: https://airtest.doc.io.netease.com/IDEdocs/poco_framework/6_poco_sdk Ensure that the 'Installed' value is set to 'true' and that there is no 'Enterprise' field in the PocoSDK.uplugin file to ensure the Poco SDK starts correctly. ```json "Installed" : true, ``` -------------------------------- ### Connect to Windows Window by Title Regex Source: https://airtest.doc.io.netease.com/IDEdocs/3.2device_connection/5_windows_connection Connect to a Windows window by matching its title using a regular expression. This method is generally more stable as window titles are less likely to change than handles. The example matches titles starting with '吹梦到西洲' followed by any characters except a newline. ```python # 例如匹配“吹梦到西洲”后面跟着换行符以外的任意字符的窗口title auto_setup(__file__,devices=["Windows:///?title_re=吹梦到西洲.*"]) ``` -------------------------------- ### Initializing Environment and Connecting Devices with auto_setup Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/2_connect_device The auto_setup function initializes the runtime environment and can automatically attempt to connect to an Android device if none are connected. It also supports connecting to single or multiple devices by passing a list of device connection strings. ```APIDOC ## auto_setup ### Description Initializes the runtime environment and attempts to connect to devices. If no device is connected, it defaults to trying an Android device. It can also connect to multiple devices by providing a list of device URIs. ### Method `auto_setup(__file__, devices=["device_uri_1", "device_uri_2"]) ` ### Parameters * `__file__` (string) - The current script file path. * `devices` (list of strings) - A list of device connection URIs to connect to. ### Request Example ```python auto_setup(__file__, devices=["Android://127.0.0.1:5037/SJE5T17B17", "Android://127.0.0.1:5037/SJE5T17B18"]) ``` ``` -------------------------------- ### Connect to Emulator via Command Line with Options Source: https://airtest.doc.io.netease.com/IDEdocs/3.2device_connection/2_emulator_connection When running scripts from the command line, append connection options like `cap_method` and `ori_method` to the device string. Use `^&^&` for Windows or `/&/&` for Mac to separate parameters. ```bash airtest run D:/test/moniqi_test.air --device Android://127.0.0.1:5037/127.0.0.1:62001?cap_method=JAVACAP^&^&ori_method=ADBORI --log E:/log_test ``` -------------------------------- ### Basic Airtest Script Example Source: https://airtest.doc.io.netease.com/tutorial/1_quick_start_guide Demonstrates basic Airtest commands for interacting with UI elements. Use touch for clicks, exists for checking element presence, and loops for repetitive actions. ```python touch("开卡包.png") if exists("奖励面板.png"): for i in range(5): Poco("奖励-%s" % i).click() ``` -------------------------------- ### Install OpenCV for Older Python Versions Source: https://airtest.doc.io.netease.com/IDEdocs/3.4run_script/0_run_script For Python versions below 3.7, uninstall the current OpenCV and install version 3.2.0.7. Ensure pip is updated if the installation fails. ```bash > pip uninstall opencv-contrib-python # 若以下安装语句运行失败,可以尝试更新pip到最新版本后重试 > pip install opencv-contrib-python==3.2.0.7 ``` -------------------------------- ### Android Initialization Log Example Source: https://airtest.doc.io.netease.com/IDEdocs/3.2device_connection/9_android_init This log shows the results of the initialization process for an OPPO phone, detailing which settings were applied and which failed. Review this log to confirm settings or troubleshoot issues. ```log ----------------------- * * * ----------------------- OPPO手机的设置项: - 连接模式-传输文件 - 【需手动设置】请事先登录好OPPO账号 - 【需手动设置】开发者选项开启方式:连续点击【设置-系统管理-关于手机-版本信息-软件版本】 - 设置-电池-应用耗电管理-pocoservice-允许应用自启动,允许完全后台行为 - 设置-其他设置-开发者选项-禁止权限监控 打开,充电时屏幕不休眠 打开 - 设置-其他设置-键盘与输入法-管理输入法-yosemite 启用 - 设置-其他设置-键盘与输入法-输入密码时启用安全键盘 关闭 - 设置-安全与隐私-允许安装未知来源的应用 打开 (不是所有机型都有) - 【无需设置】如OPPO出现10分钟断连的情况,不要插拔手机,直接在屏幕上方下拉的选项里再次打开 USB调试 ----------------------- 以下步骤设置失败: ----------------------- - 设置-安全与隐私-允许安装未知来源的应用 打开 (本选项不是所有的机型都有) 错误原因: Cannot find any visible node by query UIObjectProxy of "text=安全与隐私" ``` -------------------------------- ### Airtest Run Command Examples Source: https://airtest.doc.io.netease.com/IDEdocs/3.4run_script/1_useCommand_runScript Demonstrates various 'airtest run' command options including disabling screenshots, setting screenshot compression, and enabling screen recording with a specified filename. ```bash # 设置脚本运行过程中不再截图 > airtest run test.air --device Android:/// --log logs/ --no-image # 设置脚本运行过程的截图精度为90 > airtest run test.air --device Android:/// --log logs/ --compress 90 # 设置脚本运行过程录屏,录屏文件保存为123.mp4 > airtest run test.air --device Android:/// --log logs/ --recording 123.mp4 ``` -------------------------------- ### Installing Third-Party Libraries Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/8_airtest_using Install necessary third-party libraries such as Airtest and Poco using pip before importing them into your Python environment. ```bash pip install airtest pip install pocoui ``` -------------------------------- ### Connect Multiple Devices with auto_setup Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/2_connect_device Use auto_setup with a list of device URIs to connect multiple devices simultaneously. This function also helps in automatically configuring the runtime environment. ```python auto_setup(__file__, devices=["Android://127.0.0.1:5037/SJE5T17B17","Android://127.0.0.1:5037/SJE5T17B18"]) ``` -------------------------------- ### Install Airtest in Python 2 environment Source: https://airtest.doc.io.netease.com/IDEdocs/faq/2_common%20problems Use this command to install the Airtest library specifically within a Python 2 environment. ```bash python2 -m pip install airtest ``` -------------------------------- ### Install Airtest in Python 3 environment Source: https://airtest.doc.io.netease.com/IDEdocs/faq/2_common%20problems Use this command to install the Airtest library specifically within a Python 3 environment. ```bash python3 -m pip install airtest ``` -------------------------------- ### Run Airtest Script with Parameters via Command Line Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/9_batch_execution Demonstrates how to run an Airtest script from the command line, with options for specifying device, log directory, and recording. ```bash airtest run D:\test\newsLogin.air # 带命令行参数运行脚本 airtest run D:\test\newsLogin.air --device Android:/// --log log/ --recording ``` -------------------------------- ### Initialize Airtest Environment Source: https://airtest.doc.io.netease.com/tutorial/2_Airtest_introduction Import necessary Airtest APIs and initialize the script environment. auto_setup(__file__) is the simplest form, reading parameters from the command line. ```python # -*- encoding=utf8 -*- __author__ = "user" # 初始化环境 from airtest.core.api import * auto_setup(__file__) ``` -------------------------------- ### Initialize Device with init_device Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/2_connect_device Initialize a device by specifying its platform and UUID. Refer to the documentation for detailed parameter information. ```python init_device(platform="Android",uuid="SJE5T17B17") ``` -------------------------------- ### Example Runner Command with Device Specification Source: https://airtest.doc.io.netease.com/tutorial/4_Android_automated_testing_one This command demonstrates how to run an Airtest script on a specific Android device using the `--device` argument, including connection details and capture/touch methods. ```bash "D:\demo\AirtestIDE-win-1.2.10\AirtestIDE\AirtestIDE" runner "D:\test\taikang_test.air" --device android://127.0.0.1:5037/127.0.0.1:7555?cap_method=MINICAP&&ori_method=MINICAPORI&&touch_method=MINITOUCH --log "D:/test/test01\fe03093fd01433d6bf58dc5fa5556c22" ``` -------------------------------- ### Initialize Poco for Unity Projects Source: https://airtest.doc.io.netease.com/IDEdocs/poco_framework/2_API_word Shows the import and initialization process for Poco in Unity projects. ```python # unity项目的 poco 初始化 # import unity poco driver from this path from poco.drivers.unity3d import UnityPoco # then initialize the poco instance in the following way poco = UnityPoco() ``` -------------------------------- ### Initialize Emulator Connection in Pure Python Script Source: https://airtest.doc.io.netease.com/IDEdocs/3.2device_connection/2_emulator_connection For pure Python scripts, initialize the device connection using `auto_setup` with the device string, including any necessary connection parameters. ```python # -*- encoding=utf8 -*- __author__ = "xiaoming" from airtest.core.api import * from airtest.cli.parser import cli_setup if not cli_setup(): auto_setup(__file__, logdir=True, devices=[ "Android://127.0.0.1:5037/127.0.0.1:62001?cap_method=JAVACAP^&^&ori_method=ADBORI", ]) ``` -------------------------------- ### Reinstall Poco Library Source: https://airtest.doc.io.netease.com/IDEdocs/faq/2_common%20problems If you encounter a 'no module named 'poco.drivers'' error, it indicates that the 'poco' library was installed instead of the correct 'pocoui' library. Uninstall 'poco' and install 'pocoui'. ```bash pip uninstall poco pip install pocoui ``` -------------------------------- ### Start POCO Broker for Egret Source: https://airtest.doc.io.netease.com/IDEdocs/poco_framework/6_poco_sdk Run this command in the terminal to start the POCO broker, which is necessary for AirtestIDE to connect to Egret applications. It listens on WebSocket port 5003 and TCP port 15004. ```python python -m poco.utils.net.stdbroker "ws://*:5003" "tcp://*:15004" ``` -------------------------------- ### Android Device String Formats Source: https://airtest.doc.io.netease.com/IDEdocs/3.4run_script/1_useCommand_runScript Examples of Android device connection strings, including default connection, specifying serial number, and connecting to remote devices. Also shows how to append special connection parameters like cap_method, ori_method, and touch_method. ```bash # 什么都不填写,会默认取当前连接中的第一台手机 Android:/// # 连接本机默认端口连的一台设备号为79d03fa的手机 Android://127.0.0.1:5037/79d03fa # 用本机的adb连接一台adb connect过的远程设备,注意10.254.60.1:5555其实是serialno Android://127.0.0.1:5037/10.254.60.1:5555 ``` ```bash # 连接了模拟器,勾选了`Use javacap`模式 Android://127.0.0.1:5037/127.0.0.1:7555?cap_method=JAVACAP # 所有的选项都勾选上之后连接的设备,用&&来连接多个参数字符串 Android://127.0.0.1:5037/79d03fa?cap_method=JAVACAP&&ori_method=ADBORI&&touch_method=ADBTOUCH ``` -------------------------------- ### Basic Airtest Image Scripting Example Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/3_airtest_image This is a fundamental example of using Airtest's image recognition to perform a touch action on a specified template image. The Template class encapsulates image matching parameters. ```Python touch(Template(r"tpl1635489343794.png", record_pos=(-0.365, 0.228), resolution=(1080, 2280))) ``` -------------------------------- ### Get Current Resolution with Airtest Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/4_airtest_ADB Retrieve the current screen resolution of the device with `android.get_current_resolution()`. ```python android = Android() android.get_current_resolution() ``` -------------------------------- ### Get App Path with Airtest Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/4_airtest_ADB Use `android.path_app()` to find the full path of an application on the device. ```python android = Android() android.path_app("com.netease.cloudmusic") ``` -------------------------------- ### Embedding Poco-SDK on Different Platforms Source: https://airtest.doc.io.netease.com/IDEdocs/poco_framework/2_API_word Guides on how to integrate the Poco-SDK into various game engines and platforms. ```APIDOC ## Embedding Poco-SDK on Different Platforms ### Description This part of the Poco API documentation offers detailed tutorials for integrating the Poco-SDK with different game engines. ### Integration Guides Detailed tutorials for integrating the Poco-SDK with specific engines are provided here. Users can find the relevant engine's integration guide to start using the Poco framework. ``` -------------------------------- ### Initialize Selenium Window and WebChrome Instance Source: https://airtest.doc.io.netease.com/IDEdocs/3.3record_script/4_selenium_window This code initializes the Selenium Window and creates a WebChrome instance for web automation. It includes necessary imports and sets an implicit wait time for element interactions. Ensure Chrome path is configured in IDE settings. ```python from selenium import webdriver from selenium.webdriver.common.keys import Keys from airtest_selenium.proxy import WebChrome driver = WebChrome() driver.implicitly_wait(20) ``` -------------------------------- ### Check App Existence with Airtest Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/4_airtest_ADB Employ `android.check_app()` to verify if a specific application is installed on the current device. ```python android = Android() android.check_app("com.netease.cloudmusic") ``` -------------------------------- ### Initialize Poco for UE4 Project Source: https://airtest.doc.io.netease.com/IDEdocs/poco_framework/5_poco_example Use this to initialize Poco for a UE4 project. Ensure the device is connected and the UE4 project with Poco-SDK is launched. ```python from poco.drivers.ue4 import UE4Poco poco = UE4Poco() ``` ```python # example poco("StartButton").click() ``` -------------------------------- ### Standard Initialization for .air Scripts Source: https://airtest.doc.io.netease.com/IDEdocs/3.4run_script/0_run_script This is the standard initialization script for .air files in AirtestIDE. The `auto_setup(__file__)` function automatically handles device connection and log saving when run within the IDE. ```python # -*- encoding=utf8 -*- __author__ = "AirtestProject" from airtest.core.api import * auto_setup(__file__) ``` -------------------------------- ### Using Template for Image Touch Source: https://airtest.doc.io.netease.com/tutorial/2_Airtest_introduction Demonstrates how to use the `Template` class for touch operations with image recognition. It includes parameters like image path, recording position, and resolution for precise image matching. ```python touch(Template(r"tpl1556019871196.png", record_pos=(0.204, -0.153), resolution=(1280, 720))) ``` -------------------------------- ### Python Script Initialization with Logdir Source: https://airtest.doc.io.netease.com/IDEdocs/3.5about_report/Generate_report When running Python scripts, ensure the 'Generate log' option is selected to set 'logdir' correctly. This example shows 'logdir' being set to True, indicating default log saving. ```python from airtest.core.api import * # If you want to record log, please set logdir parameter # logdir=True means save log to default path # logdir="/data/local/tmp/" means save log to the specified path auto_setup(__file__, logdir=True, devices=["android:///"]) ``` -------------------------------- ### Initialize Poco with Devices from Global List Source: https://airtest.doc.io.netease.com/tutorial/5_Android_automated_testing_two This snippet demonstrates initializing Poco instances for multiple devices when they are automatically connected via command line arguments (e.g., `--device`). It accesses the device list from `airtest.core.api.G` and creates a Poco object for each device. ```python from airtest.core.api import G from poco.drivers.android.uiautomation import AndroidUiautomationPoco print(G.DEVICE_LIST) # 假设当前总共有2台手机 poco1 = AndroidUiautomationPoco(G.DEVICE_LIST[0]) poco2 = AndroidUiautomationPoco(G.DEVICE_LIST[1]) ``` -------------------------------- ### Get Android Version with ADB Source: https://airtest.doc.io.netease.com/IDEdocs/airtest_framework/4_airtest_ADB Obtain the Android system version using `adb -s shell getprop ro.build.version.release`. ```bash >>> adb -s PFT4PBLF75GQHYBM shell getprop ro.build.version.release 7.1.1 ```