This article is from the official account of the project: “AirtestProject” Copyright notice: It is allowed to be reproduced, but the original link must be retained. Do not use it for commercial or illegal purposes

preface

Poco initialization has always been a very easy place for students to have problems, so today we will separate this part of the content to explain to you, hoping to reduce your doubts about this content.

1. How to initialize different POCos

First of all, we all know that there are many types of Poco, so how can we distinguish which Poco mode we should use in the actual testing process?

1) Unity POCO: Dedicated to Unity3D games

Games are developed by a variety of engines, and for games developed by Unity, we use Unity POCO for testing. Whether the Unity game is packaged as an ios package, an Android package, or a Unity game for Windows, after embedding the Poco-SDK, you should always select Unity Poco to test the game application:

# unity3D poCO init script from poco. Drivers. unity3D import UnityPoco poco = UnityPoco()Copy the code

Note that the Poco initialization of the game application should be done after the game is started!! (After the game starts, the POCO service embedded in the game will start, and then we can initialize our game POCO and get the game control information)

2) UE4 POCO: dedicated to UE4 games

With unity games, UE4 engine developed products, we can use UE4 POCO to initialize:

UE4 import UE4Poco poco = UE4Poco()Copy the code

3) CoCOS-Lua POCO: Cocos2DX-Lua games only

STD import StdPoco poco = StdPoco()Copy the code

4) COCOS-JS POCO: used by cocos2DX-JS and CoCOS-Creator games

Import CocosJsPoco poco = CocosJsPoco()Copy the code

5) Android POCO: Exclusively for Android native apps

# the Android native application initialization scripts from poco. Drivers. Android. Uiautomation import AndroidUiautomationPoco poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)Copy the code

In particular, the initialization of Android native apps should be placed after the Android device is connected!! (And the device has been started, that is, under the normal operation of Android system)

6) iOS POCO: iOS native apps only

IOS import iosPoco poco = iosPoco()Copy the code

The initialization of native apps for Android devices and iOS devices should be placed after the iOS device is connected!! (The iOS system of the device is running normally)

7) QT poco

It is not enabled, but will be updated later

8) STD-Broker POCO: Exclusive to Egret engine

STD import StdPoco from poco.utils.device import VirtualDevice POco = StdPoco(15004, VirtualDevice('localhost'))Copy the code

2. Initialize multiple POCos on a single device

Believe that we often encounter this kind of situation, we need to test one Android device application, it has both Android native applications, there are all kinds of games, when we from the operation of the native applications, switch to the game application of the operation, is involved in this device, multiple poco initialization, the sample is as follows:

# -*- encoding=utf8 -*- __author__ = "AirtestProject" from airtest.core. API import * auto_setup(__file__) # Initialize Android poco from poco.drivers.android.uiautomation import AndroidUiautomationPoco poco = AndroidUiautomationPoco(use_airtest_input=True, Screenshot_each_action =False) poco(text="poco").click() sleep(5.0) # Initialize unity poco from poco.drivers Click () sleep(2.0) keyevent("HOME")Copy the code

Of course, in order to distinguish between different POCo, we can also set different variable names for poCO during initialization, such as:

from poco.drivers.unity3d import UnityPoco
unity_poco = UnityPoco()

unity_poco("btn_start").click()
Copy the code

In addition, when we test the game, we often encounter some input boxes that are not game controls, but Android native controls, common in the game account login, or other input boxes; It is also necessary to switch the POCO mode we are using in real time:

# -*- encoding=utf8 -*- __author__ = "AirtestProject" from airtest.core.api import * auto_setup(__file__) from poco.drivers.unity3d import UnityPoco unity_poco = UnityPoco() unity_poco("Placeholder").click() from poco.drivers.android.uiautomation import AndroidUiautomationPoco android_poco = AndroidUiautomationPoco(use_airtest_input=True, Screenshot_each_action =False) Android_poco (" android.widget.editText ").set_text("hei ") Android_poco (" android. Widget. The Button "). Click () sleep (1.0) unity_poco (" star_single "). Long_click ()Copy the code

3. Initialize the POCO for multiple devices

For example, in one script, multiple devices need to be switched. After the switch, initialize the CORRESPONDING POCO for the new device, and then perform the POCO operation for the device:

4. Poco initialization time

1) PoCO for Android and iOS native apps

For Android and iOS native POCo, the initialization script should be placed after the device connection script, the auto_setup interface, or other device connection interface:

# -* -encoding =utf8 -* -__author__ = "AirtestProject" from airtest.core. API import * # auto_setup Don't fill in the equipment parameters take the default local connection of the first equipment auto_setup (__file__) from poco. Drivers. Android. Uiautomation import AndroidUiautomationPoco poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)Copy the code

2) PoCO corresponding to the game

The initialization script of the game POCO should be placed after the game application is started, and the device under test needs to be connected before the game is started, so the overall order is as follows:

# -*- encoding= UTf8 -*- __author__ = "AirtestProject" from airtest.core. API import * # Connect device Auto_setup (__file__, logdir = True, devices = [" Android: / / 127.0.0.1:5037 / emulator - 5554 "]) # start the application start_app (" Ease "com.Net Sleep (6.0) # initialize poco from poco.drivers.unity3d import UnityPoco poco = UnityPoco() poco("btn_start").click()Copy the code

5. Solution to pocoService frequent restart

1) Close all network agents

If network proxies are enabled, you need to disable all proxies and VPNS first. Otherwise, POCO communication may be affected.

2) Some Android phones have setup problems

Check whether there are restrictions on PocoService. apk in mobile assistant. For example, in a certain version of Huawei mobile phone, it is necessary to enable automatic startup and background activities, and some OnePlus mobile phones should turn off the battery optimization of PocoService. apk. Details you can refer to “common Android connection problem” document (airtest.doc.io.netease.com/IDEdocs/dev…

3) It cannot be started at the same time as UIAutomator

You can’t start the UIAutomator at the same time, otherwise it will conflict with the UIAutomator.

4) You can try to restart the system

Try restarting the phone to see if it recovers.

summary

That’s all for Poco initialization. If you have any other questions, please leave a message on our official account


AirtestIDE download: airtest.netease.com/ Airtest tutorial website: airtest.doc.io.netease.com/ build enterprise private cloud service: airlab.163.com/b2b

Official Q group: 654700783

Ah, so serious all see here, help in the left side of the article click on the likes and favorites, give me a support, ash often thank ~