接口测试返回值的具体内容


http://www.robotframework.net/?/article/91

 

运行这段脚本,第4行的打印结果是:INFO : <class 'requests.models.Response'>
从结果可以看出${resp}是一个类对象,源码可在requests/models/Response查看,对象句点操作一般是取对象属性,顺藤摸瓜,找出该类的所有属性,第6行打印结果:
 ['__attrs__', '__bool__', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getstate__', '__hash__', '__init__', '__iter__', '__module__', '__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_content', '_content_consumed', 'apparent_encoding', 'close', 'connection', 'content', 'cookies', 'elapsed', 'encoding', 'headers', 'history', 'is_permanent_redirect', 'is_redirect', 'iter_content', 'iter_lines', 'json', 'links', 'ok', 'raise_for_status', 'raw', 'reason', 'request', 'status_code', 'text', 'url']

粗体的是比较重要的,今后会被频繁使用的属性:

content: 响应body的内容,二进制编码,如果返回只有文本内容,和text差不多
cookies:响应回写的cookies,cookieJar类对象
headers: 响应头内容
json(): 响应body内容,json格式
status_code: 状态码
text: 响应body的内容,默认unicode编码

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM