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.
- Clone the
Unity3Dfolder from poco sdk repo.
- Place the cloned
Unity3Dfolder in the
Assets/Scriptsfolder of your Unity project.
- Delete unused folders named UI system in the
Assets/Scripts/Unity3Ddirectory. Example: If the UI system used in your project is
ugui, please delete the two folders
ngui,then keep the
- Open your project in
script componentto your
GameObject.It is required to be mounted under an object that will never be destroyed, such as the main camera under normal circumstances.
Click on the
Main Camera in the
demo scene, and the
inspector interface will appear on the right. Then click on
Add Component in the
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.
File-> Build Settingsin the upper left corner of the interface to generate a suitable Android package and install it on your phone.
Airtest IDE, link your phone to Airtest IDE as described above, and start the corresponding game.
Unitymode in the
Poco auxiliary windowin the lower left corner, and you can see the UI tree structure of the current interface:
- After selecting the
Airtest IDEwill 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 click
drag 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.
- 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
iproxy 8100 8100 iproxy 5001 5001
Here iproxy is equivalent to forward in adb
- After connecting the iOS phone, you select the
Unitymode 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.