1

我正在使用 Dynatrace 和 Gatling 进行性能分析和测试。Dynatrace 支持通过向每个 HTTP 请求添加标头来跟踪测试运行。我希望该标头具有动态测试指南,而无需将其单独添加到 100 个位置的每个请求中。

一个示例测试:

def GetLocationPage = exec(http(domain + "GetLocationPage")
.post("/location ")
.formParam("updateVersion", "1")

我知道我可以在每个请求中单独添加标头...

.headers(gatlingHeaders)

...但我的目标是避免在代码中使用 100 多个位置。本质上,我正在寻找与Spring中此功能等效的 Gatling。

我在 Gatling 上发现了这个问题,但无法确定它是否有用。

有什么建议吗?

4

1 回答 1

6

您可以在创建 http 协议时直接配置默认标头,例如

val httpConf = http
   // Here is the root for all relative URLs
   .baseURL("http://computer-database.gatling.io") 
   // Here are the common headers, via specialized methods
  .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") 
  .acceptEncodingHeader("gzip, deflate")
  .acceptLanguageHeader("en-US,en;q=0.5")
  .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")
  // More generic methods are available too
  .header("foo", "bar") // to set one header
  .headers(Map("foo" -> "bar", "baz" -> "qix")) // to set a bunch of headers

val scn = scenario("Scenario Name")
  .exec(http("request_1").headers(...) // This is for single request, but you know it already
  .get("/")) // etc...

setUp(scn.inject(atOnceUsers(1)).protocols(httpConf))

有关更多信息,请参阅文档Http Headers

于 2017-04-21T12:09:14.753 回答