1.簡介
上一篇中宏哥已經將其的理論知識介紹了一下,這一篇宏哥就帶着你們一步一步的把上一篇介紹的理論知識實踐一下,而後再說一下如何建立高級web測試計劃。html
2.網絡計劃實戰
經過上一篇的學習,宏哥將其分類爲:web
(1)不須要登陸驗證身份就能夠操做的。apache
(2)須要登陸驗證身份以後才能操做的。瀏覽器
2.1不須要登陸
這裏宏哥就拿博客園來舉例子,如博客園,你不須要登陸驗證身份,就能夠執行閱讀、查找和瀏覽博客園內的文章(前提是這些文章沒有設置「只容許註冊的用戶訪問」)。緩存
2.1.1抓包
1.閱讀博客園文章服務器
一、瀏覽器上輸入博客園地址,點擊文章::Jmeter(三) - 從入門到精通 - 測試計劃(Test Plan)的元件(詳解教程),以下圖所示:cookie

二、fiddler抓包工具抓取博客園查找的過程。從下圖紅色圈住的部分能夠看到查找的URL和請求查找發送的參數。以下圖所示:網絡

2.1.2閱讀文章
按照抓包抓取到的參數,咱們下一步就是用Jmeter模擬閱讀博客園文章:Jmeter(三) - 從入門到精通 - 測試計劃(Test Plan)的元件(詳解教程)。session
1.創建一個測試計劃命名爲:Test Blog Read Plan。如圖下所示:工具

2.選中測試計劃,添加線程組用戶,命名爲:Blog User。以下圖所示:
注意:敲腦袋,敲黑板啦!!!宏哥這個就是一個用戶閱讀一次,若是要壓測你能夠設置多個用戶同時閱讀。

3.選中線程組,添加一個HTTP Header Manager(HTTP信息頭管理器)。這個主要是爲了不Jmeter發送請求後,返回結果可能會出現狀態碼爲403的錯誤。以下圖所示:
注意:敲腦袋,敲黑板啦!!!這裏HTTP信息頭管理器,主要添加一個參數User-Agent。根據你抓包的header來填寫便可。

4.選中線程組,設置一個http,發送http默認請求值,放入你需求測試的地址。這樣作的好處就是後邊的全部的http請求你就再也不須要重複的寫這個測試地址了。以下圖所示:
注意:敲腦袋,敲黑板啦!!!宏哥本地搭建的Jenkins應用程序,那麼測試地址就很清楚了,這裏請求值填寫以下:
(1)protocol(協議:http or https):目前博客園是https協議,因此這裏填寫Protocol:https
(2)測試地址爲:博客園的地址,不用囉嗦你們都知道了,Sever Name or IP:www.cnblogs.com
(3)Port:(博客園沒有端口)

5.選中線程組,添加一個http請求命名爲:Read。以下圖所示:
注意:敲腦袋,敲黑板啦!!!宏哥本地搭建的Jenkins應用程序,那麼Read請求值,咱們查看抓到登陸請求包(2.2.1)就很清楚了,這裏請求值填寫以下:
(1)protocol(協議:http or https):目前這個是本地搭建的http協議,因此這裏填寫Protocol:https
(2)測試地址爲:本地搭建,不用囉嗦你們都知道了,Sever Name or IP:www.cnblogs.com
(3)Port:(博客園沒有端口)
(4)Method:是那種類型的請求就選擇那種,這裏選擇get
(5)Path:閱讀博客園文章的請求路徑
(6)Content Encoding:編碼宏哥這裏沒有填寫,若是出現亂碼,你能夠填寫utf-8和Gb2312試一下,便可。

6.選中線程組,添加一個結果樹,命名爲:Check Read Results,監聽閱讀博文是否成功。以下圖所示:

2.2須要登陸
一樣的這裏也拿博客園舉例子,你若是要發佈隨筆、評論、點推薦等等的一系列操做,就須要你登陸驗證身份之後才能執行這些操做。可是因爲博客園的登陸機制改變宏哥就不拿博客園舉例子,宏哥拿一個,宏哥在本地搭建的Jenkins的web應用程序來實戰一下,刪除一個job。可是這個job必須在登陸之後才能刪除,若是沒有登陸就會刪除失敗。
2.2.1抓包
1.登陸
一、瀏覽器上登陸jenkins,輸入帳號和密碼,點擊登陸。以下圖所示:

二、fiddler抓包工具抓取jenkins登陸的過程。從下圖紅色圈住的部分能夠看到登陸的URL和請求登陸發送的參數。以下圖所示:

2.刪除
一、咱們前面講過登陸後新建任務後,那能夠繼續接着操做:刪除剛纔新建的任務。以下圖所示:

二、用fiddler抓包,抓到刪除新建任務的請求,從抓包結果能夠看出,傳的data參數是Jenkins-Crumb。以下圖所示:

3.這個Jenkins-Crumb哪裏來的呢?能夠看上個請求的body。以下圖所示:

2.2.2登陸
按照抓包抓取到的參數,咱們下一步就是用Jmeter模擬登陸到Jenkins。
1.創建一個測試計劃命名爲:Test Jenkins Plan。以下圖所示:

2.選中測試計劃,添加線程組用戶,命名爲:Jenkins User。以下圖所示:
注意:敲腦袋,敲黑板啦!!!宏哥這個就是一個用戶登陸一次,若是要壓測你能夠設置多個用戶同時登陸。

3.選中線程組,添加一個HTTP Header Manager(HTTP信息頭管理器)。這個主要是爲了不Jmeter發送請求後,返回結果可能會出現狀態碼爲403的錯誤。以下圖所示:
注意:敲腦袋,敲黑板啦!!!這裏HTTP信息頭管理器,主要添加兩個參數User-Agent和Content-Type。根據你抓包的header來填寫便可。

4.選中線程組,設置一個http,發送http默認請求值,放入你需求測試的地址。這樣作的好處就是後邊的全部的http請求你就再也不須要重複的寫這個測試地址了。以下圖所示:
注意:敲腦袋,敲黑板啦!!!宏哥本地搭建的Jenkins應用程序,那麼測試地址就很清楚了,這裏請求值填寫以下:
(1)protocol(協議:http or https):目前這個是本地搭建的http協議,因此這裏填寫Protocol:http
(2)測試地址爲:本地搭建,不用囉嗦你們都知道了,Sever Name or IP:localhost
(3)Port:8080(這裏宏哥搭建的默認端口8080,你也能夠在Tomcat的配置文件修改這個端口)

5.選中線程組,添加一個http請求命名爲:Login。以下圖所示:
注意:敲腦袋,敲黑板啦!!!宏哥本地搭建的Jenkins應用程序,那麼Login請求值,咱們查看抓到登陸請求包(2.2.1)就很清楚了,這裏請求值填寫以下:
(1)protocol(協議:http or https):目前這個是本地搭建的http協議,因此這裏填寫Protocol:http
(2)測試地址爲:本地搭建,不用囉嗦你們都知道了,Sever Name or IP:localhost
(3)Port:8080(這裏宏哥搭建的默認端口8080,你也能夠在Tomcat的配置文件修改這個端口)
(4)Method:是那種類型的請求就選擇那種,這裏選擇post
(5)Path:登陸的請求路徑
(6)Content Encoding:編碼宏哥這裏沒有填寫,若是出現亂碼,你能夠填寫utf-8和Gb2312試一下,便可。

6.選中線程組,添加一個cookie管理器,用來管理登陸後的cookie。以下圖所示:
注意:敲腦袋,敲黑板啦!!!cookie的添加一個值,這個也能夠在抓包登錄請求中header查看到,這裏宏哥就不細說了。
(1)Name:JSESSIONID
(2)Value:一串數字和字母
(3)Domain:localhost

7.選中線程組,添加一個結果樹,命名爲:Check Login Results,監聽登陸是否成功。以下圖所示:

8.選中線程組,添加一個http請求命名爲:Delete Item。以下圖所示:
注意:敲腦袋,敲黑板啦!!!宏哥本地搭建的Jenkins應用程序,那麼Delete請求值,咱們查看抓到刪除請求包(2.2.1)就很清楚了,這裏請求值填寫以下:
(1)protocol(協議:http or https):目前這個是本地搭建的http協議,因此這裏填寫Protocol:http
(2)測試地址爲:本地搭建,不用囉嗦你們都知道了,Sever Name or IP:localhost
(3)Port:8080(這裏宏哥搭建的默認端口8080,你也能夠在Tomcat的配置文件修改這個端口)
(4)Method:是那種類型的請求就選擇那種,這裏選擇post
(5)Path:刪除的請求路徑
(6)Content Encoding:編碼宏哥這裏沒有填寫,若是出現亂碼,你能夠填寫utf-8和Gb2312試一下,便可。

9.選中線程組,添加一個結果樹,命名爲:Check Delete Results,監聽刪除job是否成功。以下圖所示:

2.3JMeter運行查看運行結果
2.3.1不須要登陸
一、點擊綠色的按鈕,運行Jmeter,以下圖所示:

二、查看JMeter運行結果,一個請求的監聽結果都是綠色的,說明請求成功。以下圖所示:

(1)查看閱讀是否成功,從結果看到博文內容,說明閱讀成功。以下圖所示:

2.3.2登陸
一、Jenkins的新建任務裏有「北京-宏哥」,以下圖所示:

二、點擊綠色的按鈕,運行Jmeter,以下圖所示:

三、查看JMeter運行結果,兩個請求的監聽結果都是綠色的,說明請求成功。以下圖所示:

(1)查看登陸是否成功,從結果看到「admin」和「註銷」,說明登陸成功。以下圖所示:

(2)能夠看到登陸成功後的,任務中有「北京-宏哥」。以下圖所示:

(3)查看刪除是否成功,從結果中沒有看到「北京-宏哥」,說明刪除成功。以下圖所示:

四、查看Jenkins的新建任務,沒有看到「北京-宏哥」,說明刪除成功了,以下圖所示:

3.制定高級Web測試計劃