How to test games based on the Unity3D engine
Because the game interface is rendered by the game engine, the game interface does not have system-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.
Android platform
- Clone the
Unity3D
folder from poco sdk repo.
- Place the cloned
Unity3D
folder in theAssets/Scripts
folder of your Unity project.
- Delete unused folders named UI system in the
Assets/Scripts/Unity3D
directory. Example: If the UI system used in your project isugui
, please delete the two foldersfairygui
andngui
,then keep theugui
folder.
- Open your project in
Unity3D
and addUnity3D/PocoManager.cs
as ascript component
to yourGameObject
.It is required to be mounted under an object that will never be destroyed, such as the main camera under normal circumstances.
For example:
Click on the Main Camera
in thedemo
scene, and the inspector
interface will appear on the right. Then click on Add Component
in the inspector
interface.
Enter poco
in the pop-up dialog box and select the Poco Manager
option that appears.
After completing the above operations, the component
will appear in the inspector
interface as shown in the figure.
-
Click
File-> Build Settings
in the upper left corner of the interface to generate a suitable Android package and install it on your phone. -
Start
Airtest IDE
, link your phone to Airtest IDE as described above, and start the corresponding game. -
Select the
Unity
mode in thePoco auxiliary window
in the lower left corner, and you can see the UI tree structure of the current interface:
- After selecting the
Unity
mode,Airtest IDE
will automatically insert poco's initialization code:
When writing the script, we can use the API provided by Poco to operate the elements on the game interface.
Here is a simple test case. You can download this simple Unity3D game from here. After the installation is complete, open the game, click Start
button, then clickdrag drop
, and the following interface will appear.
For each star you drag to the shell in the center of the screen, you will get 20 points; if you drag 5 stars to the shell in turn, you will get 100 points. The following script is testing whether dragging 5 stars one by one will get 100 points.
from airtest.core.api import *
auto_setup(__file__)
from poco.drivers.unity3d import UnityPoco
poco = UnityPoco()
poco('btn_start').click()
time.sleep(1.5)
poco('drag_and_drop').click()
shell = poco('shell').focus('center')
for star in poco('plays').offspring('star'):
star.drag_to(shell)
time.sleep(1)
assert poco('scoreVal').get_text() == "100", "score correct."
poco('btn_back', type='Button').click()
Click the Run Script button and you will get the result shown below.
iOS platform
- Similarly, you need to complete the engine SDK access first, and then connect 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, 5001 port is used to connect to rpc port of poco-sdk
Here iproxy is equivalent to forward in adbiproxy 8100 8100 iproxy 5001 5001
-
After connecting the iOS phone, you select the
Unity
mode in the Poco auxiliary window, and then you will 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.