BDD测试在任何点平台上进行监视
我正在创建在任何点平台上监视的测试。首先,我有一些终点来生成令牌,我想在标题中使用此令牌。
import * from bat::BDD
import * from bat::Assertions
var context = bat::Mutable::HashMap() // <--- First, the HashMap
var headers = {
'example': 'test'
}
---
describe `token jwt` in [
it should "take token" in [
GET `example: some endpoind to get token` with {
headers: headers
} assert [
$.response.status mustEqual 200
] execute [
context.set('token', $.response.payload[26 to 102]), // <--- Setting token
log(context.get('token'))
]
],
it should "token header" in [
POST `example: endpoint with token in headers` with {
headers: {
'token': context.get('token'),
'Content-Type': 'application/json'
},
body:
{
"test": "example"
}
} assert [
$.response.status mustEqual 200,
$.request.headers.token mustEqual context.get('token')
]
execute [
log(context.get('token'))
]
]
]
有人可以帮助我如何在标题中使用这个令牌?我有一个错误:
message: "You called the function 'wrappedRequest' with these arguments: \n
1: String (\"POST\")\n 2: String (\""example: endpoint with token in headers)\n
3: Object ({headers: {"token: \"exampleToken...)\n\n
But it expects arguments of these types:\n 1: String\n 2: String\n 3: HttpCustomOptions\n",
"location": "\n144| wrappedRequest(method, stringInterpolation(parts, interpolation map $ as String), configDelegate(null, null))\n
I'm creating the test for monitoring on anypoint platform. And first I have some endpoint to generate the token and the I would like use this token in header.
import * from bat::BDD
import * from bat::Assertions
var context = bat::Mutable::HashMap() // <--- First, the HashMap
var headers = {
'example': 'test'
}
---
describe `token jwt` in [
it should "take token" in [
GET `example: some endpoind to get token` with {
headers: headers
} assert [
$.response.status mustEqual 200
] execute [
context.set('token', $.response.payload[26 to 102]), // <--- Setting token
log(context.get('token'))
]
],
it should "token header" in [
POST `example: endpoint with token in headers` with {
headers: {
'token': context.get('token'),
'Content-Type': 'application/json'
},
body:
{
"test": "example"
}
} assert [
$.response.status mustEqual 200,
$.request.headers.token mustEqual context.get('token')
]
execute [
log(context.get('token'))
]
]
]
Someone could help me how I can use this token in header ? I have this error:
message: "You called the function 'wrappedRequest' with these arguments: \n
1: String (\"POST\")\n 2: String (\""example: endpoint with token in headers)\n
3: Object ({headers: {"token: \"exampleToken...)\n\n
But it expects arguments of these types:\n 1: String\n 2: String\n 3: HttpCustomOptions\n",
"location": "\n144| wrappedRequest(method, stringInterpolation(parts, interpolation map $ as String), configDelegate(null, null))\n
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发布或获得的第一个论点是URL。看起来您正在传递描述(
示例:端点eNDPOINT in Headers in Headers
)。同样,当您具有授权令牌时,通常会在标准授权
http标头中发送。例子:
The first argument to POST or GET is the URL. It looks like you are passing a description instead (
example: endpoint with token in headers
). Also when you have an authorization token usually it is sent in the standardAuthorization
HTTP header.Example: