zoukankan      html  css  js  c++  java
  • robotframework接口测试——处理响应数据(4)

    • 找到一个不错的博客:http://www.robotframework.net/?/people/xueji
    • 对于初学者,还是1 要懂点python, 2 要懂rf和python之间的表达切换,rf里最好的调试语句是log。建议多写多log

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

    初使用RequestsLibrary做接口测试时,你会不会感到困惑,为什么会有${resp.content}, ${resp.status_code}这样的写法,这个status_code什么鬼,f5查的时候怎么没说明这个东西,为什么写Demo的人知道可以这么写,我少写个’_’可不可以,还有其它啥高端玩法是我不知道的,这玩意的使用说明到底保存在哪啊喂!
    说到这个,我们先来了解一下,返回的${resp}是个什么类型的对象,在rf上用个巧妙的方法查看:

    2-1看resp类型.png



    运行这段脚本,第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编码

     

    -----------------------------------------Have a good day!---------------------------------------------------------------------------------------------------
  • 相关阅读:
    Introduction to Guid ( globally unique identifier )
    Visual Studio调试技巧 -- Attach to Process #Reprinted#
    ASP.NET PipeLine #Reprinted#
    Introduction to REST #Reprinted#
    HTTP status codes
    Introduction to Json
    Visual Studio shortcut keys
    C# Programming Study #1
    面向对象程序设计-C++ Finial exam review NOTES【第十六次上课笔记】
    几道汇编入门题目(二)
  • 原文地址:https://www.cnblogs.com/ww-xiaowei/p/10339255.html
Copyright © 2011-2022 走看看