How to use uiautomator2 - 10 common examples

To help you get started, we’ve selected a few uiautomator2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openatx / uiautomator2 / tests / test_simple.py View on Github external
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')
github openatx / weditor / weditor / rpcserver.py View on Github external
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)
github openatx / weditor / weditor / web / jsonrpc_server.py View on Github external
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)
github openatx / uiautomator2 / uiautomator2 / session.py View on Github external
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)
github zhixideyu / uiautomator2---FaceBook / python-鱼 / xiaomi6.0 / xm_register.py View on Github external
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")
github openatx / uiautomator2 / uiautomator2 / webview.py View on Github external
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)
github openatx / uiautomator2 / uiautomator2 / xpath.py View on Github external
def init():
    uiautomator2.plugin_register("xpath", XPath)
github openatx / uiautomator2 / uiautomator2 / __main__.py View on Github external
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)
github openatx / uiautomator2 / uiautomator2 / __main__.py View on Github external
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)
github openatx / uiautomator2 / uiautomator2 / init.py View on Github external
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]