Skip to content

Commit

Permalink
Merge pull request #2 from Tencent/bugfix-comment
Browse files Browse the repository at this point in the history
fix comment format error
  • Loading branch information
drunkdream committed Nov 7, 2018
2 parents f45d92f + a22d23e commit c3d8d4f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 82 deletions.
72 changes: 23 additions & 49 deletions qt4a/andrcontrols.py
Expand Up @@ -21,7 +21,7 @@
import tempfile
import time

from testbase.util import LazyInit
from testbase.util import LazyInit, Timeout
from tuia.exceptions import ControlNotFoundError

from qt4a.androiddriver.androiddriver import AndroidDriver
Expand Down Expand Up @@ -541,31 +541,13 @@ def rect(self):
self._last_rect = result
return self._last_rect

# ifndef __RELEASE__
# @property
# def bounding_rect(self):
# '''left, top, width, height
# to be deleted
# '''
# return self.rect
# endif

@property
@func_wrap
def visible(self):
'''是否可见
'''
return self._driver.get_control_visibility(self.hashcode)

# ifndef __RELEASE__
# @property
# def visibility(self):
# '''是否可见
# to be deleted
# '''
# return self.visible
# endif

@property
@func_wrap
def _clickable(self):
Expand All @@ -575,14 +557,12 @@ def _clickable(self):
flags = self._driver.get_object_field_value(self.hashcode, 'mViewFlags')
return int(flags) & CLICKABLE == CLICKABLE

# ifndef __RELEASE__
@property
def clickable(self):
'''是否可点击
to be deleted
'''
return self._clickable
# endif

@property
@func_wrap
Expand All @@ -594,15 +574,6 @@ def enabled(self):
flags = int(self._driver.get_object_field_value(self.hashcode, 'mViewFlags'))
return flags & ENABLED_MASK == ENABLE

# ifndef __RELEASE__
@property
def enable(self):
'''是否可用
to be deleted
'''
return self.enabled
# endif

@property
def content_desc(self):
'''控件描述
Expand Down Expand Up @@ -634,10 +605,10 @@ def wait_for_exist(self, timeout=10, interval=0.1):
def wait_for_visible(self, timeout=10, interval=0.2):
'''等待控件可见
:param timeout: 超时时间,单位:秒
:type timeout: int/float
:param interval:重试间隔时间,单位:秒
:param interval:int/float
:param timeout: 超时时间,单位:秒
:type timeout: int/float
:param interval: 重试间隔时间,单位:秒
:type interval: int/float
'''
time0 = time.time()
while time.time() - time0 < timeout:
Expand All @@ -648,10 +619,10 @@ def wait_for_visible(self, timeout=10, interval=0.2):
def wait_for_invisible(self, timeout=10, interval=0.2):
'''等待控件不可见
:param timeout: 超时时间,单位:秒
:type timeout: int/float
:param interval:重试间隔时间,单位:秒
:param interval:int/float
:param timeout: 超时时间,单位:秒
:type timeout: int/float
:param interval: 重试间隔时间,单位:秒
:type interval: int/float
'''
time0 = time.time()
while time.time() - time0 < timeout:
Expand Down Expand Up @@ -960,7 +931,6 @@ def wait_for_value(self, prop_name, prop_value, timeout=10, interval=0.5, regula
:param interval: 等待间隔,默认为0.5
:param regularMatch: 参数 property_name和waited_value是否采用正则表达式的比较。默认为不采用(False)正则,而是采用恒等比较。
"""
from testbase.util import Timeout
Timeout(timeout, interval).waitObjectProperty(self, prop_name, prop_value, regularMatch)

def swipe(self, direct):
Expand Down Expand Up @@ -1280,12 +1250,13 @@ def reach_bottom(self):

def _scroll(self, x, y, count=5, interval=0.04):
'''横向或纵向滚动
:param x: x>0时向左滑动,x = x1 - x2,滚动条向右
:param x: x > 0 时向左滑动,x = x1 - x2,滚动条向右
:type x: int
:param y: y>0时向上滑动,y = y1 - y2,滚动条向下
:param y: y > 0 时向上滑动,y = y1 - y2,滚动条向下
:type y: int
:param count: 分为几次滑动
:type count: int
:param count: 分为几次滑动
:type count: int
'''
if y != 0: y = y * 100 / abs(y) if abs(y) < 100 else y # 为防止在某个控件内滚动变成点击,设置最小滑动距离为100
rect = self.rect
Expand All @@ -1310,12 +1281,13 @@ def _scroll(self, x, y, count=5, interval=0.04):

def scroll(self, x, y, count=5, interval=0.04):
'''横向或纵向滚动
:param x: x>0时向左滑动,x = x1 - x2,滚动条向右
:param x: x > 0 时向左滑动,x = x1 - x2,滚动条向右
:type x: int
:param y: y>0时向上滑动,y = y1 - y2,滚动条向下
:param y: y > 0时向上滑动,y = y1 - y2,滚动条向下
:type y: int
:param count: 分为几次滑动
:type count: int
:param count: 分为几次滑动
:type count: int
'''
# 为避免在不可滑动区域滑动,每次滑动只在可滑动区域3/4处滑动
time0 = time.time()
Expand Down Expand Up @@ -1685,8 +1657,9 @@ def _update(self):

def has(self, key):
'''是否存在该节点
:param key: 封装时定义的子节点名
:type key: string
:type key: string
'''
from androiddriver.util import ControlExpiredError, logger
item = self._view.container[key]
Expand Down Expand Up @@ -1985,8 +1958,9 @@ def item_count(self):

def scroll(self, count=1, rect=None):
'''左右滚动
:param count: 滑动次数,大于0表示向右滑动,小于0表示向左滑动
:type count:
:type count: int
'''
if rect == None: rect = self.rect
x1 = rect[0] + 5
Expand Down
27 changes: 15 additions & 12 deletions qt4a/androidapp.py
Expand Up @@ -137,10 +137,11 @@ def wait_for_activity(self, activity, timeout=15, interval=0.5):

def drag(self, direction='right', count=1):
'''滑动屏幕,适合一大块区域(如引导屏)的滑动,无需关心具体的控件
:param direction: 方向,right、left、top、bottom
:type direction: string
:param count: 次数
:type count: int
:type direction: string
:param count: 次数
:type count: int
'''
width, height = self.device.screen_size
mid_width = width / 2
Expand Down Expand Up @@ -179,8 +180,9 @@ def send_back_key(self):

def send_key(self, key):
'''发送单个按键
:param key: 发送的按键字符串
:type key: string
:type key: string
'''
self.get_driver().send_key(key)

Expand Down Expand Up @@ -340,6 +342,7 @@ def monitor_thread(self):

def get_string_resource(self, string_id, lang=''):
'''获取字符串资源
:param string_id: 字符串ID
:type string_id: string
:param lang: 字符串语言,默认为当前系统语言
Expand Down Expand Up @@ -409,20 +412,20 @@ def set_activity_popup(self, activity, popup=False, process_name=''):
def send_image(self, activity, image_path):
'''向Activity发送图片,支持多图
:param activity: 目标Activity名称
:type activity: string
:param image_path:图片在PC上的路径或路径列表
:type image_path: string | list
:param activity: 目标Activity名称
:type activity: string
:param image_path: 图片在PC上的路径或路径列表
:type image_path: string | list
'''
self.device.send_image_to_app('%s/%s' % (self.package_name, activity), image_path)

def send_file(self, activity, file_path):
'''向Activity发送文件
:param activity: 目标Activity名称
:type activity: string
:param file_path:文件在PC上的路径
:type file_path: string
:param activity: 目标Activity名称
:type activity: string
:param file_path: 文件在PC上的路径
:type file_path: string
'''
self.device.send_file_to_app('%s/%s' % (self.package_name, activity), file_path)

Expand Down
42 changes: 21 additions & 21 deletions qt4a/device.py
Expand Up @@ -294,9 +294,9 @@ def run_as(self, package_name, cmd, **kwargs):
'''以package_name权限执行命令cmd
:param package_name: 包名,必须是已经安装的debug包
:type package_name: string
:param cmd:命令行
:type cmd: string
:type package_name: string
:param cmd: 命令行
:type cmd: string
'''
return self.adb.run_as(package_name, cmd, **kwargs)

Expand Down Expand Up @@ -333,12 +333,12 @@ def start_activity(self, activity_name, action='', type='', data_uri='', extra={
def install_package(self, pkg_path, pkg_name='', overwrite=False):
'''安装应用
:param pkg_path: 安装包路径
:type pkg_path: string
:param pkg_name: 应用包名
:type pkg_name: string
:param overwrite:是否是覆盖安装
:type overwrite: bool
:param pkg_path: 安装包路径
:type pkg_path: string
:param pkg_name: 应用包名
:type pkg_name: string
:param overwrite: 是否是覆盖安装
:type overwrite: bool
'''
return self._device_driver.install_package(pkg_path, overwrite)

Expand Down Expand Up @@ -536,14 +536,14 @@ def take_screen_shot(self, save_path):
def record_screen(self, save_path, record_time, frame_rate=10, quality=20):
'''录屏
:param save_path: 保存路径,如果为已存在的目录路径,则会将每一帧图片保存到该目录下
:type save_path: string
:param record_time:录制时间,单位:秒
:type record-time:int/float
:param frame_rate: 帧率,1-30
:type frame_rate: int
:param quality: 压缩质量,10-100
:type quality: int
:param save_path: 保存路径,如果为已存在的目录路径,则会将每一帧图片保存到该目录下
:type save_path: string
:param record_time: 录制时间,单位:秒
:type record-time: int/float
:param frame_rate: 帧率,1-30
:type frame_rate: int
:param quality: 压缩质量,10-100
:type quality: int
'''
import shutil
from androiddriver.device_driver import qt4a_path
Expand Down Expand Up @@ -849,10 +849,10 @@ def get_static_field_value(self, pkg_name, cls_name, field_name, field_type=''):
def set_default_app(self, action, type, new_app):
'''设置默认应用
:param action: 应用针对的类型,如:android.media.action.IMAGE_CAPTURE
:type action: String
:param new_app:新的应用包名
:type new_app: String
:param action: 应用针对的类型,如:android.media.action.IMAGE_CAPTURE
:type action: String
:param new_app: 新的应用包名
:type new_app: String
'''
return self._device_driver.set_default_app(action, type, new_app)

Expand Down

0 comments on commit c3d8d4f

Please sign in to comment.