试图测试rest api。在我的项目中没有用于登录的 api。每当您点击 api 时,它都会被重定向到 login ,获取用户/密码并为您提供结果。
我按如下方式尝试了 GET,这对我来说效果很好。
var frisby = require('frisby')
var url = 'https://localhost:8443';
var api= '/api/v2/events/details'
var endpoint = '?id=ccce2aef971f'
var user= 'demo@demo.com'
var pass= 'temp'
frisby.create('GET event details based on eventid from an endpoint')
.get(url+api+endpoint,{strictSSL: false})
.auth(user,pass,false)
.expectStatus(200)
.expectHeader('Content-Type', 'application/json;charset=UTF-8')
.toss();
现在我想使用相同格式的 POST 方法,但没有响应。
var frisby = require('frisby')
var user= 'demo@demo.com'
var pass= 'temp'
var jsonbody = {"group": "a10bbd20",
"category":"Attack",
"notes":"abcdddd",
"criteria":[ {"attribute":"PATH" ,"operator": "EQUALS", "value":"/Account/demo.aspx" }]
}
frisby.create('TEST POST')
.post('https://localhost:8443/api/v2/rule-settings/pointwise',jsonbody,{ json: true },{ headers: { 'Content-Type': 'application/json' }},{strictSSL: false})
.auth(user,pass,false)
.expectStatus(201)
.toss();
=======================
我尝试通过存储来自先前响应的 cookie 来执行 POST 请求,但超时仍然出现相同的错误
var frisby = require('frisby')
var url = 'https://localhost:8443';
var api= '/api/v2/events/details'
var endpoint = '?id=ccce2aef971f'
var user= 'demo@demo.com'
var pass= 'temp'
var loginState = {
};
frisby.create('GET event details based on eventid from an endpoint')
.get(url+api+endpoint,{strictSSL: false})
.auth(user,pass,false)
.after(function (body,res) {
var cookie = res.headers['set-cookie'];
console.log(cookie);
loginState.user1 = {}; // build an object for user 1
loginState.user1.cookie = cookie;
var jsonbody = {"group": "a10bbd20",
"category":"Attack",
"notes":"abcdddd",
"criteria":[ {"attribute":"PATH" ,"operator": "EQUALS", "value":"/Account/demo.aspx" }]
}
frisby.create('TEST POST')
.post('https://localhost:8443/api/v2/rule-settings/pointwise',jsonbody,{ json: true },{strictSSL: false})
.addHeader('cookie', loginState.user1.cookie)
.addHeader('Content-Type', 'application/json')
.inspectRequest()
.expectStatus(201)
.toss();
})
.toss();
我得到的输出是
Message:
Expected 500 to equal 200.
Stacktrace:
Error: Expected 500 to equal 200.
at null.<anonymous> (C:\Users\Administrator\Documents\TestSuite\node_modules
\frisby\lib\frisby.js:493:42)
at null.<anonymous> (C:\Users\Administrator\Documents\TestSuite\node_modules
\frisby\lib\frisby.js:1074:43)
at Timer.listOnTimeout (timers.js:92:15)