Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_plugin(self):
def _my_plugin(d, k):
def _inner():
return k
return _inner
u2.plugin_clear()
u2.plugin_register('my', _my_plugin, 'pp')
self.assertEqual(self.d.ext_my(), 'pp')
def _connect(device_id: str):
"""
Returns:
(u2.Device, fixed-device-id)
"""
platform, uri = device_id.split(":", maxsplit=1)
if platform == "android":
d = uiautomator2.connect(uri)
_id = "android:" + d.serial
return d, _id
elif platform == "ios":
import wda
d = wda.Client(uri)
return d.session(), device_id
else:
raise RuntimeError("unknown platform", platform)
def _connect(device_id: str):
"""
Returns:
(u2.Device, fixed-device-id)
"""
platform, uri = device_id.split(":", maxsplit=1)
if platform == "android":
d = uiautomator2.connect(uri)
_id = "android:" + d.serial
return d, _id
elif platform == "ios":
import wda
d = wda.Client(uri)
return d.session(), device_id
else:
raise RuntimeError("unknown platform", platform)
def drag_to(self, *args, **kwargs):
duration = kwargs.pop('duration', 0.5)
timeout = kwargs.pop('timeout', None)
self.must_wait(timeout=timeout)
steps = int(duration * 200)
if len(args) >= 2 or "x" in kwargs or "y" in kwargs:
def drag2xy(x, y):
x, y = self.session.pos_rel2abs(x,
y) # convert percent position
return self.jsonrpc.dragTo(self.selector, x, y, steps)
return drag2xy(*args, **kwargs)
return self.jsonrpc.dragTo(self.selector, Selector(**kwargs), steps)
def register():
try:
services = 'ebd4f2f67d83'
start_time = time.time()
d = u2.connect_usb(services)
d.screen_off()
d.screen_on()
time.sleep(1)
swipe = Swipeclass(d)
swipe.swipeUp(d, 0.1)
time.sleep(3)
d.app_start('io.virtualapp')
# d.app_start('com.facebook.katana')
print('正在启动io.virtualapp')
except Exception as e:
print(e)
sys.exit()
time.sleep(5)
print('virtualapp启动成功!')
time.sleep(5)
res = d(resourceId="io.virtualapp:id/item_app_name", text=u"Facebook")
def runtest():
import uiautomator2 as u2
d = u2.connect_usb()
pprint(d.request_agent("/webviews").json())
port = d._adb_device.forward_port("localabstract:chrome_devtools_remote")
wd = WebviewDriver(f"http://localhost:{port}")
tabs = wd.get_active_tab_list()
pprint(tabs)
def init():
uiautomator2.plugin_register("xpath", XPath)
def cmd_init(args):
serial = args.serial or args.serial_optional
if serial:
device = adbutils.adb.device(serial)
init = Initer(device)
init.install(args.server)
else:
for device in adbutils.adb.iter_device():
init = Initer(device, loglevel=logging.DEBUG)
init.install(args.server)
def cmd_init(args):
serial = args.serial or args.serial_optional
if serial:
device = adbutils.adb.device(serial)
init = Initer(device)
init.install(args.server)
else:
for device in adbutils.adb.iter_device():
init = Initer(device, loglevel=logging.DEBUG)
init.install(args.server)
def is_atx_agent_outdated(self):
agent_version = self._device.shell("/data/local/tmp/atx-agent version").strip()
if agent_version == "dev":
self.logger.info("skip version check for atx-agent dev")
return False
# semver major.minor.patch
try:
real_ver = list(map(int, agent_version.split(".")))
want_ver = list(map(int, __atx_agent_version__.split(".")))
except ValueError:
return True
self.logger.debug("Real version: %s, Expect version: %s", real_ver,
want_ver)
if real_ver[:2] != want_ver[:2]:
return True
return real_ver[2] < want_ver[2]