How to use the uiautomator2.exceptions.JsonRpcError 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 / uiautomator2 / uiautomator2 / __init__.py View on Github external
raise GatewayError(
                res, "gateway error, time used %.1fs" %
                (time.time() - request_start))
        if res.status_code == 410:  # http status gone: session broken
            raise SessionBrokenError("app quit or crash", jsonrpc_url,
                                     res.text)
        if res.status_code != 200:
            raise UiaError(jsonrpc_url, data, res.status_code, res.text,
                           "HTTP Return code is not 200", res.text)
        jsondata = res.json()
        error = jsondata.get('error')
        if not error:
            return jsondata.get('result')

        # error happends
        err = JsonRpcError(error, method)

        def is_exception(err, exception_name):
            return err.exception_name == exception_name or exception_name in err.message


        if isinstance(
                err.data,
                six.string_types) and 'UiAutomation not connected' in err.data:
            err.__class__ = UiAutomationNotConnectedError
        elif err.message:
            if is_exception(err, 'uiautomator.UiObjectNotFoundException'):
                err.__class__ = UiObjectNotFoundError
            elif is_exception(err, 'android.support.test.uiautomator.StaleObjectException'):
                # StaleObjectException
                # https://developer.android.com/reference/android/support/test/uiautomator/StaleObjectException.html
                # A StaleObjectException exception is thrown when a UiObject2 is used after the underlying View has been destroyed.
github openatx / uiautomator2 / uiautomator2 / exceptions.py View on Github external
self.exception_name = None

    def __str__(self):
        return '%d %s: <%s> data: %s, method: %s' % (
            self.code, self.format_errcode(
                self.code), self.message, self.data, self.method)

    def __repr__(self):
        return repr(str(self))


class UiObjectNotFoundError(JsonRpcError):
    """ 控件没找到 """


class UiAutomationNotConnectedError(JsonRpcError):
    """ 与手机上运行的UiAutomator服务连接断开 """


class NullObjectExceptionError(JsonRpcError):
    """ 空对象错误 """


class NullPointerExceptionError(JsonRpcError):
    """ 空指针错误 """


class StaleObjectExceptionError(JsonRpcError):
    """ 一种,打算要操作的对象突然消失的错误 """


class InjectPermissionError(JsonRpcError):
github openatx / uiautomator2 / uiautomator2 / exceptions.py View on Github external
return repr(str(self))


class UiObjectNotFoundError(JsonRpcError):
    """ 控件没找到 """


class UiAutomationNotConnectedError(JsonRpcError):
    """ 与手机上运行的UiAutomator服务连接断开 """


class NullObjectExceptionError(JsonRpcError):
    """ 空对象错误 """


class NullPointerExceptionError(JsonRpcError):
    """ 空指针错误 """


class StaleObjectExceptionError(JsonRpcError):
    """ 一种,打算要操作的对象突然消失的错误 """


class InjectPermissionError(JsonRpcError):
    """ 开发者选项中: 模拟点击没有打开 """


# 保证兼容性
UiaError = BaseError
github openatx / uiautomator2 / uiautomator2 / exceptions.py View on Github external
self.code, self.format_errcode(
                self.code), self.message, self.data, self.method)

    def __repr__(self):
        return repr(str(self))


class UiObjectNotFoundError(JsonRpcError):
    """ 控件没找到 """


class UiAutomationNotConnectedError(JsonRpcError):
    """ 与手机上运行的UiAutomator服务连接断开 """


class NullObjectExceptionError(JsonRpcError):
    """ 空对象错误 """


class NullPointerExceptionError(JsonRpcError):
    """ 空指针错误 """


class StaleObjectExceptionError(JsonRpcError):
    """ 一种,打算要操作的对象突然消失的错误 """


class InjectPermissionError(JsonRpcError):
    """ 开发者选项中: 模拟点击没有打开 """


# 保证兼容性
github openatx / uiautomator2 / uiautomator2 / exceptions.py View on Github external
""" 与手机上运行的UiAutomator服务连接断开 """


class NullObjectExceptionError(JsonRpcError):
    """ 空对象错误 """


class NullPointerExceptionError(JsonRpcError):
    """ 空指针错误 """


class StaleObjectExceptionError(JsonRpcError):
    """ 一种,打算要操作的对象突然消失的错误 """


class InjectPermissionError(JsonRpcError):
    """ 开发者选项中: 模拟点击没有打开 """


# 保证兼容性
UiaError = BaseError
github openatx / uiautomator2 / uiautomator2 / exceptions.py View on Github external
self.method = method
        if isinstance(self.data, dict):
            self.exception_name = self.data.get("exceptionTypeName")
        else:
            self.exception_name = None

    def __str__(self):
        return '%d %s: <%s> data: %s, method: %s' % (
            self.code, self.format_errcode(
                self.code), self.message, self.data, self.method)

    def __repr__(self):
        return repr(str(self))


class UiObjectNotFoundError(JsonRpcError):
    """ 控件没找到 """


class UiAutomationNotConnectedError(JsonRpcError):
    """ 与手机上运行的UiAutomator服务连接断开 """


class NullObjectExceptionError(JsonRpcError):
    """ 空对象错误 """


class NullPointerExceptionError(JsonRpcError):
    """ 空指针错误 """


class StaleObjectExceptionError(JsonRpcError):
github openatx / uiautomator2 / uiautomator2 / exceptions.py View on Github external
""" 控件没找到 """


class UiAutomationNotConnectedError(JsonRpcError):
    """ 与手机上运行的UiAutomator服务连接断开 """


class NullObjectExceptionError(JsonRpcError):
    """ 空对象错误 """


class NullPointerExceptionError(JsonRpcError):
    """ 空指针错误 """


class StaleObjectExceptionError(JsonRpcError):
    """ 一种,打算要操作的对象突然消失的错误 """


class InjectPermissionError(JsonRpcError):
    """ 开发者选项中: 模拟点击没有打开 """


# 保证兼容性
UiaError = BaseError