Ejemplo n.º 1
0
    def __init__(self, addr=DEFAULT_ADDR):
        # init airtest env
        try:
            # new version
            from airtest.core.api import connect_device, device as current_device
            if not current_device():
                connect_device("Android:///")
        except ImportError:
            # old version
            from airtest.cli.runner import device as current_device
            from airtest.core.main import set_serialno
            if not current_device():
                set_serialno()
        # cocos games poco sdk listens on Android localhost:5003
        localport = addr.split(":")[-1]
        current_device().adb.forward("tcp:%s" % localport, "tcp:5003", False)

        self.conn = WebSocketClient(addr)
        self.c = RpcClient(self.conn)
        self.c.DEBUG = False
        self.c.run(backend=True)
        self.c.wait_connected()

        hierarchy = FreezedUIHierarchy(Dumper(self.c))
        screen = AirtestScreen()
        input = AirtestInput()
        super(CocosJsPocoAgent, self).__init__(hierarchy, input, screen, None)
Ejemplo n.º 2
0
class StdPocoAgent(PocoAgent):
    def __init__(self, addr=DEFAULT_ADDR):
        self.conn = TcpClient(addr)
        self.c = RpcClient(self.conn)
        self.c.connect()

        hierarchy = FrozenUIHierarchy(StdDumper(self.c), StdAttributor(self.c))
        screen = StdScreen(self.c)
        inputs = AirtestInput()
        super(StdPocoAgent, self).__init__(hierarchy, inputs, screen, None)

    @property
    def rpc(self):
        return self.c

    @sync_wrapper
    def get_debug_profiling_data(self):
        return self.c.call("GetDebugProfilingData")

    @sync_wrapper
    def get_sdk_version(self):
        return self.c.call('GetSDKVersion')

    def on_bind_driver(self, driver):
        super(StdPocoAgent, self).on_bind_driver(driver)
        if isinstance(self.input, AirtestInput):
            self.input.add_preaction_cb(driver)
Ejemplo n.º 3
0
    def __init__(self, addr=DEFAULT_ADDR):
        try:
            port = int(addr.rsplit(":", 1)[-1])
        except ValueError:
            raise ValueError(
                'Argument `addr` should be a string-like format. e.g. "ws://192.168.1.2:5003". Got {}'
                .format(repr(addr)))

        if not current_device():
            connect_device("Android:///")
        if device_platform() == 'Android':
            local_port, _ = current_device().adb.setup_forward(
                'tcp:{}'.format(port))
            ip = 'localhost'
            port = local_port
        elif device_platform() == 'IOS':
            # Note: ios is now support for now.
            # ip = device.get_ip_address()
            # use iproxy first
            ip = 'localhost'
            local_port, _ = current_device().instruct_helper.setup_proxy(port)
            port = local_port
        else:
            import socket
            ip = socket.gethostbyname(socket.gethostname())

        self.conn = WebSocketClient('ws://{}:{}'.format(ip, port))
        self.c = RpcClient(self.conn)
        self.c.connect()

        hierarchy = FrozenUIHierarchy(Dumper(self.c))
        screen = AirtestScreen()
        inputs = AirtestInput()
        super(CocosJsPocoAgent, self).__init__(hierarchy, inputs, screen, None)
Ejemplo n.º 4
0
class StdPocoAgent(PocoAgent):
    def __init__(self, addr=DEFAULT_ADDR, use_airtest_input=True):
        self.conn = TcpClient(addr)
        self.c = RpcClient(self.conn)
        self.c.DEBUG = False
        self.c.connect()

        hierarchy = FrozenUIHierarchy(StdDumper(self.c), StdAttributor(self.c))
        screen = StdScreen(self.c)
        if use_airtest_input:
            inputs = AirtestInput()
        else:
            inputs = StdInput(self.c)
        super(StdPocoAgent, self).__init__(hierarchy, inputs, screen, None)

    @property
    def rpc(self):
        return self.c

    @sync_wrapper
    def get_debug_profiling_data(self):
        return self.c.call("GetDebugProfilingData")

    @sync_wrapper
    def get_sdk_version(self):
        return self.c.call('GetSDKVersion')
Ejemplo n.º 5
0
class CocosJsPocoAgent(PocoAgent):
    def __init__(self, addr=DEFAULT_ADDR):
        try:
            port = int(addr.rsplit(":", 1)[-1])
        except ValueError:
            raise ValueError('Argument `addr` should be a string-like format. e.g. "ws://192.168.1.2:5003". Got {}'
                             .format(repr(addr)))

        if not current_device():
            connect_device("Android:///")
        if device_platform() == 'Android':
            local_port, _ = current_device().adb.setup_forward('tcp:{}'.format(port))
            ip = 'localhost'
            port = local_port
        else:
            import socket
            ip = socket.gethostbyname(socket.gethostname())
            # Note: ios is not support for now.

        self.conn = WebSocketClient('ws://{}:{}'.format(ip, port))
        self.c = RpcClient(self.conn)
        self.c.DEBUG = False
        # self.c.run(backend=True)
        self.c.wait_connected()

        hierarchy = FrozenUIHierarchy(Dumper(self.c))
        screen = AirtestScreen()
        input = AirtestInput()
        super(CocosJsPocoAgent, self).__init__(hierarchy, input, screen, None)
Ejemplo n.º 6
0
    def __init__(self, addr=DEFAULT_ADDR, unity_editor=False):
        if not unity_editor:
            # init airtest env
            try:
                # new version
                from airtest.core.api import connect_device, device as current_device
                if not current_device():
                    connect_device("Android:///")
            except ImportError:
                # old version
                from airtest.cli.runner import device as current_device
                from airtest.core.main import set_serialno
                if not current_device():
                    set_serialno()
            # unity games poco sdk listens on Android localhost:5001
            current_device().adb.forward("tcp:%s" % addr[1], "tcp:5001", False)

        self.conn = TcpClient(addr)
        self.c = RpcClient(self.conn)
        self.c.DEBUG = False
        self.c.run(backend=True)
        self.c.wait_connected()

        hierarchy = FreezedUIHierarchy(Dumper(self.c), UnityAttributor(self.c))
        if unity_editor:
            screen = UnityScreen(self.c)
        else:
            screen = AirtestScreen()
        input = AirtestInput()
        super(UnityPocoAgent, self).__init__(hierarchy, input, screen, None)
Ejemplo n.º 7
0
    def __init__(self, port, device=None):
        self.device = device or current_device()
        if not self.device:
            self.device = connect_device("Android:///")

        platform_name = device_platform(self.device)
        if platform_name == 'Android':
            local_port, _ = self.device.adb.setup_forward(
                'tcp:{}'.format(port))
            ip = self.device.adb.host or 'localhost'
            port = local_port
        elif platform_name == 'IOS':
            # Note: ios is now support for now.
            # ip = device.get_ip_address()
            # use iproxy first
            ip = 'localhost'
            local_port, _ = self.device.instruct_helper.setup_proxy(port)
            port = local_port
        else:
            ip = self.device.get_ip_address()

        # transport
        self.conn = WebSocketClient('ws://{}:{}'.format(ip, port))
        self.c = RpcClient(self.conn)
        self.c.connect()

        hierarchy = FrozenUIHierarchy(Dumper(self.c))
        screen = AirtestScreen()
        inputs = AirtestInput()
        super(CocosJsPocoAgent, self).__init__(hierarchy, inputs, screen, None)
Ejemplo n.º 8
0
    def __init__(self, addr=DEFAULT_ADDR):
        self.conn = TcpClient(addr)
        self.c = RpcClient(self.conn)
        self.c.connect()

        hierarchy = FrozenUIHierarchy(StdDumper(self.c), StdAttributor(self.c))
        screen = StdScreen(self.c)
        inputs = AirtestInput()
        super(StdPocoAgent, self).__init__(hierarchy, inputs, screen, None)
Ejemplo n.º 9
0
    def __init__(self, addr=("localhost", 5001)):
        conn = TcpClient(addr)
        self.c = RpcClient(conn)
        self.c.DEBUG = False
        self.c.run(backend=True)

        hierarchy = MhHierarchy(self.c)
        screen = MhScreen(self.c)
        input = MhInput(self.c)
        super(MhPocoAgent, self).__init__(hierarchy, input, screen, None)
Ejemplo n.º 10
0
class UnityPocoAgent(PocoAgent):
    def __init__(self,
                 addr=DEFAULT_ADDR,
                 unity_editor=False,
                 connect_default_device=True):
        # init airtest env
        try:
            # new version
            from airtest.core.api import connect_device, device as current_device
            from airtest.core.helper import device_platform
            if unity_editor and not current_device():
                connect_device(
                    "Windows:///?class_name=UnityWndClass&title_re=Unity.*")
                game_window = current_device().app.top_window().child_window(
                    title="UnityEditor.GameView")
                current_device()._top_window = game_window.wrapper_object()
                current_device().focus_rect = (0, 40, 0, 0)

            if connect_default_device and not current_device():
                # currently only connect to Android as default
                # can apply auto detection in the future
                connect_device("Android:///")

            if device_platform() == "Android":
                # always forward port for Android
                # unity games poco sdk listens on Android localhost:5001
                current_device().adb.forward("tcp:%s" % addr[1], "tcp:5001",
                                             False)

        except ImportError:
            # old version, 逐渐废弃
            from airtest.cli.runner import device as current_device
            from airtest.core.main import set_serialno
            if not current_device():
                set_serialno()
            # unity games poco sdk listens on Android localhost:5001
            current_device().adb.forward("tcp:%s" % addr[1], "tcp:5001", False)

        self.conn = TcpClient(addr)
        self.c = RpcClient(self.conn)
        self.c.DEBUG = False
        self.c.wait_connected()

        hierarchy = FrozenUIHierarchy(Dumper(self.c), UnityAttributor(self.c))
        screen = UnityScreen(self.c)
        input = AirtestInput()
        super(UnityPocoAgent, self).__init__(hierarchy, input, screen, None)

    @sync_wrapper
    def get_debug_profiling_data(self):
        return self.c.call("GetDebugProfilingData")

    @sync_wrapper
    def get_sdk_version(self):
        return self.c.call('GetSDKVersion')
Ejemplo n.º 11
0
def dump():
    conn = TcpClient(DEFAULT_ADDR)
    c = RpcClient(conn)
    c.DEBUG = False
    c.run(backend=True)
    time.sleep(2)
    t0 = time.time()
    d = Dumper(c)
    h = d.dumpHierarchy()
    t1 = time.time()
    print(t1 - t0)
    return h
Ejemplo n.º 12
0
    def __init__(self, addr=DEFAULT_ADDR):
        # init airtest env

        self.conn = TcpClient(addr)
        self.c = RpcClient(self.conn)
        self.c.DEBUG = False
        self.c.wait_connected()

        hierarchy = FrozenUIHierarchy(Dumper(self.c), StdAttributor(self.c))
        screen = StdScreen(self.c)
        input = AirtestInput()
        super(StdPocoAgent, self).__init__(hierarchy, input, screen, None)
Ejemplo n.º 13
0
    def __init__(self, addr=DEFAULT_ADDR, use_airtest_input=True):
        self.conn = TcpClient(addr)
        self.c = RpcClient(self.conn)
        self.c.DEBUG = False
        self.c.connect()

        hierarchy = FrozenUIHierarchy(StdDumper(self.c), StdAttributor(self.c))
        screen = StdScreen(self.c)
        if use_airtest_input:
            inputs = AirtestInput()
        else:
            inputs = StdInput(self.c)
        super(StdPocoAgent, self).__init__(hierarchy, inputs, screen, None)
Ejemplo n.º 14
0
class CocosJsPocoAgent(PocoAgent):
    def __init__(self, port, device=None):
        self.device = device or current_device()
        if not self.device:
            self.device = connect_device("Android:///")

        platform_name = device_platform(self.device)
        if platform_name == 'Android':
            local_port, _ = self.device.adb.setup_forward(
                'tcp:{}'.format(port))
            ip = self.device.adb.host or 'localhost'
            port = local_port
        elif platform_name == 'IOS':
            # Note: ios is now support for now.
            # ip = device.get_ip_address()
            # use iproxy first
            ip = 'localhost'
            local_port, _ = self.device.instruct_helper.setup_proxy(port)
            port = local_port
        else:
            ip = self.device.get_ip_address()

        # transport
        self.conn = WebSocketClient('ws://{}:{}'.format(ip, port))
        self.c = RpcClient(self.conn)
        self.c.connect()

        hierarchy = FrozenUIHierarchy(Dumper(self.c))
        screen = AirtestScreen()
        inputs = AirtestInput()
        super(CocosJsPocoAgent, self).__init__(hierarchy, inputs, screen, None)

    @property
    def rpc(self):
        return self.c

    def get_sdk_version(self):
        return self.rpc.call("getSDKVersion")

    def on_bind_driver(self, driver):
        super(CocosJsPocoAgent, self).on_bind_driver(driver)
        if isinstance(self.input, AirtestInput):
            self.input.add_preaction_cb(driver)
Ejemplo n.º 15
0
class StdPocoAgent(PocoAgent):
    def __init__(self, addr=DEFAULT_ADDR):
        # init airtest env

        self.conn = TcpClient(addr)
        self.c = RpcClient(self.conn)
        self.c.DEBUG = False
        self.c.wait_connected()

        hierarchy = FrozenUIHierarchy(Dumper(self.c), StdAttributor(self.c))
        screen = StdScreen(self.c)
        input = AirtestInput()
        super(StdPocoAgent, self).__init__(hierarchy, input, screen, None)

    @sync_wrapper
    def get_debug_profiling_data(self):
        return self.c.call("GetDebugProfilingData")

    @sync_wrapper
    def get_sdk_version(self):
        return self.c.call('GetSDKVersion')
Ejemplo n.º 16
0
    def __init__(self, addr=DEFAULT_ADDR, unity_editor=False):
        # if not unity_editor:
        # init airtest env
        try:
            # new version
            from airtest.core.api import connect_device, device as current_device
            from airtest.core.helper import device_platform
            if not current_device():
                if unity_editor:
                    connect_device("Windows:///?title_re=Unity.*")
                    game_window = current_device().app.top_window().child_window(title="UnityEditor.GameView")
                    current_device()._top_window = game_window.wrapper_object()
                    current_device().focus_rect = (0, 40, 0, 0)
                else:
                    connect_device("Android:///")
            if device_platform() == "Android":
                # unity games poco sdk listens on Android localhost:5001
                current_device().adb.forward("tcp:%s" % addr[1], "tcp:5001", False)
        except ImportError:
            # old version
            from airtest.cli.runner import device as current_device
            from airtest.core.main import set_serialno
            if not current_device():
                set_serialno()
            # unity games poco sdk listens on Android localhost:5001
            current_device().adb.forward("tcp:%s" % addr[1], "tcp:5001", False)

        self.conn = TcpClient(addr)
        self.c = RpcClient(self.conn)
        self.c.DEBUG = False
        self.c.wait_connected()

        hierarchy = FreezedUIHierarchy(Dumper(self.c), UnityAttributor(self.c))
        screen = UnityScreen(self.c)
        input = AirtestInput()
        super(UnityPocoAgent, self).__init__(hierarchy, input, screen, None)