Skip to content

Commit

Permalink
Ga have supported UE4 project in iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
David-pzk committed Sep 29, 2020
1 parent 38e82c1 commit 1959140
Show file tree
Hide file tree
Showing 12 changed files with 590 additions and 39 deletions.
34 changes: 34 additions & 0 deletions GAutomatorIos/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File : config.py
@Contact : davidzkpu@tencent.com
@License : (C)Copyright 2020-2021, TIMI-TI-TEST
@Modify Time @Author @Version @Desciption
------------ ------- -------- -----------
2020/9/28 5:23 下午 davidzkpu 1.0 NONE
'''

from enum import Enum

class Account(object):
QQNAME="" #QQ acount
QQPWD="" #QQ password
WECHATNAME="" #wechat account
WECHATPWD="" #wechat passwords


class TestInfo(object):
PACKAGE="" # test package name
udid = "" #ios udid

### Engine Type
Unity="unity"
UE4="ue4"

class EngineType(Enum):
Unity=0,
UE4=1

EngineType=EngineType.UE4 #Type="unity" # unity or ue4
1 change: 0 additions & 1 deletion GAutomatorIos/ga2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from ga2.automation.automationWrapper import *
from ga2.device.iOS.iOSDevice import IOSDevice
from ga2.engine.engine import EngineType
from ga2.automation.by import By
from ga2.device.device import DeviceType
from ga2.device.device import DeviceOrientation
Expand Down
275 changes: 267 additions & 8 deletions GAutomatorIos/ga2/automation/automationHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ga2.common.utils import *
from ga2.cloud.reporter import Reporter
from ga2.common.WebDriverWait import WebDriverWait
from config import Account

class AutomationHelper:

Expand All @@ -15,13 +16,46 @@ def __init__(self, device=None):
self.device = device

@callLog
def wait_element(self, method, param,timeout):
def computetarget(self, param):
'''
坐标映射
:param param:
:return:
'''
display = self.device.display_size()
scale = max(self.device.screenshot_format().size) / max(display)

#设置屏幕像素与逻辑像素比值,iphonex=1.5 ipad pro 11inch=1.2438
UNscale=1.2438
targetPos = ((param.x + param.width / 2) * UNscale / scale, (param.y + param.height / 2) * UNscale / scale)
if isInCloudMode():
Reporter().screenshot_with_mark(display[0], display[1],targetPos[0],targetPos[1])
return targetPos

@callLog
def get_version(self, method,timeout):
method_map = {By.NAME_IN_ENGINE: getattr(self, "get_engine_version")}
if method not in method_map:
logger.error("invalid find method :" + method)
return None
return method_map.get(method)(timeout)

@callLog
def wait_element(self, method, param, timeout):
method_map = {By.NAME_IN_ENGINE: getattr(self, "wait_engine_element_by_name")}
if method not in method_map:
logger.error("invalid find method :" + method)
return None
return method_map.get(method)(param, timeout)

@callLog
def get_dumptree(self, method, timeout):
method_map = {By.NAME_IN_ENGINE: getattr(self, "wait_engine_dump_tree")}
if method not in method_map:
logger.error("invalid find method :" + method)
return None
return method_map.get(method)(timeout)

@callLog
def touch_element(self, method, param):
method_map = {By.NAME_IN_ENGINE: getattr(self, "touch_engine_element_by_name")}
Expand All @@ -30,22 +64,95 @@ def touch_element(self, method, param):
return None
return method_map.get(method)(param)

@callLog
def swipe_screen(self, method, param):
method_map = {By.NAME_IN_ENGINE: getattr(self, "swipe_engine_element_by_name")}
if method not in method_map:
logger.error("invalid swipe method :" + method)
return None
return method_map.get(method)(param)

@callLog
def move_joystick(self, method, param):
method_map = {By.NAME_IN_ENGINE: getattr(self, "joystick_move")}
if method not in method_map:
logger.error("invalid move method :" + method)
return None
return method_map.get(method)(param)

@callLog
def swipe_hold_screen(self, method, param):
'''
Written by davidzkpu
:param method: method name
:param param: dict
:return:
'''
method_map = {By.NAME_IN_ENGINE: getattr(self, "swipe_hold")}
if method not in method_map:
logger.error("invalid hold method :" + method)
return None
return method_map.get(method)(param)

@callLog
def long_press_element(self, method, param, duration=2):
method_map = {By.NAME_IN_ENGINE: getattr(self, "long_press_engine_element_by_name")}
if method not in method_map:
logger.error("invalid touch method :" + method)
logger.error("invalid long press method :" + method)
return None
return method_map.get(method)(param, duration)

@callLog
def double_touch_element(self, method, param):
method_map = {By.NAME_IN_ENGINE: getattr(self, "double_touch_engine_element_by_name")}
if method not in method_map:
logger.error("invalid touch method :" + method)
logger.error("invalid double touch method :" + method)
return None
return method_map.get(method)(param)

@callLog
def get_element_text(self, method, param):
method_map = {By.NAME_IN_ENGINE: getattr(self, "get_element_engine_text_by_name")}
if method not in method_map:
logger.error("invalid get_txt method :" + method)
return None
return method_map.get(method)(param)

@callLog
def tencent_login(self, method):
method_map = {By.NAME_IN_ENGINE: getattr(self, "wait_engine_tencent_login")}
if method not in method_map:
logger.error("invalid loging method :" + method)
return None
return method_map.get(method)()

@callLog
def screen_shot(self, method, param):
'''
'''
method_map = {By.NAME_IN_ENGINE: getattr(self, "screen_engine_shot")}
if method not in method_map:
logger.error("invalid screenshot method :" + method)
return None
return method_map.get(method)(param)




##################################################################

@callLog
def get_engine_version(self, timeout):
if self.device and self.device.engine_connector():
element = None
try:
element = WebDriverWait(timeout, 2).until(self.device.engine_connector().get_sdk_version)
except Exception as e:
logger.warn("get engine version timeout")
return element
return None

@callLog
def wait_engine_element_by_name(self, name, timeout):
if self.device and self.device.engine_connector():
Expand All @@ -57,6 +164,17 @@ def wait_engine_element_by_name(self, name, timeout):
return element
return None

@callLog
def wait_engine_dump_tree(self,timeout):
if self.device and self.device.engine_connector():
element = None
try:
element = WebDriverWait(timeout,2).until(self.device.engine_connector()._get_dump_tree)
except Exception as e:
logger.warn("getdumptree timeout")
return element
return None

@callLog
def touch_engine_element_by_name(self, name):
if not self.device or not self.device.engine_connector():
Expand All @@ -67,11 +185,7 @@ def touch_engine_element_by_name(self, name):
logger.error("touch element is none in touch_engine_elem")
return None
bound = engine.get_element_bound(element)
targetPos = (bound.x + bound.width / 2, bound.y + bound.height / 2)
if isInCloudMode():
(width, height) = self.device.display_size()
Reporter().screenshot_with_mark(width, height,targetPos[0],targetPos[1])

targetPos=self.computetarget(bound)
self.device.touch(targetPos[0],targetPos[1])

return element
Expand Down Expand Up @@ -119,3 +233,148 @@ def double_touch_engine_element_by_name(self, name):
# logger.error("login_helper is not inited...")
# return ERR_LOGIN_FAILED

@callLog
def swipe_engine_element_by_name(self, param):
if not self.device or not self.device.engine_connector():
return None
engine = self.device.engine_connector()
self.device.drag(param['fx'],param['fy'],param['tx'],param['ty'],param['duration'])

@callLog
def swipe_hold(self, param):
'''
written by davidzkpu
:param param: dict
:return:
'''
if not self.device or not self.device.engine_connector():
return None
engine = self.device.engine_connector()
self.device.drag_hold(param['fx'], param['fy'], param['tx'], param['ty'], param['dragduration'], param['holdduration'], param['velocity'])

@callLog
def joystick_move(self, param):
'''
swipe joystick
:param dict
:param distance: the distance for joystick swipe
:param stickname: jotstick_name
:param duration: hold name
:param velocity: swip speed
:param style: value=left,right,up,down
:return:
'''

if not self.device or not self.device.engine_connector():
return None
engine = self.device.engine_connector()
element = engine.find_element(param['stickname'])
if element is None:
logger.error("long press element is none in long_press_engine_element_by_name")
return None
ret=engine.get_element_bound(element)
if not ret:
return False
targetpos=self.computetarget(ret)
switch={'left': lambda x:[x[0]-param['distance'],x[1]],
'right': lambda x:[x[0]+param['distance'],x[1]],
'up': lambda x:[x[0],x[1]-param['distance']],
'down': lambda x:[x[0],x[1]+param['distance']]
}

topos = switch.get(param['style'], lambda: False)(targetpos)
self.device.drag_hold(targetpos[0], targetpos[1], topos[0], topos[1], 1,param['duration'], param['velocity'])
return

@callLog
def get_element_engine_text_by_name(self, name):
if not self.device or not self.device.engine_connector():
return None
engine = self.device.engine_connector()
element = engine.find_element(name)

if element is None:
logger.error("touch element is none in touch_engine_elem")
return None
res = engine.get_element_text(element)

return res

@callLog
def wait_engine_tencent_login(self):
'''
:param name:
:return:
'''
if self.device and self.device.engine_connector():
self.device.wda_session().tap(200, 200)
time.sleep(1)
while True:
if self.device.wda_session()(className='Button',name=u'好').exists:
self.device.wda_session()(className='Button', name=u'好').tap()
time.sleep(1)
continue
if self.device.wda_session()(className='Button',name=u'允许').exists:
self.device.wda_session()(className='Button', name=u'允许').tap()
time.sleep(1)
continue
if self.device.wda_session()(className='StaticText', name=u'同意').exists:
self.device.wda_session()(className='StaticText', name=u'同意').tap()
time.sleep(1)
break


time.sleep(1)
if self.device.wda_session()(name=u'允许').exists:
self.device.wda_session()(cname=u'允许').tap()

time.sleep(1)
if self.device.wda_session()(name=u'同意').exists:
self.device.wda_session()(name=u'同意').tap()

time.sleep(1)
if self.device.wda_session()(className='TextField',name=u'帐号').exists:
self.device.wda_session()(className='TextField',name=u'帐号').set_text(Account.QQNAME)

time.sleep(1)
if self.device.wda_session()(className='SecureTextField',name=u'密码').exists:
self.device.wda_session()(className='SecureTextField',name=u'密码').set_text(Account.QQPWD)

time.sleep(1)
if self.device.wda_session()(className='Button', name=u'登录按钮').exists:
self.device.wda_session()(className='Button', name=u'登录按钮').tap()

time.sleep(2)
if self.device.wda_session()(className='StaticText', value=u'确定').exists:
self.device.wda_session()(className='StaticText', value=u'确定').tap()


time.sleep(1)
if self.device.wda_session()(className='Button', name=u'QQ授权登录').exists:
self.device.wda_session()(className='Button', name=u'QQ授权登录').tap()

time.sleep(1)
if self.device.wda_session()(className='Button', name=u'完成QQ授权').exists:
self.device.wda_session()(className='Button', name=u'完成QQ授权').tap()



@callLog
def screen_engine_shot(self, param):
'''
'''
if not self.device or not self.device.engine_connector():
return None
self.device.screenshot(param)
return








Loading

0 comments on commit 1959140

Please sign in to comment.