空手道加特林:来自馈线的数据在特征中具有未定义的值
Gatling with Karate: data from feeder has undefined values in feature
来自馈线的数据未传入特征。我应该如何将数据从馈线传递到功能?我将在这里描述我的代码:
模拟
val protocol: KarateProtocol = karateProtocol(
"/" -> Nil,
"/" -> pauseFor("get" -> 3, "post" -> 5)
)
private val feeder = Iterator.continually(Map(
"uri" -> s"https://$runEnv-url.com",
"token" -> getApiAuthToken(userLogin, userPassword, userAccount).getToken,
"userId" -> getApiAuthToken(userLogin, userPassword, userAccount).getUserID
))
val scn: ScenarioBuilder =
scenario("Scenario name")
.feed(feeder)
.exec(session => {
println(session)
session
})
.exec(karateFeature("classpath:specs/api.feature"))
setUp(
scn.inject(constantUsersPerSec(1) during(1 seconds)).protocols(protocol)
)
特征:
Feature: Scenario name
Background:
* url __gatling.uri
* header Authentication = 'Token ' + __gatling.token
Scenario: Get User Details
Given path 'users', __gatling.userId
When method get
Then status 200
And print response
结果,我得到的是 undefined
而不是来自馈线的数据。
日志:
When method get
http call failed after 92 milliseconds for url: /users
UPD: 答案中的代码有效,但仍然从会话中获取价值 returns undefined
使用 karateSet()
(1.1.0 中的新功能),如此 example
像这样的东西应该在你的 Scala 模拟中工作:
.feed(feeder)
.exec(karateSet("token", session => session("token").as[String]))
另请阅读文档:https://github.com/intuit/karate/tree/master/karate-gatling#chaining
如果仍然卡住,请按照以下流程操作:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
来自馈线的数据未传入特征。我应该如何将数据从馈线传递到功能?我将在这里描述我的代码:
模拟
val protocol: KarateProtocol = karateProtocol(
"/" -> Nil,
"/" -> pauseFor("get" -> 3, "post" -> 5)
)
private val feeder = Iterator.continually(Map(
"uri" -> s"https://$runEnv-url.com",
"token" -> getApiAuthToken(userLogin, userPassword, userAccount).getToken,
"userId" -> getApiAuthToken(userLogin, userPassword, userAccount).getUserID
))
val scn: ScenarioBuilder =
scenario("Scenario name")
.feed(feeder)
.exec(session => {
println(session)
session
})
.exec(karateFeature("classpath:specs/api.feature"))
setUp(
scn.inject(constantUsersPerSec(1) during(1 seconds)).protocols(protocol)
)
特征:
Feature: Scenario name
Background:
* url __gatling.uri
* header Authentication = 'Token ' + __gatling.token
Scenario: Get User Details
Given path 'users', __gatling.userId
When method get
Then status 200
And print response
结果,我得到的是 undefined
而不是来自馈线的数据。
日志:
When method get
http call failed after 92 milliseconds for url: /users
UPD: 答案中的代码有效,但仍然从会话中获取价值 returns undefined
使用 karateSet()
(1.1.0 中的新功能),如此 example
像这样的东西应该在你的 Scala 模拟中工作:
.feed(feeder)
.exec(karateSet("token", session => session("token").as[String]))
另请阅读文档:https://github.com/intuit/karate/tree/master/karate-gatling#chaining
如果仍然卡住,请按照以下流程操作:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue