AirtestProject / Poco

A cross-engine test automation framework based on UI inspection
http://airtest.netease.com/
Apache License 2.0
1.77k stars 318 forks source link

更新最新Tagent,Poco 报错TypeError: string indices must be integers #389

Open zhangqiongxiu opened 4 years ago

zhangqiongxiu commented 4 years ago

File "main.py", line 29, in setUp GetAuthorization.allow() File "/home/test_user/common/get_authorization.py", line 15, in allow while PortfolioCommon.portfoElement(auth_name).exists(): File "/home/test_user/common/portfolio_common.py", line 14, in portfoElement if poco(name=str).exists(): File "/home/test_user/python363/lib/python3.6/site-packages/poco/proxy.py", line 72, in wrapped return func(proxy, *args, *kwargs) File "/home/test_user/python363/lib/python3.6/site-packages/poco/proxy.py", line 774, in exists return self.attr('visible') File "/home/test_user/python363/lib/python3.6/site-packages/poco/proxy.py", line 39, in wrapped return func(self, args, **kwargs) File "/home/test_user/python363/lib/python3.6/site-packages/poco/proxy.py", line 734, in attr nodes = self._do_query(multiple=False) File "/home/test_user/python363/lib/python3.6/site-packages/poco/proxy.py", line 872, in _do_query self._nodes = self.poco.agent.hierarchy.select(self.query, multiple) File "/home/test_user/python363/lib/python3.6/site-packages/poco/freezeui/hierarchy.py", line 90, in select return self.selector.select(query, multiple) File "/home/test_user/python363/lib/python3.6/site-packages/poco/sdk/Selector.py", line 77, in select return self.selectImpl(cond, multiple, self.getRoot(), 9999, True, True) File "/home/test_user/python363/lib/python3.6/site-packages/poco/sdk/Selector.py", line 71, in getRoot return self.dumper.getRoot() File "/home/test_user/python363/lib/python3.6/site-packages/poco/freezeui/hierarchy.py", line 35, in getRoot root = Node(self.dumpHierarchy()) File "/home/test_user/python363/lib/python3.6/site-packages/poco/drivers/ios/init.py", line 48, in dumpHierarchy data = ios_dump_json(jsonObj, self.size) File "/home/test_user/python363/lib/python3.6/site-packages/poco/drivers/ios/init.py", line 65, in ios_dump_json data = json_parser(jsonObj, screen_size) File "/home/test_user/python363/lib/python3.6/site-packages/poco/drivers/ios/init.py", line 89, in json_parser w = float(node["frame"]["width"]) TypeError: string indices must be integers

cheliosooo commented 4 years ago

I also had this issue. Was very odd since it worked fine on one mac but didn't work on another. Nonetheless I had to go into the poco driver class to patch things up.

If anyone's still having this problem, node["frame"] is returning a string since keys are not provided in that json data for some reason, (i.e. it looks something along the lines of this: "{{34, 67}, {337, 731}}"), and since it can't parse that into json data, it has to accept it as a string.

So a quick fix I set up was to grab the values out of the string manually, (if it is a string). Go into poco/drivers/ios/__init__.py, in the json_parser() method, replace:

w = float(node["frame"]["width"])
h = float(node["frame"]["height"])
x = float(node["frame"]["x"])
y = float(node["frame"]["y"])

with this instead:

from re import search

if isinstance(node["frame"], str):
     frameData = search(r'{{(-?\d+\.?\d*), (-?\d+\.?\d*)}, {(\d+\.?\d*), (\d+\.?\d*)}}', node["frame"])
     x = float(frameData.group(1))
     y = float(frameData.group(2))
     w = float(frameData.group(3))
     h = float(frameData.group(4))
else:
     w = float(node["frame"]["width"])
     h = float(node["frame"]["height"])
     x = float(node["frame"]["x"])
     y = float(node["frame"]["y"])

Things should work fine after that.

metoto commented 3 years ago

有种情况,出现{{inf,inf},{0,0}} 这种,会导致楼上的group方法失效,暂时不知道对于这种inf的返回,要怎么处理

yanyanqiaoba commented 3 years ago

I also had this issue. Was very odd since it worked fine on one mac but didn't work on another. Nonetheless I had to go into the poco driver class to patch things up.

If anyone's still having this problem, node["frame"] is returning a string since keys are not provided in that json data for some reason, (i.e. it looks something along the lines of this: "{{34, 67}, {337, 731}}"), and since it can't parse that into json data, it has to accept it as a string.

So a quick fix I set up was to grab the values out of the string manually, (if it is a string). Go into poco/drivers/ios/__init__.py, in the json_parser() method, replace:

w = float(node["frame"]["width"])
h = float(node["frame"]["height"])
x = float(node["frame"]["x"])
y = float(node["frame"]["y"])

with this instead:

from re import search

if isinstance(node["frame"], str):
     frameData = search(r'{{(-?\d+\.?\d*), (-?\d+\.?\d*)}, {(\d+\.?\d*), (\d+\.?\d*)}}', node["frame"])
     x = float(frameData.group(1))
     y = float(frameData.group(2))
     w = float(frameData.group(3))
     h = float(frameData.group(4))
else:
     w = float(node["frame"]["width"])
     h = float(node["frame"]["height"])
     x = float(node["frame"]["x"])
     y = float(node["frame"]["y"])

Things should work fine after that.

按照你的方法试了,还是有报错 File "/Applications/AirtestIDE.app/Contents/MacOS/poco/drivers/ios/init.py", line 90, in json_parser frameData = search(r'{{(-?\d+.?\d), (-?\d+.?\d)}, {(\d+.?\d), (\d+.?\d)}}', node["frame"]) TypeError: string indices must be integers