Ниже приведены моя функция конструктора "Req" и функция прототипа "get" для выполнения http-запроса.
var request = require('request');
function Req(url, type, body) {
this.url = url;
this.username = "##############";
this.password = "##############";
this.type = type;
this.body = body
this.authenticationHeader = "Basic " + new Buffer(this.username + ":" + this.password).toString("base64");
}
Req.prototype.get = function (callback) {
request(
{
url: this.url,
headers: { "Authorization": this.authenticationHeader }
},
function (error, response, body) {
if (error) {
console.log("Error in Get Request is " + error)
}
else if (body) {
console.log("******************GET Response is****************" + "\n" + body)
}
callback();
}
);
}
Это работает нормально, и я вызываю эту функцию-прототип, как это в Cucumber
var testObject;
Given('I have request with {string}, {string} and {string}', function (url, type, body) {
testObject = new Req(url, type, body)
});
When('the request is triggered', function (callback) {
testObject.get(callback);
})
Но я хочу показать только значение ответа, которое "Body", в течение шага
Then('I should get the result', function () {
How to do here??
});
Благодарим Вас за помощь.