How to use the uiautomator2.connect function in uiautomator2

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 / 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 huowenxuan / auto_touch / qutoutiao_android.py View on Github external
import uiautomator2 as u2
import time
import random

d = u2.connect()
info = d.info
print(info) # 1920 * 1080

screen_height = info.get('displayHeight')
screen_width = info.get('displayWidth')

def print_click(sx, sy, ex, ey, second):
    print(str(round(second, 2)) + '秒后拖拽(' + str(round(sx, 2)) + ', ' + str(round(sy, 2)) + '), 到(' +  str(round(ex, 2)) + ',' +  str(round(ey, 2)) + ')')

while 1:
    sx = random.uniform(20, screen_width / 3 * 2)
    sy = random.uniform(screen_height / 2, screen_height - 150)
    ex = random.uniform(20, screen_width / 3 * 2)
    ey = random.uniform(50, screen_height / 2)
    second = random.uniform(20, 40)
    print_click(sx, sy, ex, ey, second)
github freedom-wy / uiautomator2_spider / douyin / Handle_douyin_u2.py View on Github external
def __init__(self):
        #连接手机
        self.d = u2.connect("MBC6OBPJSSG6IJSW")
        #启动抖音app
        self.d.app_start("com.ss.android.ugc.aweme")
github xinxi1990 / atxdemo / driver.py View on Github external
def init_driver(self,device_name):
        '''
        初始化driver
        is_clear:清除数据
        :return:
        '''
        try:
            logger.info(device_name)
            d = ut2.connect(device_name)
            # d = ut2.connect("192.168.129.93")
            #logger.info("设备信息:{}".format(d.info))
            # 设置全局寻找元素超时时间
            d.wait_timeout = wait_timeout  # default 20.0
            # 设置点击元素延迟时间
            d.click_post_delay = click_post_delay
            #d.service("uiautomator").stop()
            # 停止uiautomator 可能和atx agent冲突
            logger.info("连接设备:{}".format(device_name))
            return d
        except Exception as e:
            logger.info("初始化driver异常!{}".format(e))
github openatx / adbutils / adbutils / __main__.py View on Github external
print("apkVersion: {}".format(version_name))
        print("success pushed, time used %d seconds" % (time.time() - start))

        new_dst = "/data/local/tmp/{}-{}.apk".format(package_name, version_name)
        d.shell(["mv", dst, new_dst])
        dst = new_dst
        info = d.sync.stat(dst)
        print("verify pushed apk, md5: %s, size: %s" %
              (r._hash, humanize(info.size)))
        assert info.size == r.copied

        print("install to android system ...")
        if args.install_confirm:
            # Beta
            import uiautomator2 as u2
            ud = u2.connect(args.serial)
            ud.press("home")
            ud.watcher.when("继续安装").click()
            ud.watcher.when("允许").click()
            ud.watcher.when("安装").click()
            ud.watcher.start(2.0)
        
        try:
            start = time.time()
            d.install_remote(dst, clean=True)
            print("Success installed, time used %d seconds" %
                (time.time() - start))
            if args.launch:
                print("Launch app: %s/%s" % (package_name, main_activity))
                d.shell(['am', 'start', '-n', package_name+"/"+main_activity])

        except AdbInstallError as e:
github openatx / weditor / weditor / web / device.py View on Github external
def __init__(self, device_url):
        import uiautomator2 as u2
        d = u2.connect(device_url)
        self._d = d
github openatx / uiautomator2 / examples / runyaml / run.py View on Github external
device = None
conf_filename = None

def test_entry():
    pass



if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-c", "--command", help="run single step command")
    parser.add_argument("-s", "--serial", help="run single step command")
    parser.add_argument("conf_filename", default="test.yml", nargs="?", help="config filename")
    args = parser.parse_args()

    d = u2.connect(args.serial)
    if args.command:
        cf = bunch.Bunch({"output_directory": "output"})
        app = d.session()
        run_step(cf, app, args.command)

    else:
        run_conf(d, args.conf_filename)