Skip to content

AlwaysAndForeverYimi/GAutomator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GAutomator

Wetest license

GAutomator(Game Automator) is an open source test automation framework for Unity game.GAutomator, designed just like android uiautomator, also include ui automator functions.GAutomator operation GameObject(GameObjects are the fundamental objects in Unity that represent characters, props and scenery) implements UI automated testing. GameObject-based approach has no mobile phone resolution adaptation problems, a testing script test game can be executed on different mobiles. Robust is another advantage of GameObject, since the game's UI interface is constantly changing, GameObject changes the frequency is relatively low

SGameDrawing

1 System Requirements

Windows Os and Software Requirements:

  • Windows 7 (32/64 bit), Windows 8 or higher
  • python 2.7
  • Android SDK(or adb),Enable ADB setting on device and connect your android device using usb with your PC.

Linux and Software Requirements:

  • Ubuntu 14.04 LTS
  • python 2.7
  • Android SDK(or adb),Enable ADB setting on device and connect your android device using usb with your PC.

Android: Android 4.3 (API level 18) or higher.

2 Writing Tests for GAutomator

GAutomtor tested game needs to be integrated SDK ,WeTest SDK and SDK integration tutorial. GAutomator in the Sample directory comes with a integrated WeTest SDK demo game, you can use it for automated practice.GAutomator Documentation,start your fisrt unity game automation. Just like uiautomatorviewer,GAutomatorViewer can help you inspect the UI of an application in order to find the layout hierarchy, and view the properties associated with the controls.GAutomatorView,While designing your UI automation suite, this tool is very helpful as it exposes the GameObject name and other attributes of an GameObject, which is needed for writing scripts,GAutomatorView Documentation.

Drawing

Strongly recommended pycharm as python IDE.

import wpyscripts.manager as manager
from testcase.tools import *

def test():
    engine=manager.get_engine()
    logger=manager.get_logger()

    version=engine.get_sdk_version()
    logger.debug("Version Information : {0}".format(version))

    scene=engine.get_scene()
    logger.debug("Scene :   {0}".format(scene))

    sample_button=engine.find_element("/Canvas/Panel/Sample")
    logger.debug("Button : {0}".format(sample_button))
	#engine.click(sample_button)
    screen_shot_click(sample_button)

test()
  • step 1:Save the code as sample.py, in the location with the main.py sibling directory, so that you can find the relevant library of GAutomator;
  • step 2:Launch wetest demo game,and then run this test script;
  • step 3:The automation click the sample button,then you will see a ballon.

3 GAutomator Framework

GAutomator Design

The current GAutomator version can only support Unity. GAutomator is no across test automation,so tested game needs to integrate sdk.The integrated SDK will start with the game,and open a socket listener. GAutomator Client use adb connect from your Android device to your host computer(->can use adb to build/estabilish a connection between your Android device and your host computer),then GAutomator can send requests to the SDK via socket, including querying the GameObject, getting UI location information, performing click actions, and so on. (+Through)Automated testing process, but(->you/user) also need to operate Android UI elements, such as QQ login and so on.GAutomator use xiaocong uiautomator.

Drawing

GAutomator Project Structure

Strictly speaking, GAutomator is not a library, but a python project. GAutomator does not use setup.py installation. Mainly in the company network environment, the installation of Python library may not be an easy thing(-> It is because in company network environment, installing python libraries are always not easy). We would like to provide a way to write script can run any computer which have python environment, eliminating the trouble of packaging and installation of the library. (-> So we would like to provide a way -- writting script rathering than packaging and intalling library, then it can be easily run on any computer with python environment)

Drawing

GAutomator API

The Unity engine-related APIs are placed in the engine.py module

Engine API Description
find_element Finds a GameObject by name and returns it.
find_elements_path According to the picture name, text content, sub-node order to find GameObject instance collection
find_elements_by_component Returns a list of active GameObjects by component
get_element_bound Return the bounding volume of the GameObject
get_element_text Return the string value GameObject display
get_element_image Return the sprite name that is used to render
get_scene Gets the currently active sceneScene
get_element_world_bound Get 3D objects in the game world coordinates in the location and volume, writing 3D game test cases are often used
click_position Perform a click at arbitrary coordinates specified by the user
click Performs a click at the center of the visible bounds of the UI Node represented by this GameObject.
press_position Perform a long click at arbitrary coordinates specified by the user
press Performs a long click at the center of the visible bounds of the UI Node represented by this GameObject.
swipe_position Performs a swipe from one coordinate to another using the number of steps to determine smoothness and speed.
swipe Performs the swipe action from one GameObject to another
swipe_and_press Simulates joystick
input Sets the text in an editable field(NGUI or UGUI), after clearing the field's content.
get_touchable_elements_bound Get the list of touchable buttons
get_registered_handlers Return list of the functions register on the sdk
call_registered_handler Call the function registered on the sdk,such as call GM commands
get_component_methods Get the method name in the component
call_component_method Call the method in the component

Mobile API in device.py, use uiautomator

Device API Description
back Simulates a short press on the BACK button.
get_current_package Retrieves the name of the last package to report accessibility events.
get_rotation Returns the current rotation of the display, as defined in Surface
get_display_size Gets the display size, in pixels.
login_qq_wechat_wait Login QQ or wechat

Report API in report.py

Reporter API Description
add_start_scene_tag\add_end_scene_tag Performance data tag (only support wetest cloud report)
screenshot Take a screenshot of current window and store it as jpg, display in the report
capture_and_mark Take a screenshot of current window,mark a red dot on the click position and store it as jpg, display in the report
report Report information,just like assert

4 Contact

For more information about contributing issues or pull requests, Issues,your can also contact(QQ:800024531)


GAutomator

Wetest license

GAutomator是一个针对Unity手游的UI自动化测试框架。设计理念与使用方式,类似于Android的UIAutomator。GAutomator以Unity中的GameObject为操作对象,通过操作GameObject实现UI自动化测试。基于GameObject的方式,不存在手机分辨率适配的问题,一份脚本能够运行在不同手机之上,基于GameObject的另外一个优点为鲁棒性较强,游戏的UI界面经常发生变化,GameObject变化频率相对较低。

SGame Drawing

一 运行环境要求

window平台下运行,linux可运行脚本(GAutomator)。

  • python 2.7版本
  • 环境变量中包含有adb

工程中已包含所有的库,打开即可编写测试用例,写完即可运行(考虑到国内公司网络限制较多,python库的安装非常麻烦)。

二 测试用例编写

GAutomator被测试的游戏需要集成SDKWeTest SDK打包方式。GAutomator中在Sample目录下自带了一个集成有WeTest SDK的demo游戏,可以使用该游戏进行自动化的练习。GAutomator使用说明文档,在doc下面也有详细的接入文档与使用说明文档。GAutomator与UIAutomator类似,提供了一个UI控件信息查看器GAutomatorView,可以查看UI对于的GameObject及相关信息,GAutomatorView使用说明文档Drawing

强烈建议使用pycharm编写python代码

import wpyscripts.manager as manager
from testcase.tools import *

def test():
    engine=manager.get_engine()
    logger=manager.get_logger()

    version=engine.get_sdk_version()
    logger.debug("Version Information : {0}".format(version))

    scene=engine.get_scene()
    logger.debug("Scene :   {0}".format(scene))

    sample_button=engine.find_element("/Canvas/Panel/Sample")
    logger.debug("Button : {0}".format(sample_button))
	#engine.click(sample_button)
    screen_shot_click(sample_button)

test()
  • step 1:代码保存为sample.py,位置与main.py同级目录,这样能够查找到GAutomator的相关库;
  • step 2:拉起游戏,然后运行上面的代码;
  • step 3:点击sample,跳出一个气球

三 GAutomator结构

GAutomator框架原理

GAutomator目前仅支持Unity。GAutomator是非跨进程的,所以需要在游戏中集成SDK。集成SDK之后会在游戏中启动一个socket服务,GAutomator Python端通过adb与wetest sdk建立端口映射。GAutomator通过socket向WeTest SDK发送请求,包括查询GameObject、获取UI的位置信息、执行点击操作等。手游自动化测试过程中,还需要操作Android标准控件,如QQ登录等。GAutomator使用xiaocong uiautomator作为pc端调用uiautomator的解决方案。 Drawing

GAutomator工程结构

严格意义上来说,GAutomator并不算一个库,算是一个工程。GAutomator并没有采用setup.py安装的方式。主要在公司网络环境下,安装Python库可能并不是一件容易的事情。我们想提供一种方式,编写完拷贝到任何一台安装有python环境的电脑上都能运行,免去打包和安装库的烦恼。 Drawing

GAutomator接口功能

Unity引擎相关的API均放在engine.py模块中

Engine API 说明
find_element 根据GameObject名称或者全路径查找,GameObject实例Eelement
find_elements_path 根据图片名称、文字内容、子节点顺序查找GameObject实例集合,对find_element功能的补充
find_elements_by_component 根据Component名称查找所有符合的GameObject集合
get_element_bound 查找GameObject在手机屏幕上的位置及长宽
get_element_text 获取GameObject上的文字内容
get_element_image 获取GameObject上的绑定的图片名称
get_scene 获取游戏当前的Scene名称
get_element_world_bound 获取3D物体在游戏世界坐标中的位置及体积,编写3D游戏测试用例经常用到
click_position 点击手机屏幕指定位置
click 点击GameObject的中心位置。查找到GameObject的位置和长宽后,计算中心点并进行点击操作
press_position 长按手机屏幕指定位置
press 长按GameObject的中心位置。查找到GameObejct在手机上的位置和长宽,计算中心点并进行长按操作
swipe_position 滑动操作
swipe 从开始的GameObject滑动到结束的GameObject
swipe_and_press 滑动并且长按一段时间,主要用于模拟摇杆
input NGUI或UGUI的Input输入框,修改输入内容
get_touchable_elements_bound 获取当前游戏界面的可点击节点(能有效过滤弹出框下的按钮),NGUI源码有修改的游戏可能会无效
get_registered_handlers 游戏开发人员可在WeTest SDK注册方法供脚本调用,完成复杂功能,如GM命令、人物移动等。该接口获取所有注册的方法
call_registered_handler 调用游戏开发人员注册的方法,如发送GM命令、人物移动到指定位置
get_component_methods 获取游戏组件上的public方法信息
call_component_method 调用游戏组件上的public方法,需要传入组件名称方法名称和参数列表

手机相关的接口均放在device.py中,主要通过uiautomator实现

Device API 说明
back 回退键
get_current_package 获取手机当前应用的package名称
get_rotation 获取屏幕转向
get_display_size 获取屏幕尺寸,长宽高
login_qq_wechat_wait QQ或微信登录,环境变量或者main.py控制账号密码,完成登录过程

自动化测试报告相关功能,目前部分功能仅支持云端运行,后续将陆续在本地运行实现

Reporter API 说明
add_start_scene_tag\add_end_scene_tag 性能数据标签(仅支持wetest云端报告)
screenshot 截图,保存在screenshot目录中,云端显示在报告中
capture_and_mark 截图并标记红点,主要可用于跟踪测试过程
report 断言,模拟单元测试的Assert

四 联系

bug、需求使用过程中的疑问均可直接发布在Issues,有专人负责回答。也可直接联系wetest助手(800024531)

About

Automation for unity mobile game apps

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%