scala - 加特林序列场景
问题描述
我正在尝试使用gatling
,但我遇到了问题。
1-我有一个场景,执行POST
请求获取令牌列表并将所有令牌保存在csv
2-我创建了另一个执行请求的场景,GET
但我需要一个令牌来验证每个请求
我的问题是在执行我的第一个场景之前我的文件不存在并且我有以下错误:
Could not locate feeder file: Resource user-files/resources/token.csv not found
我的代码:
方案 1:
val auth_app = scenario("App authentication")
.exec(http("App Authentication")
.post("/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.formParamSeq(Seq(("grant_type", "password"), ("client_id", clientID), ("client_secret", clientSecret)))
.check(jsonPath("$.token").saveAs("token")))
.exec(session => {
val token_data = new File(token_file_path)
if(token_data.exists()){
val writer = new PrintWriter(new FileOutputStream(new File(token_file_path), true))
writer.write(session("access_token").as[String].trim)
writer.write("\n")
writer.close()
}
else {
val writer = new PrintWriter(new FileOutputStream(new File(token_file_path), true))
writer.println("AccessToken")
writer.write(session("access_token").as[String].trim)
writer.write("\n")
writer.close()
}
session
})
方案 2:
val load_catalog = scenario("Load catalog")
.exec(http("Load catalog")
.get("/list")
.headers(Map("Content-Type" -> "application/json", "Authorization Bearer" -> "${AccessToken}")))
.feed(csv(token_file_path).random)
我的设置:
setUp(
auth_app.inject(atOnceUsers(10)).protocols(httpProtocol),
load_catalog.inject(nothingFor(120 seconds), atOnceUsers(10)).protocols(httpProtocol)
)
是否有可能有一个带加特林的动态馈线?
解决方案
推荐阅读
- c# - “消息”:“无法建立 SSL 连接,请参阅内部异常。” 在 Windows Server 2012 R2 中
- python-3.x - Boto3:根据多个标签获取自动缩放组名称
- android - 如何计算有权访问证书的正确 apkCertificateDigestSha256?
- javascript - 将对象作为属性发送到反应组件
- python-3.x - 如何解决 OperationalError:靠近“(”:sqldf python 中的语法错误?
- c# - 如何为 SonarQube 添加覆盖范围?
- react-native - 如何过滤领域中的对象?
- node.js - 构建 gradle 项目时出现以下错误
- jquery - 为什么当 Jquery toggle() 并显示时链接不可点击?
- asp.net-mvc - 提交无效模型后将多选的选定值从控制器设置为视图