I am using "soap" for testing my application wsdls in protractor. this is the code I am using
I want 'servicechitest' function to return "results" object(highlighted in the screenshot). It prints expected output to the console. Not sure where can I place return statement to get results object.
You need to implement a promise to get the value from an asynchronous method. you can use q
module from npm to implement promise.
to install q
, run the below command in terminal,
npm install q
once q
is downloaded, Use it in your application like below,
var q= require('q');
servicehitest : function () {
var url ="someurl";
var args= [];
var defered = q.defer();
soap.creatClient(url,creatClient);
function clientCreate(err,client) {
if(err){
console.log("in error block");
console.log(client.describe());
}
client.getInstrument(args,instrument);
function instrument(err,result){
if(err){
defered.reject(err);
} else {
console.log(result);
defered.resolve(result);
}
}
}
return defered.promise;
}
To get the result from servicehitest
method, use the below code.
servicehitest().then(function(result){
//this method will be called when the result is obtained from getInstrument() method.
console.log("Successfully got result:"+result);
},
function(error){
//error callback method will be called if there is any error from getInstrument() method.
console.log("Some error occured:"+error);
})