Open skempegouda opened 2 years ago
It looks like the error is happening because the code is trying to treat a string as if it were a dictionary. Specifically, when it tries to access jsonresult["error"]["data"]["exceptionTypeName"]
, it's expecting jsonresult["error"]["data"]
to be a dictionary, but it's actually a string. That's why we're getting the "string indices must be integers"
error. We need to add a check to make sure we're dealing with a dictionary before trying to access keys like that.
Here's the code to check if jsonresult["error"]["data"] is a dictionary before accessing its keys:
if isinstance(jsonresult["error"]["data"], dict):
exception_type = jsonresult["error"]["data"].get("exceptionTypeName", "UnknownException")
else:
exception_type = "UnknownException"
..\conftest.py:9: in test_setup d.demo.close_all() ......\lib\demo.py:412: in close_all self.device.press.recent() ........\venv\lib\site-packages\uiautomator__init.py:74: in call return self.func(*args, **kwargs) ........\venv\lib\site-packages\uiautomator__init__.py:787: in _press return self.server.jsonrpc.pressKey(str(key)) ........\venv\lib\site-packages\uiautomator\init.py:421: in wrapper return _method_obj(*args, **kwargs) ........\venv\lib\site-packages\uiautomator\init.py:132: in call__ "%s: %s" % (jsonresult["error"]["data"]["exceptionTypeName"], jsonresult["error"]["message"]) E TypeError: string indices must be integers