我想使用類似Cucumber JVM的東西來驅動爲Gatling編寫的性能測試。理想情況下,黃瓜功能將以某種方式動態地構建場景 - 可能重複使用類似於「高級教程」中所述的方法的預定義鏈對象,例如,以編程方式執行Gatling測試
val scn = scenario("Scenario Name").exec(Search.search("foo"), Browse.browse, Edit.edit("foo", "bar")
我已經看了如何Maven插件執行腳本,而且我也看到使用應用程序特徵的提及,但我找不到以後的任何文件和這讓我感到別人將之前想這樣做...
任何人都可以指向(一個加特林noob)在一些文檔或示例代碼的方向如何實現這一目標?
編輯20150515
所以解釋多一點:
我創建了旨在建立起來,我覺得一個序列的特徵,是由黃瓜步驟觸發ChainBuilders:
trait GatlingDsl extends ScalaDsl with EN {
private val gatlingActions = new ArrayBuffer[GatlingBehaviour]
def withGatling(action: GatlingBehaviour): Unit = {
gatlingActions += action
}
}
一個GatlingBehaviour看起來是這樣的:
object Google {
class Home extends GatlingBehaviour {
def execute: ChainBuilder =
exec(http("Google Home")
.get("/")
)
}
class Search extends GatlingBehaviour {...}
class FindResult extends GatlingBehaviour {...}
}
而且StepDef類中:
class GoogleStepDefinitions extends GatlingDsl {
Given("""^the Google search page is displayed$""") {() =>
println("Loading www.google.com")
withGatling(Home())
}
When("""^I search for the term "(.*)"$""") { (searchTerm: String) =>
println("Searching for '" + searchTerm + "'...")
withGatling(Search(searchTerm))
}
Then("""^"(.*)" appears in the search results$""") { (expectedResult: String) =>
println("Found " + expectedResult)
withGatling(FindResult(expectedResult))
}
}
的想法是,然後我就可以通過類似執行行動的整個序列:
val scn = Scenario(cucumberScenario).exec(gatlingActions)
setup(scn.inject(atOnceUsers(1)).protocols(httpConf))
,然後檢查報告或趕上如有異常測試失敗,例如響應時間過長。
看來,無論我如何使用'exec'方法,它都會嘗試在那裏立即執行它,然後不等待該場景。
另外我不知道這是否是最好的方法,我們想爲我們的Gatling測試構建一些可重用的塊,可以通過Cucumber的Given/When/Then樣式構建。有更好的還是現有的方法?
謝謝,我已經看到了,但它看起來像加載靜態Gatling腳本沒有通過動態生成的情景 - 我錯過了什麼? – SilentICE
現在我明白了。我編輯了我的答案。 –