postman具體講解

postman 簡單教程-實現簡單的接口測試

最近開始作接口測試了,由於公司電腦恰好有postman,因而就用postman來作接口測試,哈哈哈哈,。。。postman 功能蠻強大的,還比較好用,下面說下postman如何來測試接口html

1.下載postman插件,網址http://chromecj.com/web-development/2014-09/60/download.htmlweb

2.chrom 瀏覽器設置中-更多工具-擴展程序中找到postman插件,找到postman,點擊啓動按鈕,打開postmanchrome

 

 

 

3.postman頁面詳細介紹json

 

4.postman 實現簡單的post請求瀏覽器

a.填寫urlless

b.body中天下參數名及參數值工具

c.點擊send按鈕post

d.查看返回的結果數據與預期是否一致測試

 

嗯,接口測試就是這麼簡單,下一篇,咱們開始講postman的環境變量和如何引用postman中上一次請求返回的值url

 

 

 

postman簡單教程,如何在請求中引用上次請求返回的值

 

作接口測試,必定會遇到這種狀況,須要拿上次請求的值在本次請求中使用,好比,咱們去測試一個東西,要去登陸才能作其餘的操做,須要拿到登陸返回數據中的某些字段,好比,token啊等。。。

若是發一次請求,就去粘貼複製一次,,會很伐木累。。。,並且token 有時候還會過時,每次都要再操做一次,再粘貼複製,真的真的好伐木累,。。。本君不會說,70多個接口,我真的是每次都手動粘貼複製,真的很伐木累啊;因此在請求中引用上次請求返回的值真的很必要!!!!下面開始講如何引用上次請求的值,須要結合上篇文章咱們講的環境變量來實現,直接上栗子講吧,,

1,先發送登陸,查看須要引用的返回值

二、postman -tests模塊中設置須要引用的值爲環境變量

 

3.下一個請求中引用咱們設置的環境變量

 

大概就是這樣,蠻簡單 的,你們學起來,學起來,下一章開始寫如何判斷接口是pass仍是failed,postman的tests模塊

 

postman簡單教程,使用tests模塊來驗證接口時是否經過

接口測試醉重要的就是返回數據的檢查,一個簡單的接口,咱們能夠肉眼檢查返回數據,但接口一旦多起來且複雜,每次的檢查都會很費勁,此時咱們就須要postman 的tests模塊來代替

概念:

Postman的test本質上是JavaScript代碼,經過咱們編寫測試代碼,每個tests返回True,或是False。
每個tests實際上就是一個測試用例

 test驗證方式:

內置腳本說明:

1. 清除一個全局變量 Clear a global variable 對應腳本: postman.clearGlobalVariable("variable_key"); 參數:須要清除的變量的key 2.清除一個環境變量 Clear an environment variable 對應腳本: postman.clearEnvironmentVariable("variable_key"); 參數:須要清除的環境變量的key 3.response包含內容 Response body:Contains string 對應腳本: tests["Body matches string"] =responseBody.has("string_you_want_to_search"); 參數:預期內容 4.將xml格式的response轉換成son格式 Response body:Convert XML body to a JSON Object 對應腳本: var jsonObject = xml2Json(responseBody); 參數:(默認不須要設置參數,爲接口的response)須要轉換的xml 5.response等於預期內容 Response body:Is equal to a string 對應腳本: tests["Body is correct"] = responseBody === "response_body_string"; 參數:預期response 6.json解析key的值進行校驗 Response body:JSON value check 對應腳本: tests["Args key contains argument passed as url parameter"] = 'test' in responseJSON.args 參數:test替換被測的值,args替換被測的key 7.檢查response的header信息是否有被測字段 Response headers:Content-Type header check 對應腳本: tests["Content-Type is present"] = postman.getResponseHeader("Content-Type"); 參數:預期header 8.響應時間判斷 Response time is less than 200ms 對應腳本: tests["Response time is less than 200ms"] = responseTime < 200; 參數:響應時間 9.設置全局變量 Set an global variable 對應腳本: postman.setGlobalVariable("variable_key", "variable_value"); 參數:全局變量的鍵值 10.設置環境變量 Set an environment variable 對應腳本: postman.setEnvironmentVariable("variable_key", "variable_value"); 參數:環境變量的鍵值 11.判斷狀態碼 Status code:Code is 200 對應腳本: tests["Status code is 200"] = responseCode.code != 400; 參數:狀態碼 12.檢查code name 是否包含內容 Status code:Code name has string 對應腳本: tests["Status code name has string"] = responseCode.name.has("Created"); 參數:預期code name包含字符串 13.成功的post請求 Status code:Successful POST request 對應腳本: tests["Successful POST request"] = responseCode.code === 201 || responseCode.code === 202; 14.微小驗證器 Use Tiny Validator for JSON data 對應腳本: var schema = { "items": { "type": "boolean" } }; var data1 = [true, false]; var data2 = [true, 123]; console.log(tv4.error); tests["Valid Data1"] = tv4.validate(data1, schema); tests["Valid Data2"] = tv4.validate(data2, schema); 參數:能夠修改items裏面的鍵值對來對應驗證json的參數
相關文章
相關標籤/搜索