记airtest执行poco任何函数报raise JSONDecodeError("Expecting value", s, err.value) from None异常

暗月博客 2021年1月19日23:32:45评论339 views字数 2220阅读7分24秒阅读模式
摘要

airtestpoco 近期在学习用airtest进行自动化测试,遇到的坑来记录一下。用pycharm学习airtest的时候发现任何poco的函数都会直接报错raise JSONDecodeError("Expecting value", s, err.value) from None异常,进行debug后发现问题出在minicap.py文件的get_display_info方法里面。
get_display_info代码

airtestpoco

前言

近期在学习用airtest进行自动化测试,遇到的坑来记录一下。

问题

用pycharm学习airtest的时候发现任何poco的函数都会直接报错raise JSONDecodeError("Expecting value", s, err.value) from None异常,进行debug后发现问题出在minicap.py文件的get_display_info方法里面。
get_display_info代码

def get_display_info(self):      display_info = self.adb.shell("%s -i" % self.CMD)     display_info = json.loads(display_info)     display_info["orientation"] = display_info["rotation"] / 90     # 针对调整过手机分辨率的情况     actual = self.adb.shell("dumpsys window displays")     arr = re.findall(r'cur=(/d+)x(/d+)', actual)     if len(arr) > 0:         display_info['physical_width'] = display_info['width']         display_info['physical_height'] = display_info['height']         # 通过 adb shell dumpsys window displays | find "cur="         # 获取到的分辨率是实际分辨率,但是需要的是非实际的         if display_info["orientation"] in [1, 3]:             display_info['width'] = int(arr[0][1])             display_info['height'] = int(arr[0][0])         else:             display_info['width'] = int(arr[0][0])             display_info['height'] = int(arr[0][1])     return display_info 

这个方法会被传一条命令进来 LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -i ; echo ---$?---

执行之后会返回这些

WARNING: linker: /data/local/tmp/minicap has text relocations. This is wasting memory and prevents security hardening. Please fix.  {      "id": 0,      "width": 540,      "height": 960,      "xdpi": 240.00,      "ydpi": 240.00,      "size": 4.59,      "density": 1.50,      "fps": 60.00,      "secure": true,      "rotation": 0  } 

很明显里面多了一句警告,导致了**json.loads(display_info)**时候报错,下面我们改造一下这段代码。

添加如下两行

index = display_info.index("{") display_info = display_info[index:len(display_info)] 

最后代码如下

def get_display_info(self):     display_info = self.adb.shell("%s -i" % self.CMD)     index = display_info.index("{")     display_info = display_info[index:len(display_info)]     display_info = json.loads(display_info)     display_info["orientation"] = display_info["rotation"] / 90     # 针对调整过手机分辨率的情况     actual = self.adb.shell("dumpsys window displays")     arr = re.findall(r'cur=(/d+)x(/d+)', actual)     if len(arr) > 0:         display_info['physical_width'] = display_info['width']         display_info['physical_height'] = display_info['height']         # 通过 adb shell dumpsys window displays | find "cur="         # 获取到的分辨率是实际分辨率,但是需要的是非实际的         if display_info["orientation"] in [1, 3]:             display_info['width'] = int(arr[0][1])             display_info['height'] = int(arr[0][0])         else:             display_info['width'] = int(arr[0][0])             display_info['height'] = int(arr[0][1])     return display_info 

来源:http://www.safe6.cn/

本文由 safe6 创作,著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

记airtest执行poco任何函数报raise JSONDecodeError("Expecting value", s, err.value) from None异常

本站的所有程序和文章,仅限用于学习和研究目的;不得用于商业或者非法用途,否则,一切后果请用户自负!! 最后编辑时间为: 2019-10-25

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
暗月博客
  • 本文由 发表于 2021年1月19日23:32:45
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   记airtest执行poco任何函数报raise JSONDecodeError("Expecting value", s, err.value) from None异常https://cn-sec.com/archives/247591.html

发表评论

匿名网友 填写信息