在Frisby中访问头文件
Access headers in Frisby
我正在使用Frisby.js库来测试一些api,并且我需要访问set-cookie头中的会话cookie以发送以下请求。
当我尝试inspectJSON()方法时,我没有看到输出中包含的标头,并且我无法识别任何方法来访问响应中的标头。任何帮助,非常感谢。谢谢!
这个例子链接了一个Login调用和一个后续调用,该调用将"set-cookie"添加到下一个调用。cookie像web浏览器一样被维护,并且第二次调用将只与传递给第二次调用的set-cookie一起工作。
var cookie = "";
frisby.create('Login')
.post('localhost:8080/login', {
"username": "test_user_01",
"password": "abcd1234",
}, {
json: true
})
.inspectJSON() // Prints response json to stdout
.inspectHeaders() // Prints out all the headers in response
.expectStatus(200) // Check for http success
.expectJSONTypes({ // Check for any reported errors
status: 1,
message: 'success'
})
.after(function(body,res) {
cookie = res.headers['set-cookie'];
// Fetch account
frisby.create('Get Accounts')
.get(utils.URL + '/accounts?includeAllAccounts=1', {
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Cookie": cookie,
}
})
.inspectJSON()
.expectStatus(200)
.expectJSONTypes('responseMap.accounts.0', {
//These tests will fail if the value is null
accountNumber: String,
})
.toss();
}).toss();
好的,大约2分钟后张贴这个问题,我找到了答案。我能够访问.after()函数中的头文件,如下所示:
.after(function(body,res) {
//output headers to console
console.log('************* Headers: ' + JSON.stringify(res.headers, null, 4));
})
相关文章:
- 从另一个文件访问函数的返回值
- 从HTML中的另一个文件访问javascript方法
- Chrome中的本地文件访问
- 从require()'d文件访问函数
- 从另一个 javascript 文件访问 main() 函数
- 从不同的javascript文件访问HTML表单提交的值
- http(localhost或remote)提供的文件是否可以从通过file://protocol打开的本地文件访问?反
- 使用PrimeFaces从Javascript文件访问资源
- 从php文件访问javascript数组
- 如何从单独的javascript文件访问模型属性?(MVC)
- 通过文件访问页面时Cookie不起作用://
- 从批处理文件访问JavaScript方法
- 从不同目录中的另一个文件访问一个文件
- 从其他文件访问 Ext 甘特 JS 变量
- 解决 Html5 本地文件访问问题
- 从外部 Javascript 文件访问数据
- 从 javascript 文件访问 Webform
- 从外部 JavaScript 文件访问表单元素
- 如何从 jade 文件中的 javascript 文件访问变量的值
- 如何从我的外部javascript文件访问php变量