gatling系列教程(翻譯)-(附加三)checks

概念
Check API用於兩件事情:正則表達式

驗證對請求的響應是否符合預期
最終在其中捕獲一些元素。
檢查是根據具備檢查方法的請求執行的。 例如,在HTTP請求上:函數

http("My Request").get("myUrl").check(status.is(200))

One can of course perform multiple checks:spa

http("My Request").get("myUrl").check(status.not(404), status.not(500))

默認狀況下,Gatling遵循重定向(能夠在協議中禁用)。 若是啓用此行爲,檢查將忽略中間響應,並將針對着陸響應。code

Defining the check type

HTTP檢查實現提供如下內置函數:orm

HTTP status

  • status

Targets the HTTP response status code.對象

當您未指定請求時,狀態檢查將自動添加到請求中。 它檢查HTTP響應是否具備2XX或304狀態代碼。ip

Page location

  • currentLocation

指定當前頁絕對URL。 如下重定向是有用的,以檢查目標網頁是否確實是預期的。字符串

  • currentLocationRegex(pattern)

與上述相同,可是pattern用於在當前位置應用正則表達式。get

默認狀況下,它能夠提取0或1個捕獲組,所以提取類型爲String。io

能夠提取多於1個捕獲組,並使用Type [T]額外步驟定義不一樣的類型:

currentLocationRegex(pattern).ofType[T]

Gatling提供了從Tuple2 [String]提取String元組到Tuple8 [String]的內置支持。

如下示例將捕獲兩個捕獲組:

currentLocationRegex("http://foo.com/bar?(.*)=(.*)").ofType[(String, String)]

HTTP header

  • header(headerName)

指定給定名稱的HTTP響應標頭。 headerName能夠是純字符串,使用Gatling EL或Expression [String]的String。

  • headerRegex(headerName, pattern)

與上述相同,可是pattern用於在標頭值上應用正則表達式。

標題名稱可用做DSL中的常量,可從HttpHeaderNames對象訪問,例如。HttpHeaderNames.ContentType。

默認狀況下,它能夠提取0或1個捕獲組,所以提取類型爲String。

能夠提取多於1個捕獲組,並使用Type [T]額外步驟定義不一樣的類型:

headerRegex(headerName, pattern).ofType[T]

Gatling提供了從Tuple2 [String]提取String元組到Tuple8 [String]的內置支持。

如下示例將捕獲兩個捕獲組:

headerRegex("FOO", "foo(.*)bar(.*)baz").ofType[(String, String)]

HTTP response body

相關文章
相關標籤/搜索