How to use the airtest.core.api.device function in airtest

To help you get started, we’ve selected a few airtest 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 AirtestProject / my-testflow / testflow / scripts / multitests_together.py View on Github external
def setUp(self):
        if not current_device():
            connect_device('Android:///')

        self.package_name = 'com.google.android.calculator'
        apk_path = self.R('res/app/com.google.android.calculator.apk')
        install_android_app(current_device().adb, apk_path)
        start_app(self.package_name)
github AirtestProject / Poco / poco / utils / airtest / input.py View on Github external
elif t == 'm':
                contact = e[2]
                x, y = e[1]
                pos = self.get_target_pos(x, y)
                me = MoveEvent(pos, contact)
            elif t == 'u':
                contact = e[1]
                me = UpEvent(contact)
            elif t == 's':
                how_long = e[1]
                me = SleepEvent(how_long)
            else:
                raise ValueError('Unknown event type {}'.format(repr(t)))
            mes.append(me)

        current_device().minitouch.perform(mes, interval=0)
github AirtestProject / my-testflow / testflow / scripts / multitests_one_by_one.py View on Github external
def setUpClass(cls):
        super(CalculatorCase, cls).setUpClass()
        cls.package_name = 'com.google.android.calculator'
        apk_path = cls.R('res/app/com.google.android.calculator.apk')
        install_android_app(current_device().adb, apk_path)
        start_app(cls.package_name)
github AirtestProject / Poco / poco / utils / airtest / screen.py View on Github external
def getPortSize(self):
        disp = current_device().display_info
        if disp['orientation'] in (1, 3):
            return [disp['height'], disp['width']]
        else:
            return [disp['width'], disp['height']]
github AirtestProject / Poco / poco / utils / airtest / input.py View on Github external
def _get_touch_resolution(self):
        """
        get real time resolution on device if full screen
         or window size if running in window mode
        """
        if device_platform() == 'Android':
            if self.use_render_resolution:
                if self.render_resolution and len(self.render_resolution) == 4:
                    return self.render_resolution
                else:
                    return current_device().get_render_resolution()
        w, h = current_device().get_current_resolution()
        return 0, 0, w, h
github AirtestProject / my-testflow / testflow / scripts / multitests_together.py View on Github external
def setUp(self):
        if not current_device():
            connect_device('Android:///')

        self.package_name = 'com.google.android.calculator'
        apk_path = self.R('res/app/com.google.android.calculator.apk')
        install_android_app(current_device().adb, apk_path)
        start_app(self.package_name)
github AirtestProject / Poco / poco / drivers / cocosjs / __init__.py View on Github external
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:
github AirtestProject / my-testflow / testflow / lib / case / android_app.py View on Github external
def setUpClass(cls):
        super(AndroidAppCase, cls).setUpClass()
        if not current_device():
            connect_device('Android:///')

        dev = current_device()
        meta_info_emitter = cls.get_result_emitter('metaInfo')
        if device_platform() == 'Android':
            meta_info_emitter.snapshot_device_info(dev.serialno, dev.adb.get_device_info())

        cls.poco = AndroidUiautomationPoco(screenshot_each_action=False)

        action_tracker = ActionTracker(cls.poco)
        cls.register_addon(action_tracker)
        cls.site_capturer = SiteCaptor(cls.poco)
        cls.register_addon(cls.site_capturer)
github AirtestProject / Poco / poco / drivers / std / __init__.py View on Github external
def __init__(self, port=DEFAULT_PORT, device=None, use_airtest_input=True, **kwargs):
        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':
            # always forward for android device to avoid network unreachable
            local_port, _ = self.device.adb.setup_forward('tcp:{}'.format(port))
            ip = self.device.adb.host or 'localhost'
            port = local_port
        elif platform_name == 'IOS':
            # ip = device.get_ip_address()
            # use iproxy first
            ip = 'localhost'
            local_port, _ = self.device.instruct_helper.setup_proxy(port)
            port = local_port
        else:
github AirtestProject / my-testflow / testflow / lib / case / android_app.py View on Github external
def setUpClass(cls):
        super(AndroidAppCase, cls).setUpClass()
        if not current_device():
            connect_device('Android:///')

        dev = current_device()
        meta_info_emitter = cls.get_result_emitter('metaInfo')
        if device_platform() == 'Android':
            meta_info_emitter.snapshot_device_info(dev.serialno, dev.adb.get_device_info())

        cls.poco = AndroidUiautomationPoco(screenshot_each_action=False)

        action_tracker = ActionTracker(cls.poco)
        cls.register_addon(action_tracker)
        cls.site_capturer = SiteCaptor(cls.poco)
        cls.register_addon(cls.site_capturer)