使用postman發送資料並構建collections執行測試

來源:互聯網
上載者:User

標籤:輸入參數   點擊   write   google   export   程式   options   import   返回結果   

1.安裝

:https://www.getpostman.com/。直接安裝,成功後在chorme的應用程式中會多出一個Postman。如果無法在google store上直接安裝,可以下載.crx檔案手動安裝:http://chromecj.com/utilities/2015-04/423.html

2.發送請求

a.搭建伺服器。

先用tonado在本機搭一個簡易伺服器,連接埠為8000,定義兩個兩個handler,一個post方法,一個get方法。

post方法的參數為{"operation":"post","send":"yes"}

import tornado.httpserverimport tornado.ioloopimport tornado.optionsimport tornado.webimport jsonfrom tornado.escape import json_decodefrom tornado.options import define, optionsdefine("port", default=8000, help="run on the given port", type=int)class IndexHandler(tornado.web.RequestHandler):    def get(self):        resp =  {‘status‘: 0,                 ‘description‘: ‘ok‘}        resp = json.dumps(resp)        self.write(resp)class PostHandler(tornado.web.RequestHandler):    def post(self, *args, **kwargs):        data = json_decode(self.request.body)        if data[‘operation‘] == "post" and data[‘send‘] == "yes":            resp =  {‘status‘: 0,                     ‘description‘: ‘ok‘}        else:            resp =  {‘status‘: 404,                     ‘description‘: ‘params error‘}                    resp = json.dumps(resp)        self.write(resp)            if __name__ == "__main__":    tornado.options.parse_command_line()    app = tornado.web.Application(handlers=[(r"/index", IndexHandler),                                            (r‘/test‘, PostHandler)])    http_server = tornado.httpserver.HTTPServer(app)    http_server.listen(options.port)    tornado.ioloop.IOLoop.instance().start()

b.使用postman發送get請求。

選擇get方法,輸入url,點擊發送。發送後在Response-Body裡可以查看返回的json串。

c.發送post請求。

選擇post方法,輸入url,在body-raw裡輸入參數。注意這裡預設是text格式,需要改成json格式。點擊send。

可以看到當發送的欄位正確時,返回status:0

輸入錯誤的參數:{"operation":"get","send":"yes"},可以看到返回status:404.

3.驗證介面請求

點擊test,再點擊右側的“Response body:Contains string”,該方法可以判斷返回結果中是否含有某個值。指令碼編輯框中會顯示出驗證的具體指令碼:tests["Body matches string"] = responseBody.has("string_you_want_to_search"),修改“string_you_want_to_search”為“description”。

點擊右側的“Response body:Is equal to a string”,該方法用來判斷返回結果是否等於某個字串。

添加完驗證條件後點擊send,再點擊response-Tests,查看添加的驗證條件是否通過。

4.產生collections

輸入完一個請求後,可以點擊save將其儲存成collections,方便下次再次使用。

儲存後可以再右側找到該collections,後期在使用時,僅需要在此Collections中找到對應的請求名,即可直接使用請求。

5.執行測試

點擊postman左上方runner,會彈出runner頁面。選擇一個collections,點擊start,執行完成後可以在左側查看執行結果。

6.分享請求

點擊collections的share,可以分享串連,點擊Export可以將collections匯出成檔案。

使用postman發送資料並構建collections執行測試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.