0

I'm having the request script as below and saved as pageRequest.js.

pageRequest.js:

var request = require('request');

var options = {
  method: 'get',
  url: 'http://xx.xx.xx.x/api/....'
};

function callback(error, response, body) {
  var info1 = JSON.parse(body);
  global.info = info1;
}

request(options, callback);

Now I'm executing the above script as part of my protractor onPrepare function. But I need to convert the above pageRequest.js as function and need to call inside my script. can any one help me on this.

KAK
  • 905
  • 4
  • 14
  • 33

1 Answers1

0

By implementing the normal function handler, Can able to convert it as a function.

var request = require('request');

requestHandler: function(){
  var options = {
    method: 'get',
    url: 'http://xx.xx.xx.x/api/....'
  };

  function callback(error, response, body) {
    var info1 = JSON.parse(body);
    global.info = info1;
  }

  request(options, callback);
}
KAK
  • 905
  • 4
  • 14
  • 33