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

V1.0.92 #597

Merged
merged 11 commits into from
Oct 24, 2023
Merged
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
2 changes: 1 addition & 1 deletion DocBuilder/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ UI hierarchy.
from poco.drivers.unity3d import UnityPoco as Poco

poco = Poco()
ui = poco.agent.hierarchy.dump()
ui = poco.dump() # equivalent to poco.agent.hierarchy.dump()
print(json.dumps(ui, indent=4))


Expand Down
Binary file modified poco/drivers/android/lib/pocoservice-debug.apk
Binary file not shown.
8 changes: 8 additions & 0 deletions poco/drivers/android/uiautomation.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ def __init__(self, device=None, using_proxy=True, force_restart=False, use_airte
self._install_service()

# forward
self.forward_list = []
if using_proxy:
p0, _ = self.adb_client.setup_forward("tcp:10080")
p1, _ = self.adb_client.setup_forward("tcp:10081")
self.forward_list.extend(["tcp:%s" % p0, "tcp:%s" % p1])
else:
p0 = 10080
p1 = 10081
Expand Down Expand Up @@ -323,8 +325,14 @@ def stop_running(self):
print('[pocoservice.apk] stopping PocoService')
self._keep_running_thread.stop()
self._keep_running_thread.join(3)
self.remove_forwards()
self.adb_client.shell(['am', 'force-stop', PocoServicePackage])

def remove_forwards(self):
for p in self.forward_list:
self.adb_client.remove_forward(p)
self.forward_list = []


class AndroidUiautomationHelper(object):
_nuis = {}
Expand Down
14 changes: 13 additions & 1 deletion poco/pocofw.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ def rclick(self, pos):
raise NotImplementedError

def double_click(self, pos):
raise NotImplementedError
ret = self.agent.input.double_click(pos[0], pos[1])
self.wait_stable()
return ret

def swipe(self, p1, p2=None, direction=None, duration=2.0):
"""
Expand Down Expand Up @@ -505,3 +507,13 @@ def use_render_resolution(self, use=True, resolution=None):
'''
self._agent.input.use_render_resolution = use
self._agent.input.render_resolution = resolution

def dump(self):
"""
Dump the current UI tree of the target device. The output format depends on the agent implementation.

Returns:
:obj:`str`: base64 encoded UI tree data
"""

return self.agent.hierarchy.dump()
6 changes: 3 additions & 3 deletions poco/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def sibling(self, name=None, **attrs):

def parent(self):
"""
Select the direct child(ren) from the UI element(s) given by the query expression, see ``QueryCondition`` for
Select the direct parent from the UI element(s) given by the query expression, see ``QueryCondition`` for
more details about the selectors.

Warnings:
Expand Down Expand Up @@ -269,7 +269,7 @@ def __len__(self):
nodes = []
else:
nodes = self._nodes
return len(nodes)
return len(nodes) if nodes else 0

def __iter__(self):
"""
Expand Down Expand Up @@ -882,7 +882,7 @@ def invalidate(self):
def _do_query(self, multiple=True, refresh=False):
if not self._evaluated or refresh:
self._nodes = self.poco.agent.hierarchy.select(self.query, multiple)
if len(self._nodes) == 0:
if not self._nodes or len(self._nodes) == 0:
# 找不到节点时,将当前节点状态重置,强制下一次访问时重新查询一次节点信息
self.invalidate()
raise PocoNoSuchNodeException(self)
Expand Down
11 changes: 11 additions & 0 deletions poco/sdk/interfaces/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ def click(self, x, y):

raise NotImplementedError

def double_click(self, x, y):
"""
Perform click action as simulated input on target device. Coordinates arguments are all in range of 0~1.

Args:
y (:obj:`float`): y-coordinate
x (:obj:`float`): x-coordinate
"""

raise NotImplementedError

def swipe(self, x1, y1, x2, y2, duration):
"""
Perform swipe action as simulated input on target device from point A to B within given time interval to
Expand Down
6 changes: 5 additions & 1 deletion poco/utils/airtest/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from functools import wraps

from airtest.core.api import device as current_device
from airtest.core.api import touch, swipe
from airtest.core.api import touch, swipe, double_click
from airtest.core.helper import device_platform, logwrap
from poco.sdk.interfaces.input import InputInterface

Expand Down Expand Up @@ -80,6 +80,10 @@ def click(self, x, y):
pos = self.get_target_pos(x, y)
touch(pos, duration=self.default_touch_down_duration)

def double_click(self, x, y):
pos = self.get_target_pos(x, y)
double_click(pos)

def swipe(self, x1, y1, x2, y2, duration=2.0):
if duration <= 0:
raise ValueError("Operation duration cannot be less equal 0. Please provide a positive number.")
Expand Down
7 changes: 5 additions & 2 deletions poco/utils/simplerpc/jsonrpc/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
For usage examples see :meth:`Dispatcher.add_method`

"""
import collections
try:
from collections import MutableMapping
except AttributeError:
from collections.abc import MutableMapping


class Dispatcher(collections.MutableMapping):
class Dispatcher(MutableMapping):

""" Dictionary like object which maps method_name to method."""

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def parse_requirements(filename='requirements.txt'):

setup(
name='pocoui',
version='1.0.89',
version='1.0.92',
keywords="poco, automation test, ui automation",
description='Poco cross-engine UI automated test framework.',
long_description='Poco cross-engine UI automated test framework. 2018 present by NetEase Games',
Expand Down