Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dogtail 增加远程环境指定app方法 #110

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions src/dogtail_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,113 @@ def __init__(self, name=None, description=None, number=-1, check_start=True, key
logger.error(search_app)
raise ApplicationStartError(self.name) from SearchError

@staticmethod
def __remote_init(app=None, name=None, roleName=None, description=None, label=None, debugName=None,
obj_index=-1, check_start=True):
if GlobalConfig.NO_DOGTAIL:
raise EnvironmentError("Dogtail 及其相关依赖存在问题,调用相关方法失败~")
try:
obj = root.application(app)
if obj_index > 0:
obj = obj.findChildren(predicate.GenericPredicate(
name, roleName, description, label, debugName)
)[obj_index]
return obj
except SearchError:
if check_start:
search_app = CmdCtl.run_cmd(f"ps -ef | grep {app}")
logger.error(search_app)
raise ApplicationStartError(app) from SearchError

def __get_remote_app_element(self, element, **kwargs):
""" 远程特有元素获取

Args:
element: 应用的元素
**kwargs: app, roleName, description, label, debugName, obj_index, check_start

Returns: element

"""
kwargs["name"] = element
if kwargs.get('app'):
obj = self.__remote_init(**kwargs)
del kwargs['app']
else:
obj = self.obj

try:
element = obj.child(**kwargs, retry=False)
logger.debug(f"{kwargs} 获取元素对象 <{element}>")
return element
except SearchError:
raise ElementNotFound(**kwargs) from SearchError

def get_element_children_txt(self, element, index, **kwargs):
"""获取元素的子元素文本

Args:
element: 元素
index: 位置
kwargs:app, roleName, description, label, debugName, obj_index, check_start

Returns: 文本

"""
kwargs["name"] = element
element = self.__get_remote_app_element(element, **kwargs)
all_children = element.children
return all_children[index].name

def remote_element_click(self, element, button=1, **kwargs):
""" 远程特有元素点击

Args:
element: 应用的元素
button: 1>left,2>middle,3>right
**kwargs: app, roleName, description, label, debugName, obj_index, check_start

Returns: None

"""
kwargs["name"] = element
logger.debug(
f"""{"左键" if button == 1 else f"{'右键' if button == 3 else '鼠标中健'}"} 点击元素 {element}"""
)
mouse_click = (
self.click if button == 1 else self.right_click if button == 3 else self.middle_click
)
mouse_click(self.remote_element_center(element, **kwargs))

def remote_element_center(self, element, **kwargs):
""" 远程特有元素位置获取

Args:
element: 应用的元素
**kwargs: app, roleName, description, label, debugName, obj_index, check_start

Returns: None

"""
element = self.__get_remote_app_element(element, **kwargs)
_x, _y, _w, _h = element.extents
print(f"获取元素中心坐标 ({_x, _y})")
return _x + _w / 2, _y + _h / 2

def element_click_by_brother(self, element, **kwargs):
"""通过相邻元素点击

Args:
element: 元素
kwargs:app, roleName, description, label, debugName, obj_index, check_start

Returns:

"""
kwargs["name"] = element
element = self.__get_remote_app_element(element, **kwargs)
element.get_parent().click()

def app_element(self, *args, **kwargs) -> Node:
"""
获取app元素的对象
Expand Down
13 changes: 11 additions & 2 deletions src/remotectl/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,17 @@ def rdog(self) -> DogtailUtils:
restart_service=self.restart_service,
)

def click_element_by_attr(self, element, button=1):
self.rdog.element_click(element, button=button)
def click_element_by_attr(self, element, button=1, app=None, **kwargs):
self.rdog.remote_element_click(element, button=button, app=app, **kwargs)

def click_element_by_brother(self, element, app=None):
self.rdog.element_click_by_brother(element, app=app)

def get_element_children_txt(self, element, index, app=None):
return self.rdog.get_element_children_txt(element, index, app=app)

def get_element_location(self, element, app=None, **kwargs):
return self.rdog.remote_element_center(element, app=app, **kwargs)

@property
def rctl(self) -> Src:
Expand Down
Loading