我正在使用 Dynatrace 和 Gatling 进行性能分析和测试。Dynatrace 支持通过向每个 HTTP 请求添加标头来跟踪测试运行。我希望该标头带有动态测试 guid,而无需在 100 多个地方将其单独添加到每个请求中。
一个示例测试:
def GetLocationPage = exec(http(domain + "GetLocationPage")
.post("/location ")
.formParam("updateVersion", "1")
Run Code Online (Sandbox Code Playgroud)
我知道我可以在每个请求中单独添加标头...
.headers(gatlingHeaders)
Run Code Online (Sandbox Code Playgroud)
...但我的目标是避免在代码中执行 100 多个位置。本质上,我正在寻找与 Spring 中的此功能等效的 Gatling 。
我在 Gatling 上发现了这个问题,但无法确定它是否有用。
有什么建议吗?
您可以在创建 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))
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅文档Http 标头