Postman 基本操作學習


clip_image004_thumb

History

所有使用postman發送的request都會保存在這里。點擊之后會在當前Tab打開。

參考: Requests History

clip_image005_thumb

Environments

這里用來設定當前request 發送時使用的環境,比如這里可以選擇“Cooper-Remote.template”或者“header_encode_style”或者“test_demo”,還可以選擇“No Environment”,表示當前request不使用任何環境。

環境其實就是多組 key-value 。環境可以被下載保存為JSON文件。也可以導入環境,比如CSV或者JSON文件。

參考:Setting up an environment with variables

Using environments to switch contexts

clip_image007_thumb

這里的環境其實就是一組key-value的集合。比如選擇“Cooper-Remote.template”的話,URL以及Test等等都可以通過{{url}}以及{{items}}來直接使用這些變量。

clip_image009_thumb

Global variables

點擊眼形圖標,可以看到當前可以使用的所有變量:包括選擇的Environment的以及其他request添加到Globals里面的變量。

Environment和 Global的區別在於: 整個postman可以保存多個Environment,但是只會存在一組Global。 保存在Global里的key-value可以被所有的request使用,但是一個request只能選擇一個Environment。

參考:Setting up an environment with variables

clip_image010_thumb

Request

image_thumb3[1]

method

參考: Sending Requests Method

比較常見的有 GET、POST、PUT,還有一些不常見的比如 PATCH、DELETE等。

URL & Params

參考: Sending Requests URL

URL可以輸入request的地址,Params是對應的URL的參數。在Params中輸入參數,會自動同步到URL。同理,URL里面輸入帶有參數的地址,也會自動同步參數到Params。

image_thumb4[1]

Send

發送當前請求。”Send and Download“ 在發送請求之后,會自動下載該請求的response。

image_thumb5

Save

可以直接保存request。也可以選擇“Save as”。

Save as 可以保存 請求的名字以及簡單的描述。還可以決定要不要把請求保存到Collection里面去。

參考: Getting started with Collections Saving requests inside a collection

image_thumb6

image_thumb7

Authorization

如果訪問的服務需要驗證,這里可以設置驗證方式+填寫驗證所需的信息,比如用戶名密碼。

參考: Authentication helpers

image_thumb8[1]

Headers

參考: Sending Requests Headers

定義HTTP Header。

image_thumb9

Body

參考: Sending Requests Request body

設置請求的body。有四種方式進行設置: form-data、 urlencoded、raw 以及 binary。

GET是不可以設置Body的,POST請求可以。

image_thumb

Pre-request Script

參考:Pre Request Scripts

請求前需要執行的腳本可以放置在這里。主要進行一些環境以及全局變量的設置。

image_thumb10

Tests

參考:Writing Tests

           Testing examples

這里寫測試用例,進行一些判斷等等。

下面新建了兩個測試用例,名字分別是”Status code is 200“ 、”Status code name has string“。

“responseCode.code === 200” 返回 True 或者 False,進而判斷 ”Status code is 200“ 這個用例是Pass還是Fail。

image_thumb12

Generate Code

這里可以將request轉化為各種語言的代碼。比如python、java、shell、HTTP等。

image_thumb14

Response

Body

參考: Understanding and working with responses Viewing responses

這里可以查看返回的應答的body部分。

有三種查看方式: Pretty、 Raw、Preview。

Pretty會根據選擇的類型對Body進行高亮顯示,同時可以選擇要不要自動換行,方便閱讀。

Raw不會進行任何高亮顯示。

Preview顯示的是Body部分的預覽效果。

image_thumb1

Cookies

參考: Understanding and working with responses Cookies

展示瀏覽器的cookies。

Headers

參考: Understanding and working with responses Headers

以key-value對的方式展示返回的header部分。鼠標停留在key上,會顯示該key的說明(根據HTTP文檔)。

image_thumb3

Tests

展示測試結果。

image_thumb4

Status

展示返回的狀態。鼠標方式在狀態上,比如“200 OK”上,會顯示該狀態對應的說明。

image_thumb5[1]

Collections

介紹

個人感覺一個Collection就像是一個測試Project。然后Collection里面可以放置文件夾,也可以直接放置request,放置文件夾就像一個 testsuite。 文件夾里面可以放置多個request,一個request可以寫1個或者多個test。

參考: Getting started with Collections

image_thumb6[1]

Share Collection

Collection可以share給組員,也可以download為JSON文件然后發送給組員進行導入使用。

參考:Sharing Collections with your team

image_thumb7[1]

Run Collection

Collection可以直接run。

參考: Running a collection

1) Previous Runs 展示過去run的collection,點擊可以在Statistics面板顯示具體的結果。

OVERVIEW:該Collection 該輪測試PASS/FAIL數目總體概況。

Previous Runs:該Collection過去run的OVERVIEW,用來進行對比。

REQUESTS:該Collection 該輪測試的詳細情況。

image_thumb10[1]

2) CURRENT RUN 可以設置當前想要run的 collection,還可以對Environment、Iteration、Delay、Data File 進行設置。

Environment:選擇跑該Collection的 Environment。

Iteration: 設置該輪測試跑幾輪。

Delay: 。。。。。。。

Date: 可以選擇加載一個 CSV/JSON的數據文件

image_thumb8

3) RESULTS

點擊“Start Test”就可以開始跑Collection啦。

實時結果會在 RESULTS里面顯示出來。

image_thumb9[1]


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM